Home > Mobile >  APEX - Adding two columns and showing the result in a third column
APEX - Adding two columns and showing the result in a third column

Time:01-24

From APEX in Object browser, I have created below columns in a table called "Project_Management". Now I always wanted my

  • column 4 to display "column1 column3" and
  • column 5 to display "column2 column3".

How and where do I declare these from the object browser?

  1. Start_date
  2. Start_Time
  3. Duration
  4. End_date
  5. End_Time

CodePudding user response:

That's a virtual column.

SQL> create table test
  2    (start_date date,
  3     duration   number,
  4     --
  5     end_date as (start_date   duration)        --> this is a virtual column
  6    );

Table created.

SQL> insert into test (start_date, duration) values (date '2022-01-24', 2);

1 row created.

SQL> select * from test;

START_DATE            DURATION END_DATE
------------------- ---------- -------------------
24.01.2022 00:00:00          2 26.01.2022 00:00:00
                               -------------------
                               END_DATE got its value although it wasn't inserted    

You didn't say which datatypes you used. Oracle doesn't have separate datatypes for date and time; that's just DATE which contains both.

When you add a number to a date, you're actually adding number of days (that's why 24.01.2022 2 = 26.01.2022).

You said that you'd want to add the same value (duration) to the start_time column. I don't know what you expect out of that (regardless the fact that there's no TIME datatype).

CodePudding user response:

When you add interactive grid region to your page, specify your table Project_Management to gather columns you named column1, column2 and column3.enter image description here

If you change that query to something like:

select pm.col1, pm.col2, pm.col3, to_char(col1) || ' ' || to_char(col3) as. col4, to_char(col2) || ' ' || to_char(col3) as. col5, from Project_Management;

you will now see the new concatenated columns also: enter image description here

NOTE: Depending on your column types, you may need to use other operations other than to_char or you may want to use DATEFORMAT such as to_char(col1,'DD/MM/YYYY HH24:MI');

  •  Tags:  
  • Related