Create the view with the Unique ID column

I need to create a view.
The view is created using unions on 4 tables.
The problem is that I need to create a unique id column in the view that I use in an Oracle Apex application and need to drill down to each line.

Any help appreciated

Gus

You cannot use oracle sequences directly in the query that is connected with other queries using Union or INTERSECT or less cluses.

Other cases where you cannot use a sequence are:
-In a WHERE clause
-In a GROUP BY or ORDER BY clause
-In a SEPARATE clause
-Along with a UNION or INTERSECT or LESS
-In a subquery

In order to better you will love

Select seqname.nextval, col1, col2
Of
(

Union

..
..
)

as mentioned in one of the previous answer by the other members of the community...

Alternatively, you can use rownum speed of sequence to a unique number as below examle:

Select rownum, col1, col2
Of
(

Union

..
..
)

Kind regards
Lifexisxnotxsoxbeautiful...

Tags: Database

Similar Questions

  • How to create a table with two unique columns

    How to create a table with two unique columns. I use the following syntax below and I get the error message such unique or primary key already exists.

    create the table COPQ_WORKCELL_GOAL
    (
    Type_id varchar2 (4) NOT NULL UNIQUE,
    Tyle_Location varchar2 (30) NOT NULL UNIQUE,
    Type_Description varchar2 (20).
    KEY elementary SCHOOL (Type_id)
    );

    Use 1 or the other column type_id;

    create table COPQ_WORKCELL_GOAL
    (
      Type_id varchar2(4),
      Tyle_Location varchar2(30) NOT NULL UNIQUE,
      Type_Description varchar2(20),
      PRIMARY KEY (Type_id)
    );
    
    Table created
    drop table COPQ_WORKCELL_GOAL;
    
    Table dropped
    create table COPQ_WORKCELL_GOAL
    (
      Type_id varchar2(4) primary key,
      Tyle_Location varchar2(30) NOT NULL UNIQUE,
      Type_Description varchar2(20)
    );
    
    Table created
    
  • create a view with the double data type

    I have Windows XP with 10g 10.2.0.1.0

    I need to create a view of the double and with the type of data, such as NUMBER (5.2), NUMBER or VARCHAR2 (20).
    such as:
    create see test (view_test varchar2 (20)) as (select view_test from double)


    Help, please. Thanks in advance.

    It seems a little strange, but you can do something like this with the CAST function:

    SQL> create view dual_view as
      2  select cast(null as number(5,2)) col1
      3        ,cast(null as date)    col2
      4        ,cast(null as varchar2(30)) col3
      5  from   dual;
    
    View created.
    
    SQL> desc dual_view
     Name                                      Null?    Type
     ----------------------------------------- -------- -------------------------
     COL1                                               NUMBER(5,2)
     COL2                                               DATE
     COL3                                               VARCHAR2(30)
    

    I used the NULL values, but you can use the actual values if you wish.

  • create a materialized with sizes of specific columns view

    Hi all

    I am creating a materialized with a specific column size view. Something like
    create materialized view test_mv
    refresh force on demand
    as
    select id, 
           cast(my_compound_field as nvarchar2(50))
    from ( select id, 
                  field1 || field2 my_compound_field
           from   my_table);
    But Oracle seems to ignore the cast and takes the maximum size it finds for field1 | Field2 in the select query. The resulting table has a nvarchar2 (44) instead of nvarchar2 column (50).

    Which can be a problem when the display is updated... There could be new data that exceeds the current size, which is where length(field1 || field2) > 44.

    How can I change the size of the column to a field in a materialized view?

    Edit: Some extra info to clarify my case:
    Field1 and Field2 are defined as nvarchar2 (25). Field1 | Field2 can theoretically have a length of 50, but currently there is no data in my table that results from this length, the max is 44. I fear that in the future there is data that is greater than 44, which results in an error when the MV is refreshed!

    Published by: Pleiadian on January 25, 2011 14:06

    Try the substr function.

    http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions181.htm#i87066

  • How to create a view with columns from multiple lines

    I posted this in the SQL/PSL forum, but I hope that experts from the database in this group can give me ideas also, the necessity is also BI reports.

    I have a table, for example, project_milestones, that has these columns in order:

    PROJ_ID, milestone_name, actual_end_date

    with data:
    PROJ_ID, milestone_name, actual_end_date
    ===== ================ ==============
    1001, key approval, 2009-10-02
    1001, final synopsis, 2009-10-07
    1001, approved final Protocol, 2009-10-15
    1001, FPFV, 2010-01-10
    1001, LPFV, 2010-03-12
    ...
    1002, key approval, 2008-12-02
    1002, final synopsis, 2009-01-07
    1002, approved final Protocol, 2009-01-12
    1002, FPFV, 2009-03-30
    1002, LPFV, 2009-10-04
    ...
    There are about 10 steps in each project.
    I need to create a view for dish these data at the project level, looks like this:

    PROJ_ID, key_element_date, final_synopsis_date, final_protocol_approved_date, FPFV_date, LPFV_date, key_element_to_final_synopsis_days, final_synopsis_final_protocol_days...

    How can I do this?

    Thank you

    user9175541 wrote:
    I posted this in the SQL/PSL forum, but I hope that experts from the database in this group can give me ideas also, the necessity is also BI reports.

    I have a table, for example, project_milestones, that has these columns in order:

    PROJ_ID, milestone_name, actual_end_date

    with data:
    PROJ_ID, milestone_name, actual_end_date
    ===== ================ ==============
    1001, key approval, 2009-10-02
    1001, final synopsis, 2009-10-07
    1001, approved final Protocol, 2009-10-15
    1001, FPFV, 2010-01-10
    1001, LPFV, 2010-03-12
    ...
    1002, key approval, 2008-12-02
    1002, final synopsis, 2009-01-07
    1002, approved final Protocol, 2009-01-12
    1002, FPFV, 2009-03-30
    1002, LPFV, 2009-10-04
    ...
    There are about 10 steps in each project.
    I need to create a view for dish these data at the project level, looks like this:

    PROJ_ID, key_element_date, final_synopsis_date, final_protocol_approved_date, FPFV_date, LPFV_date, key_element_to_final_synopsis_days, final_synopsis_final_protocol_days...

    How can I do this?

    Thank you

    Create a PivotTable and put "milestone_name" in the columns, under the labels section.
    Put 'actual_end_date' in the section of measures and to change the rule of the aggregation of 'Max '.
    The rest of the attributes keep in the lines section.

  • How to create Table View with even a column name but another Table?

    Hi all

    I have the problem to create a tableview with the same column name, but in the other table.

    Table I: -.

    Table - PAC051MPROFORMA

    Column - MNR, visitid

    Table - PAC051TPROFORMA
    Column - MNR, visitid

    Table - PAC052MTRANSBILL
    Column - MNR, visitid

    Then, I want to create a table for this table. It comes to my SQL

    Pacviewproforma CREATE VIEW (MNR, visitid, MNR, visitid, MNR, visitid)

    Like some PAC051MPROFORMA.mrn, PAC051MPROFORMA.visitid, PAC051TPROFORMA.mrn, PAC051TPROFORMA.visitid, PAC052MTRANSBILL.mrn, PAC052MTRANSBILL.visitid

    where

    * (a.PAC051MPROFORMA.mrn = PAC051TPROFORMA.mrn) *.
    and
    * (a.PAC051TPROFORMA.mrn = PAC052TRANSBILL.mrn) *.

    SQL return this error ORA-00957 =: duplicate column name

    Can I change this SQL for

    Pacviewproforma CREATE VIEW (MNR, visitid)

    Like some PAC051MPROFORMA.mrn, PAC051MPROFORMA.visitid, PAC051TPROFORMA.mrn, PAC051TPROFORMA.visitid, PAC052MTRANSBILL.mrn, PAC052MTRANSBILL.visitid

    where

    * (a.PAC051MPROFORMA.mrn = PAC051TPROFORMA.mrn) *.
    and
    * (a.PAC051TPROFORMA.mrn = PAC052TRANSBILL.mrn) *.
    This time this error return = ORA-01730: number of column names specified invalid

    What should I do?

    Thank you...

    Hello

    SQL> CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
      2  As Select
      3  PAC051MPROFORMA.mrn,
      4  PAC051MPROFORMA.visitid,
      5  PAC051TPROFORMA.mrn,
      6  PAC051TPROFORMA.visitid,
      7  PAC052MTRANSBILL.mrn,
      8  PAC052MTRANSBILL.visitid
      9  from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
     10  where
     11  (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
     12  and
     13  (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
    CREATE VIEW pacviewproforma (mrn,visitid,mrn,visitid,mrn,visitid)
                                             *
    ERROR at line 1:
    ORA-00957: duplicate column name
    

    Please give different names to each column.

    Something like that...

    SQL> CREATE OR REPLACE VIEW pacviewproforma (MPROFORMA_mrn,MPROFORMA_visitid,TPROFORMA_mrn,TPROFORMA
    _visitid,MTRANSBILL_mrn,MTRANSBILL_visitid)
      2  As Select
      3  PAC051MPROFORMA.mrn,
      4  PAC051MPROFORMA.visitid,
      5  PAC051TPROFORMA.mrn,
      6  PAC051TPROFORMA.visitid,
      7  PAC052MTRANSBILL.mrn,
      8  PAC052MTRANSBILL.visitid
      9  from PAC051MPROFORMA,PAC051TPROFORMA,PAC052MTRANSBILL
     10  where
     11  (PAC051MPROFORMA.mrn=PAC051TPROFORMA.mrn)
     12  and
     13  (PAC051TPROFORMA.mrn=PAC052MTRANSBILL.mrn);
    
    View created.
    
    SQL> DESC  pacviewproforma;
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     MPROFORMA_MRN                                      NUMBER
     MPROFORMA_VISITID                                  NUMBER
     TPROFORMA_MRN                                      NUMBER
     TPROFORMA_VISITID                                  NUMBER
     MTRANSBILL_MRN                                     NUMBER
     MTRANSBILL_VISITID                                 NUMBER
    

    ORA-01730: number of column names specified invalid

    The list of the nmae column you specified for the CREATE VIEW must correspond with the list of SELECTION in the view.

    Twinkle

  • A composite primary key needs of the Unique ID column or not?

    Hello dear,
    I have a table that's the primary key is a key that is composed of two columns and there are like 5 columns of information. You think I'm going to use two columns as the primary key of this table or create a unique ID column.
    Example:
    Employees table:
    Services of table:

    The table of the problem is the Department managers:
    Now, I'll add employee id and service id in this table and Manager info etc... (info does not exist in the employee table), should I use as primary or create the id column in this table?

    Thank you very much.

    You must use the new ID as primary (alter table add constraint primary key,...) you cannot use foreign key as primary :)

  • Error ORA-00911 create a view with PL/SQL

    Hello. Working with SQL Developer, I'm writing a procedure that creates a view.
    After a compilation successful, whenever I try to run it, I get an error ORA-00911 and I'm not able to find the reason.
    Here is my code. Thanks in advance.
      CREATE OR REPLACE PROCEDURE "DWH_STAR"."STORICO_DATA" (
      DATA_INPUT IN VARCHAR2
    )AS
    BEGIN
      EXECUTE IMMEDIATE '
        CREATE OR REPLACE FORCE VIEW DWH_STAR.V_PORT_STOR_DATA (DATA_DESC, CLIENTE_KEY, PRODOTTO_KEY, AGENTE_KEY, TIPOLOGIA_KEY, 
        NUM_ORDINE, NUM_UNITA, RICAVO_LORDO, RICAVO_NETTO, COSTO_STD_TOTALE, GROSS_PROFIT) AS 
        SELECT
          dt.DATA_DESC,
          fv.CLIENTE_KEY,
          fv.PRODOTTO_KEY,
          fv.AGENTE_KEY,
          fv.TIPOLOGIA_KEY,
          fv.NUM_ORDINE,
          SUM (NUM_UNITA) NUM_UNITA,
          SUM (RICAVO_LORDO) RICAVO_LORDO,
          SUM (RICAVO_NETTO) RICAVO_NETTO,
          SUM (COSTO_STD_TOTALE) COSTO_STD_TOTALE,
          SUM (GROSS_PROFIT) GROSS_PROFIT
        FROM
          F_VENDUTO fv, D_TEMPO dt
        WHERE
          fv.TEMPO_KEY = dt.TEMPO_KEY
          AND TO_NUMBER(TO_CHAR(dt.DATA_DESC,''YYYYMMDD'')) <=' || DATA_INPUT ||'
        GROUP BY
          fv.CLIENTE_KEY,
          fv.PRODOTTO_KEY,
          fv.AGENTE_KEY,
          fv.TIPOLOGIA_KEY,
          fv.NUM_ORDINE,
          dt.DATA_DESC
        ORDER BY 
          dt.DATA_DESC, 
          fv.CLIENTE_KEY,
          fv.PRODOTTO_KEY,
          fv.AGENTE_KEY,
          fv.TIPOLOGIA_KEY,
          fv.NUM_ORDINE;
        UNION
        SELECT
          dt.DATA_DESC,
          fs.CLIENTE_KEY,
          fs.PRODOTTO_KEY,
          fs.AGENTE_KEY,
          fs.TIPOLOGIA_KEY,
          fs.NUM_ORDINE,
          - SUM (NUM_UNITA) NUM_UNITA,
          - SUM (RICAVO_LORDO) RICAVO_LORDO,
          - SUM (RICAVO_NETTO) RICAVO_NETTO,
          - SUM (COSTO_STD_TOTALE) COSTO_STD_TOTALE,
          - SUM (GROSSO_PROFIT) GROSS_PROFIT
        FROM
          F_SPEDITO fs, D_TEMPO dt
        WHERE
          (fs.CAUSA_RESO_KEY = 0
           AND fs.TEMPO_KEY = dt.TEMPO_KEY
           AND TO_NUMBER(TO_CHAR(dt.DATA_DESC,''YYYYMMDD'')) <=' || DATA_INPUT ||'
           )
        GROUP BY
          fs.CLIENTE_KEY,
          fs.PRODOTTO_KEY,
          fs.AGENTE_KEY,
          fs.TIPOLOGIA_KEY,
          fs.NUM_ORDINE,
          dt.DATA_DESC
        ORDER BY 
          dt.DATA_DESC, 
          fs.CLIENTE_KEY,
          fs.PRODOTTO_KEY,
          fs.AGENTE_KEY,
          fs.TIPOLOGIA_KEY,
          fs.NUM_ORDINE
      '
      ;
    END;
    /
     

    delete the order and the semicolon (;) of the first select statement. I hope you know that the operator union the same set of columns to be selected.

    But try to avoid to create objects on the fly, unless and until it is absolutely necessary and inevitable.

    Concerning

    REDA

    Published by: R.Subramanian on June 21, 2010 07:52

    Published by: R.Subramanian on June 21, 2010 07:53

  • create a view with subquery generating insufficient privileges!

    Hello
    I want to create a view by a DB user with DBA role, the view is based on a query that extracts data from 2 users, next to the query contains the subquery. When I run the query itself - without clause CREATE VIEW - it works and gets the data, but when I try to create a view based on this request, it generates ORA-01031: insufficient privileges pointing to the subquery.
    Any suggestion.

    Saad,

    Hello

    To use the table in a view, privileges must be granted directly to the owner of the view (or public). Privileges granted to a role are not enough to use the table in a view.

  • How to create a view with "WITH CLAUSE"

    Hello

    I have one query with 'BY' ARTICLE, I need to create a view of this query. But I get the error message like

    ORA-32034: Unsupported sue clause.

    Please help me...!

    Please find below my request...!

    WITH RANGE
             AS (SELECT A.MASTERMACHINEID,
                        a.startdate,
                        a.enddate,
                        a.startdate - (1 / 3) + (lvl) * 1 / 3 SHIFT_ST_DT,
                        a.startdate + (lvl) * 1 / 3 AS SHIFT_END_DT,
                        a.quantity,
                        (LEAST ( enddate, TODATE) - GREATEST ( FROMDATE, startdate)) * 24 TOTAL_HRS,
                        (enddate - startdate) * 24 AVAIL,
                       todate,
                       fromdate
                  FROM OMP A,
                       (SELECT LEVEL lvl
                          FROM (SELECT MAX (enddate - startdate) AS diff FROM OMPWORKORDER)
                        CONNECT BY LEVEL <= (diff) * 3),
                       MASTER B
                 WHERE A.MASTERMACHINEID = B.MASTERMACHINEID 
                   AND lvl / 3 <=(enddate - startdate) + 1
                ORDER BY SHIFT_ST_DT)
       SELECT shift_date,
              shift_num,
              shift_hrs,
              DECODE (SIGN (SHUT_DWN_TIME), -1, 0, SHUT_DWN_TIME),
              8 - DECODE (SIGN (SHUT_DWN_TIME), -1, 0, SHUT_DWN_TIME) shift_avail_hrs,
              qty,
              total_qty
         FROM (SELECT TRUNC (SHIFT_ST_DT) shift_date,
                      ROW_NUMBER () OVER (PARTITION BY TRUNC (SHIFT_ST_DT) ORDER BY SHIFT_ST_DT) shift_num,
                      8 shift_hrs,
                      (LEAST ( SHIFT_END_DT, TODATE) - GREATEST ( FROMDATE, SHIFT_ST_DT)) * 24
                        SHUT_DWN_TIME,
                      quantity / (avail - TOTAL_HRS) qty,
                      round(((SHIFT_END_DT - SHIFT_ST_DT) * 24 - (LEAST (SHIFT_END_DT, TODATE) - GREATEST (FROMDATE, SHIFT_ST_DT)) * 24)  * QuantiTY / (AVAIL - TOTAL_HRS),2)
                         TOTAL_QTY
                 FROM RANGE A );
    Concerning
    KPR

    Published by: BluShadow on March 17, 2011 09:48
    addition of {noformat}
    {noformat} tags for readability                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

    Try to create the view on the next request, if it helps you:

    SELECT shift_date,
        shift_num,
        shift_hrs,
        decode(SIGN(shut_dwn_time),     -1,     0,     shut_dwn_time),
        8 -decode(SIGN(shut_dwn_time),     -1,     0,     shut_dwn_time) shift_avail_hrs,
        qty,
        total_qty
    FROM
        (
            SELECT TRUNC(shift_st_dt) shift_date,
                 row_number() over(PARTITION BY TRUNC(shift_st_dt)
             ORDER BY shift_st_dt) shift_num,
                 8 shift_hrs,
                (least(shift_end_dt,      todate) -greatest(fromdate,      shift_st_dt)) *24 shut_dwn_time,
                 quantity /(avail -total_hrs) qty,
                 ROUND(((shift_end_dt -shift_st_dt) *24 -(least(shift_end_dt,      todate) -greatest(fromdate,      shift_st_dt)) *24) *quantity /(avail -total_hrs),      2) total_qty
             FROM
             (
                  SELECT a.mastermachineid,
                     a.startdate,
                     a.enddate,
                     a.startdate -(1 / 3) +(lvl) *1 / 3 shift_st_dt,
                     a.startdate +(lvl) *1 / 3 AS
                 shift_end_dt,
                     a.quantity,
                    (least(enddate,      todate) -greatest(fromdate,      startdate)) *24 total_hrs,
                    (enddate -startdate) *24 avail,
                     todate,
                     fromdate
                 FROM omp a,
                        (SELECT LEVEL lvl
                     FROM
                        (SELECT MAX(enddate -startdate) AS
                        diff
                         FROM ompworkorder)
                    CONNECT BY LEVEL <=(diff) *3),
                     master b
                 WHERE a.mastermachineid = b.mastermachineid
                 AND lvl / 3 <=(enddate -startdate) + 1
                 ORDER BY shift_st_dt
             ) a
         )
    ;
    

    Kind regards
    Dipali.l

  • Create a view with a column change journal

    Hello

    I have the following table:

    create table test1)

    number of site_number

    date of change_date,

    number of area_ha);

    insert into test1 values (1, TO_DATE('1/1/2007','DD/MM/RRRR'), 20);

    insert into test1 values (1, TO_DATE('1/1/2008','DD/MM/RRRR'), 30);

    insert into test1 values (1, TO_DATE('1/1/2009','DD/MM/RRRR'), 25);

    insert into test1 values (2, TO_DATE('1/1/2007','DD/MM/RRRR'), 50);

    insert into test1 values (2, TO_DATE('1/1/2008','DD/MM/RRRR'), 60);

    insert into test1 values (2, TO_DATE('1/1/2009','DD/MM/RRRR'), 60);

    insert into test1 values (3, TO_DATE('1/1/2007','DD/MM/RRRR'), 20);

    insert into test1 values (3, TO_DATE('1/1/2008','DD/MM/RRRR'), 25);

    insert into test1 values (3, TO_DATE('1/1/2009','DD/MM/RRRR'), 30);

    What I want to do is to have a view based on the table above which includes a column of change (change_log below) based on the anterior surface (area_ha) for each specific site_number. For example in the first line site_number 1 has increased the area of 20 hectares on the 01/01/2007 to 30 hectares on the next change_date for this site that 01/01/2008. How this could be done?

    SITE_NUMBER CHANGE_DATE AREA_HA CHANGE_LOG
    101/01/200720NO CHANGE
    101/01/200830ADDED SPACE
    101/01/200925DELETED DOMAIN
    201/01/200750NO CHANGE
    201/01/200860ADDED SPACE
    201/01/200960NO CHANGE
    301/01/200720NO CHANGE
    301/01/200825ADDED SPACE
    301/01/200930ADDED SPACE

    I am using oracle 11g R2

    Select site_number,

    change_date,

    area_ha,

    sign of case (area_ha - lag(area_ha,1,area_ha) over (partition by order of change_date site_number))

    When 1 "AREA ADDED.

    When-1 then "ZONE DELETED."

    Another 'NO CHANGE'

    end change_log

    of test1

    order of site_number,

    change_date

    /

    SITE_NUMBER CHANGE_DA AREA_HA CHANGE_LOG
    ----------- --------- ---------- ------------
    1 1 JANUARY 07 20 NO CHANGE
    1 1 JANUARY 08-30 ADDED SPACE
    1 1 JANUARY 09 25 DELETED AREA
    2 1 JANUARY 07 50 NO. CHANGE
    2 1 JANUARY 08 60 ADDED SECTOR
    2 1 JANUARY 09 60 NO. CHANGE
    3 1ST JANUARY 07 20 NO. CHANGE
    3 AREA 1 JANUARY 08 25 ADDED
    3 1ST JANUARY 09 30 ADDED AREA

    9 selected lines.

    SQL >

    SY.

  • Create a table with auto increase of columns

    I remember there is a single line of SQL to create a column that can auto increase. -Does anyone know it? something like below:

    CREATE TABLE HAS
    (
    ID INTEGER AUTOINCREMENT
    )

    Thanks a lot for your help!

    Not in Oracle, no.

    You can simulate the SQL Server AUTOINCREMENT feature by

    -Creating a table
    -Creating a sequence
    -Creating a level trigger line BEFORE INSERT on the table that populates the column, i.e.

    CREATE TABLE a (
      a_id integer primary key
    );
    
    CREATE SEQUENCE a_id_seq;
    
    CREATE TRIGGER trg_a
      BEFORE INSERT ON a
      FOR EACH ROW
    BEGIN
      SELECT a_id_seq.nextval
        INTO :new.a_id
        FROM dual;
    END;
    

    Justin

  • Problems with slot-shaped table and set the values of column

    Hello

    I have a problem with a tabular presentation.

    I have two tables

    P_detail and table v_master

    columns of v_master:
    v_id
    v_Name
    v_info

    columns of p_detail:
    P_ID
    p_master_fk
    p_name
    p_info

    I want to have a tabular presentation where I can store permanent data retail values. That's why I want to keep the default main column join the detail columns.
    In SQL, I can do this with an outer join:

    SELECT m.v_name, d.p_master_fk, d.p_name, d.p_info
    OF v_master, p_detail
    WHERE v_id = p_master_fk (+)

    I get the lines that exist for the master data and can add values for the columns of detail. I removed the "add lines" because that makes no sense, because the amount lines are already offered at the opening of the tabular presentation.

    Now, I want to get/save the v_id (main table) in the p_master_fk column value

    How can I do this?

    Thank you and best regards,
    Matthias

    Hello

    One approach is to use a database instead trigger. If you define a database view using the query:

    SELECT m.v_id, m.v_name, d.p_id, d.p_master_fk, d.p_name, d.p_info
    OF v_master m, p_detail d
    WHERE v_id = p_master_fk (+)

    Then, create a trigger on the view that will insert in the detail table if d.p_id is null and update the secondary table if d.p_id is not null instead.

    The Apex tabular form is then based on the view (with identifiers like hidden columns) and all treatments multirow Apex should work without modification.

    Rod West

  • Creating a view using multiple joins - by reducing the number of output lines

    It is difficult to put into words exactly what I want to implement, so I'll just use an example. Let's say I have the following database:

    game (id, time, place)

    Reader (game_id, name)

    Referee (game_id, name)

    Foreign keys:
    Player (game_id) references game (id)
    Referee (game_id) references game (id)

    It is a very special match, in which:
    A game can have 1 to many players
    A game can have from 1 to several arbitrators

    I want to create the following view:

    Game_overview (Game_id, time, player, referee)

    It's easy to create this view with the following output:

    Game1, 15:00, player1, Referee1
    Game1, 15:00, player1, Referee2
    Game1, 15:00, player2, Referee1
    Game1, 15:00, player2, Referee2
    Game1, 15:00, Joueur3, null
    08:00, player1, Referee1, GaMe2
    GaMe2, 08:00, player1, Referee2

    HOWEVER, I want it to look like this:

    Game1, 15:00, player1, Referee1
    Game1, 15:00, player2, Referee2
    Game1, 15:00, Joueur3, null
    08:00, player1, Referee1, GaMe2
    GaMe2, 08:00, null, Referee2

    I think that this should not be TOO difficult to solve, but I can't really get my head around it.

    Welcome to the forum!

    Whenever you have a problem, please post CREATE TABLE and INSERT statements for your sample data. Sinve it's your first post, I'll do it for you:

    CREATE TABLE     game
    (       id          VARCHAR2 (10)     PRIMARY KEY
    ,     time          VARCHAR2 (10)
    --,     location     VARCHAR2 (10)     -- No need to include columns that play no role in this problem
    );
    
    INSERT INTO game (id, time) VALUES ('Game 1',  '3PM');
    INSERT INTO game (id, time) VALUES ('Game 2',  '8AM');
    
    CREATE TABLE     player
    (       game_id          VARCHAR2 (10)
    ,     name          VARCHAR2 (10)
    );
    
    INSERT INTO  player (game_id, name) VALUES ('Game 1',  'Player 1');
    INSERT INTO  player (game_id, name) VALUES ('Game 1',  'Player 2');
    INSERT INTO  player (game_id, name) VALUES ('Game 1',  'Player 3');
    INSERT INTO  player (game_id, name) VALUES ('Game 2',  'Player 1');
    
    CREATE TABLE     referee
    (       game_id          VARCHAR2 (10)
    ,     name          VARCHAR2 (10)
    );
    
    INSERT INTO  referee (game_id, name) VALUES ('Game 1',  'Referee 1');
    INSERT INTO  referee (game_id, name) VALUES ('Game 1',  'Referee 2');
    INSERT INTO  referee (game_id, name) VALUES ('Game 2',  'Referee 1');
    INSERT INTO  referee (game_id, name) VALUES ('Game 2',  'Referee 2');
    

    In this way, people who want to help you can recreate the problem and test their ideas.

    In addition, to say what version of Oracle you are using. The following query will work in Oracle 9.1 or more.

    What you asked is what I call a Query, fixed-price , and this is a way to do it:

    WITH     player_plus     AS
    (
         SELECT     game_id
         ,     name
         ,     ROW_NUMBER () OVER ( PARTITION BY  game_id
                                   ORDER BY          name
                           )         AS r_num
         FROM    player
    )
    ,     referee_plus     AS
    (
         SELECT     game_id
         ,     name
         ,     ROW_NUMBER () OVER ( PARTITION BY  game_id
                                   ORDER BY          name
                           )         AS r_num
         FROM    referee
    )
    SELECT       g.id
    ,       g.time
    ,       p.name     AS player_name
    ,       r.name     AS referee_name
    FROM             player_plus     p
    FULL OUTER JOIN  referee_plus   r  ON   p.game_id     = r.game_id
                                    AND     p.r_num          = r.r_num
    JOIN           game          g  ON     g.id          = COALESCE (p.game_id, r.game_id)
    ORDER BY  g.id
    ,         COALESCE (p.r_num, r.r_num)
    ;
    

    Output:

    ID         TIME       PLAYER_NAM REFEREE_NA
    ---------- ---------- ---------- ----------
    Game 1     3PM        Player 1   Referee 1
    Game 1     3PM        Player 2   Referee 2
    Game 1     3PM        Player 3
    Game 2     8AM        Player 1   Referee 1
    Game 2     8AM                   Referee 2
    

    I see that you have more arbitrators than players in a game. If such was not the case, then you might make it a bit more efficient using a LEFT OUTER JOIN between p and r, rather than a FULL OUTER JOIN, and you can also use only the columns of p where I use COALESCE.

    Published by: Frank Kulash, March 9, 2012 18:15
    Fixed spelling

  • View with a column that is derived from a function

    We can create a view with a column being filled using a pl/sql script, which uses 2 other columns on the same line as input?

    Example,
    Let's say I have a vision with

    Reg. Don't | Total | Customer account | Flag of billing. CodeFn
    $1234 45 2109 Y < value in this column would be what returns the expected script pl/sql, after using the Reg # (1234) and Total (45) as entries >
    $1236 15 2101 Y < input values would be 1236 & 15 >.

    Basically, I would like the script to generate a number that is returned in this column rather than do a simple Select stmt to extract columns from other tables/views.

    Edit: The point of view does not display right... Here is a picture
    view

    Thank you!

    Published by: jess_saunders on May 8, 2012 14:05

    Hello

    jess_saunders wrote:
    We can create a view with a column being filled using a pl/sql script, which uses 2 other columns on the same line as input?

    Example,
    Let's say I have a vision with

    Reg. Don't | Total | Customer account | Flag of billing. CodeFn
    $1234 45 2109 Y
    $1236 15 2101 Y .

    Of course, you can use a function that you created in the same way that you would use a built-in function:

    CREATE OR REPLACE VIEW     view_x
    AS
    SELECT  reg_no
    ,     total
    ,     customer_account
    ,     billing_flag
    ,     my_function (reg_no, total)     AS codefn
    FROM     table_x
    ;
    

    You cannot reference the procedures or anyonymous blocks in a CREATE VIEW statement (or any other SQL statement of stinks); only functions.

    Basically, I would like the script to generate a number that is returned in this column rather than do a simple Select stmt to extract columns from other tables/views.

    I don't know what you're saying here.
    As long as the function has no arguments, or make any kind of DML or DDL, then you can use it in the definition of the view, as stated above. The function failed to contain SELECT statements.
    Your notice must be based on other tables or views. If she does not really need anything from any other table, you can base your opinion on double. A CREATE VIEW statement must contain a query, and a query in Oracle must refer to a table or a view.

Maybe you are looking for