Insert records from a single to two related tables table

DB - 10G
OS - XP

We have thousands of records delimited by commas that we want to insert in a normalized table structure.

I created a group of test data that can be found at the end of this post.


I have csv files that look like this;

Donald, huey
Dewey, Donald
Donald, louie

And I want that data to be inserted into a table separate two like that;

table named PARENTS
parent_name PK
1 donald

Table named for CHILDREN
child_name fk PK
1 1 huey
1 2 dewey
1 3 louie


I built an insert query that looks like this;

INSERT ALL
IN parents (parent_id, parent_name) VALUES (parents_seq.nextval, parent_name)
IN children (children_id, parent_id, child_name) VALUES (children_seq.nextval, parents_seq.nextval, child_name)
SELECT parent_name, child_name
SOURCES;

And this has resulted in the following:

Table named PARENTS
PK child_name
1 DONALD
2 DONALD
3 DONALD

Table named PARENTS
child_name fk PK
1 1 HUEY
2 2 DEWEY
3 3 LOUIE

Anyone have any ideas on how I could accomplish this task?

This is some sample data;

[code]
Parents_seq SEQUENCE DROP;
Sources_seq SEQUENCE DROP;
Children_seq SEQUENCE DROP;
Sources of DROP TABLE.
DROP TABLE children;
Parents of DROP TABLE;

CREATE SEQUENCE PARENTS_SEQ MINVALUE MAXVALUE 1 1000000000000000000000000000 INCREMENT OF 1 START WITH 1 CACHE 20 ALL NOCYCLE.

CREATE THE PARENTS TABLE
(THE NUMBER (8) OF PARENT_ID NOT NULL)
PARENT_NAME VARCHAR2 (50 CHAR) NOT NULL,
CONSTRAINT PARENTS_PK PRIMARY KEY (PARENT_ID)
);

create or replace
PARENTS_BI RELAXATION
FRONT
INSERT OR UPDATE PARENTS
FOR EACH START OF LINE

IF THE INSERTION

IF: NEW. PARENT_ID IS NULL THEN
SELECT PARENTS_SEQ.nextval IN: NEW. PARENT_ID FROM dual;
END IF;

END IF;

END;
/


CREATE SEQUENCE SOURCES_SEQ MINVALUE MAXVALUE 1 1000000000000000000000000000 INCREMENT OF 1 START WITH 1 CACHE 20 ALL NOCYCLE.

CREATE TABLE SOURCES
(THE NUMBER (8) OF SOURCE_ID NOT NULL)
PARENT_NAME VARCHAR2 (50 CHAR) NOT NULL,
CHILD_NAME VARCHAR2 (50 CHAR) NOT NULL,
CONSTRAINT SOURCES_PK PRIMARY KEY (SOURCE_ID)
);

create or replace
SOURCES_BI RELAXATION
FRONT
INSERT OR UPDATE ON SOURCES
FOR EACH START OF LINE

IF THE INSERTION

IF: NEW. SOURCE_ID IS NULL THEN
SELECT SOURCES_SEQ.nextval IN: NEW. SOURCE_ID FROM dual;
END IF;

END IF;

END;
/

INSERT INTO SOURCES (PARENT_NAME, CHILD_NAME) VALUES ('DONALD', 'HUEY');
INSERT INTO SOURCES (PARENT_NAME, CHILD_NAME) VALUES ('DONALD', 'DEWEY');
INSERT INTO SOURCES (PARENT_NAME, CHILD_NAME) VALUES ('DONALD', 'LOUIE');
Commit;


CREATE SEQUENCE CHILDREN_SEQ MINVALUE MAXVALUE 1 1000000000000000000000000000 INCREMENT OF 1 START WITH 1 CACHE 20 ALL NOCYCLE.

FAST * CREATE TABLE *.
CREATE TABLE CHILDREN
(CHILDREN_ID NUMBER OF NON-NULL
, PARENT_ID NUMBER NOT NULL
CHILD_NAME VARCHAR2 (50 CHAR) NOT NULL,
CONSTRAINT CHILDREN_PK PRIMARY KEY (CHILDREN_ID)
);

create or replace
CHILDREN_BI RELAXATION
FRONT
INSERT OR UPDATE ON CHILDREN
FOR EACH START OF LINE

IF THE INSERTION

IF: NEW. CHILDREN_ID IS NULL THEN
SELECT CHILDREN_SEQ.nextval IN: NEW. CHILDREN_ID FROM dual;
END IF;

END IF;

END;
/

[code]

Looks like it's a way to do this:

insert into parents (parent_name) select distinct parent_name from sources;

select *
  from parents;
PARENT_ID              PARENT_NAME
---------------------- --------------------------------------------------
1                      DONALD

insert into children (parent_id, child_name)
select p.parent_id, s.child_name
  from sources s
  join parents p
    on (s.parent_name = p.parent_name);

select *
  from children;

CHILDREN_ID            PARENT_ID              CHILD_NAME
---------------------- ---------------------- --------------------------------------------------
1                      1                      HUEY
2                      1                      DEWEY
3                      1                      LOUIE

Tags: Database

Similar Questions

  • Use with need to collect in bulk to insert records from multiple tables

    Hello

    I plsql record type with several tables with multiple columns. so when I used bulk collect with education for ALL. I want to insert records in multiple tables.

    Please give me suggestions.

    ForAll is designed to be used with a single DML statement, which may include dynamic SQL statements. However, I do not know what advantage this will give you your list iteration save several times, one for each table - especially since there is an air show with SQL dynamic.

    Example 1 (dynamic SQL):

    begin

      ...

      forall i in vRecList.First..vRecList.Last
        execute immediate '
        begin
          insert into Table1 (Col1, Col2, Col3) values (:1, :2, :3);
          insert into Table2 (Col1, Col2, Col3) values (:1, :2, :3);
        end;' using vRecList(i).Col1, vRecList(i).Col2, vRecList(i).Col3;
    end;

    Another approach that I should work (but not tested) is using to insert all the Scriptures and based record inserts, but you need to try on your version of Oracle forall has changed between the versions.  In this case vRecList must be compatible with the Table % ROWTYPE and Table2% ROWTYPE type.


    Example 2 (insert all):

    begin

      ...

      forall i in vRecList.First..vRecList.Last

        insert all

          into Table1 values vRecList(i)
          into Table2 values vRecList(i)
        select 1 from dual;

    end;

  • Inserting record than a single SHARED folder

    Hi all,
    
    
    I have table ap_comm_po  (structure)
    ap_comm_po_id ,
    po_num ,
    status ,
    status_date,
    country_id
    
    country (structure)
    country_id,
    country_name
    
    table: ap_comm_country 
    ap_comm_po_country_id
    po_num ,
    ap_comm_country_name 
     
    
    Can some please help me I have data like this.
    ap_comm_po
    ap_comm_po_id  po_num ber status status_date country
    1111           2222           CAN      1/1/2001     100
    1112           22223           APR      1/1/2002      101 
    1113           22223           APR      1/1/2003      101
    1114           22224           EST      1/1/2004      300
    1115           22225           EST      1/1/2005      400
    
    
    country table
    country_id  country_name
    100          canada
    101           us
    300           malta
    400           france
    
      
    I need to insert into ap_comm_po_country and ap_comm_po_mig table.
       
    
    here is the procedure
    
    CREATE OR REPLACE FUNCTION fn_acp_comm ( p_po_id IN NUMBER)
    RETURN PLS_INTEGER
    AS
    v_count NUMBER; 
    curr_acp_rec acp_comm_po%ROWTYPE;
    curr_acp_dtl_rec acp_comm_po_dtl%ROWTYPE;
    
    TYPE _acp_inserts_tab IS TABLE OF .acp_comm_po%ROWTYPE 
    INDEX BY PLS_INTEGER;
    
    TYPE ap_acp_cntry_inserts_tab IS TABLE OF .acp_comm_po_dtl%ROWTYPE-- 
    INDEX BY PLS_INTEGER; 
    
    acp_inserts acp_inserts_tab;
    acp_cntry_inserts acp_cntry_inserts_tab; 
    
    
    CURSOR acp_csr
    IS
    SELECT ap_comm_po_uid,
    acp_inv_id,
    acp.comm_type, 
    acp_dtl.status_date,,
    acp.application_type
    status_id, 
    ap_eu_flg
    acp_dtl.cntry_flg
    acp.country 
    FROM ap_comm_po_acp acp --,
    JOIN .ap_comm_po_dtl acp_dtl
    ON acp.ap_comm_po_uid = acp_dtl.ap_comm_po_uid 
    AND acp.ap_status= 'CAN' 
    WHERE acp.p_ap_comm_po_id = p_ap_comm_po_id; 
    
    
    BEGIN 
    
    
    FOR acp_rec IN acp_csr
    LOOP
    
    BEGIN 
    SELECT dev3.seq_id.NEXTVAL INTO curr_acp_rec.acp_po_id FROM DUAL;
    curr_acp_rec.acp_inv_id := acp_rec.acp_inv_id;
    curr_acp_rec.status_id := acp_rec.status_id;
    curr_acp_rec.status_date := acp_rec.status_date;
    acp_inserts (curr_acp_rec.ap_comm_po_id) := curr_acp_rec;  
                     
      The problem here is the acp_csr cursor returns more than one record for same po number beacuse of different statuses.
    I need to insert into ap_comm_country table ONLY one record per ap_comm_po_uid. How do I get only one record 
    
                 SELECT  sequence_id.NEXTVAL INTO acp_cntry_inserts .app_country_id FROM DUAL;  
                   acp_cntry_inserts.ap_comm_po_uid:= curr_app_rec.curr_acp_rec.ap_comm_po_id ; 
                   acp_cntry_inserts.country_id           := acp_rec.country_name;
              ...
              ....
    
    END LOOP;
     
    
    -- Create acp data 
    BEGIN
    FORALL acp_idx IN INDICES OF acp_inserts 
    INSERT INTO ap_comm_po_mig VALUES acp_inserts (acp_idx);
    v_count := SQL%ROWCOUNT; 
    EXCEPTION
    
    -- Create acp country data
    BEGIN
    FORALL acp_cntry_idx IN INDICES OF acp_cntry_inserts 
    INSERT INTO ap_comm_country VALUES acp_cntry_inserts (acp_cntry_idx);
    v_count := SQL%ROWCOUNT; 
    EXCEPTION
    
    END; 
     

    Next time, please provide CREATE TABLE and INSERT statements yourself. Here are the ones I did:

    CREATE TABLE AP_COMM_PO (AP_COMM_PO_ID,  PO_NUMBER, STATUS, STATUS_DATE, COUNTRY) AS SELECT
    '1111', 2222,  'CAN', TO_DATE('1/1/2001','mm/dd/yyyy'),  100 FROM DUAL UNION ALL SELECT
    '1112', 22223, 'APR', TO_DATE('1/1/2002','mm/dd/yyyy'),  101  FROM DUAL UNION ALL SELECT
    '1113', 22223, 'APR', TO_DATE('1/1/2003','mm/dd/yyyy'),  101  FROM DUAL UNION ALL SELECT
    '1114', 22224, 'EST', TO_DATE('1/1/2004','mm/dd/yyyy'),  300 FROM DUAL UNION ALL SELECT
    '1115', 22225, 'EST', TO_DATE('1/1/2005','mm/dd/yyyy'),  400 FROM DUAL;
    
    CREATE TABLE COUNTRY(COUNTRY_ID,  COUNTRY_NAME) AS SELECT
    100,  'CANADA' FROM DUAL UNION ALL SELECT
    101,  'us' FROM DUAL UNION ALL SELECT
    300,  'MALTA' FROM DUAL UNION ALL SELECT
    400,  'france' FROM DUAL;
    
    CREATE TABLE AP_COMM_PO_MIG AS
    SELECT AP_COMM_PO_ID,  PO_NUMBER, STATUS, STATUS_DATE
    FROM AP_COMM_PO WHERE 1=0;
    
    CREATE TABLE AP_COMM_COUNTRY AS
    SELECT COUNTRY_ID AP_COMM_PO_COUNTRY_ID,
    PO_NUMBER ,
    COUNTRY_NAME AP_COMM_COUNTRY_NAME
    from COUNTRY, AP_COMM_PO_MIG where 1=0;
    
    CREATE SEQUENCE AP_SEQ;
    CREATE SEQUENCE COUNTRY_SEQ;
    

    Now, I would just make two INSERT statements instead of all this code:

    INSERT INTO AP_COMM_PO_MIG
    select ap_seq.nextval, po_number, status, status_date from ap_comm_po;
    
    INSERT INTO AP_COMM_COUNTRY
    WITH DATA AS (SELECT DISTINCT PO_NUMBER, COUNTRY FROM AP_COMM_PO)
    SELECT COUNTRY_SEQ.NEXTVAL,
    A.PO_NUMBER,
    B.COUNTRY_NAME
    from data a join country b on (a.country = b.country_id);
    
  • Insert all records from a custom to a staging table.

    Hello

    Is it possible to insert all records of a cursor in a custom table using plsql instead of open a cursor, and each record in a loop?

    Thank you

    KK

    Use INSERT INTO your_staging_tbl... SELECT... Of your_cuatom_tbl

  • Issue when inserting records from sql loader

    Hello
    I'm trying to insert record of sql loader, but it's inclusion only a row.
    Help, please.

    Check the log file of causes.

  • Insert records from one table to another table

    Hello

    I want to insert all records in table 1 which are not in table 2 in table2

    o/p
    Insert into table2
    Select * from table1
    where a.id! = b.id;

    Please let me know is there any way I can complete reviews
    insert
      into table2
      select  *
        from  table1
        where id not in (
                         select  id
                           from  table2
                        );
    

    SY.

  • Trigger for two related tables

    Hello

    I have two tables, one i keep the general areas and the other table keep several rates per year related to the first table of field general_id (one to many relationship)

    create table (general)

    number of general_id

    general_type varchar2 (10),

    Description varchar2 (250).

    Notes varchar2 (250).

    State number,

    date of date_de_modification,

    'PK_GENERAL' CONSTRAINT PRIMARY KEY (general_id)

    );

    Insert in general (general_id, general_type, description, notes, status, date_modified)

    values (1, "gen rate", 'Test Desc', 'New folder', 0, sysdate);

    create table rates)

    number of general_id

    number of rate_id,

    Number of exercise,

    number of amount,

    date of date_de_modification,

    "PK_RATES" PRIMARY KEY CONSTRAINT (rate_id)

    );

    Insert rates (general_id, rate_id, fy, amount, date_modified)

    values (1, 1, 2012, 10, sysdate);

    Insert rates (general_id, rate_id, fy, amount, date_modified)

    values (1, 1, 2013, 20, sysdate);

    Insert rates (general_id, rate_id, fy, amount, date_modified)

    values (1, 1, 2014, 30, sysdate);

    How can I create a trigger when any amount is updated in the rate table? Don't need to save anything when insert or remove.

    I wish I had a history table that I can save some old values from the general and charts of rates such as:

    create table hst_rates)

    number of general_id

    Note varchar2 (250),-THE GENERAL TABLE

    State number,-THE GENERAL TABLE

    number of rate_id,

    Number of exercise,

    number of amount,

    date of date_de_modification,

    hst_action

    );

    can I do this?

    OR I can create tables of history for each table. But I have to do a join query to show history.

    How can I have a unique identifier between then?

    Make sense? Any ideas?

    Thanks in advance.

    Why do you not use sum? What happens if the amount is changed several times, do not end up with a bigger number? I think that max (...) Dungeon (dense_rank last date_modified) would be a better choice.

    The unchanged records, you can the union with the rate table before spinning.

  • How to insert rows from an xml file in a table

    IM Using Oracle 11g, is show below error when I run...



    declare
    charString varchar2 (80);
    finalStr varchar2 (400): = null;
    whole rowsp;
    v_FileHandle UTL_FILE. TYPE_DE_FICHIER;
    Start
    -the name of the table specified in our DTD
    xmlgen.setRowsetTag ('Zipcodes');
    -the name of the data set as shown in our DTD
    xmlgen.setRowTag ('mappings');
    -to get the result on the screen
    dbms_output. Enable (100000);
    -Open the XML document in read-only mode
    v_FileHandle: = utl_file.fopen (TMP_DIR1,'XML_NEW_CITIES.) XML', 'r');
    loop
    BEGIN
    UTL_FILE.get_line (v_FileHandle, charString);
    exception
    When no_data_found then
    UTL_FILE.fclose (v_FileHandle);
    "exit";
    END;
    dbms_output.put_line (charstring);
    If finalStr is not null then
    finalStr: = finalStr | charString;
    on the other
    finalStr: = charString.
    end if;
    end loop;
    -for the insertion of XML data in the table
    rowsp: = xmlgen.insertXML('SYS.) Codes POSTAL, finalStr);
    dbms_output.put_line ('INSERT FACT' |) To_char (rowsp));
    xmlgen.resetOptions;
    end;
    /




    XML_NEW_CITIES. XML is

    <? XML version = "1.0"? >
    < zip codes >
    < Record mappings = "4" >
    CA < STATE_ABBREVIATION > < / STATE_ABBREVIATION >
    < ZIPCODE > 94301 < / code >
    < CITY > Palo Alto < / CITY >
    < / maps >
    < Record mappings = "5" >
    < STATE_ABBREVIATION > CO < / STATE_ABBREVIATION >
    < ZIPCODE > 80323 < / code >
    < ZIP_CODE_EXTN > 9277 < / ZIP_CODE_EXTN >
    Boulder < CITY > < / CITY >
    < / maps >
    < / zip codes >




    Error report:
    ORA-06550: line 8, column 3:
    PLS-00201: identifier ' XMLGEN. SETROWSETTAG' must be declared
    ORA-06550: line 8, column 3:
    PL/SQL: Statement ignored
    ORA-06550: line 10, column 3:
    PLS-00201: identifier ' XMLGEN. SETROWTAG' must be declared
    ORA-06550: line 10, column 3:
    PL/SQL: Statement ignored
    ORA-06550: line 14, column 34:
    PLS-00201: identifier 'TMP_DIR1' must be declared.
    ORA-06550: line 14, column 3:
    PL/SQL: Statement ignored
    ORA-06550: line 31, column 12:
    PLS-00201: identifier ' XMLGEN. INSERTXML' must be declared
    ORA-06550: line 31, column 3:
    PL/SQL: Statement ignored
    ORA-06550: line 33, column 3:
    PLS-00201: identifier ' XMLGEN. RESETOPTIONS' must be reported
    ORA-06550: line 33, column 3:
    PL/SQL: Statement ignored
    06550 00000 - "line %s, column % s:\n%s".
    * Cause: Usually a PL/SQL compilation error

    Published by: 898235 on November 20, 2011 23:02

    OK, so you tried the XMLTable example, or wait for someone write at the bottom for you? :)

    You must first create an object of directory Oracle pointing to the physical location of the file (must be somewhere on the db server or at a location that the db server can access on the network).
    Then, create the procedure, in this case a simple INSERT SELECT:

    SQL> create directory tmp_dir as 'c:\temp';
    
    Directory created
    
    SQL> create table zipcodes (
      2   state_abbreviation  varchar2(2),
      3   zipcode             varchar2(5),
      4   zip_code_extn       varchar2(10),
      5   city                varchar2(80)
      6  );
    
    Table created
    
    SQL> CREATE OR REPLACE PROCEDURE insertZipcodes (
      2    p_directory IN VARCHAR2
      3  , p_filename  IN VARCHAR2
      4  )
      5  IS
      6  BEGIN
      7
      8    INSERT INTO zipcodes (state_abbreviation, zipcode, zip_code_extn, city)
      9    SELECT state_abbreviation
     10         , zipcode
     11         , zip_code_extn
     12         , city
     13    FROM XMLTable('/Zipcodes/mappings'
     14           passing xmltype(bfilename(p_directory, p_filename), nls_charset_id('AL32UTF8'))
     15           columns state_abbreviation varchar2(2)  path 'STATE_ABBREVIATION'
     16                 , zipcode            varchar2(5)  path 'ZIPCODE'
     17                 , zip_code_extn      varchar2(10) path 'ZIP_CODE_EXTN'
     18                 , city               varchar2(80) path 'CITY'
     19         )
     20    ;
     21
     22  END;
     23  /
    
    Procedure created
    
    SQL> exec insertZipcodes('TMP_DIR', 'xml_new_cities.xml');
    
    PL/SQL procedure successfully completed
    
    SQL> commit;
    
    Commit complete
    
    SQL> select * from zipcodes;
    
    STATE_ABBREVIATION ZIPCODE ZIP_CODE_EXTN CITY
    ------------------ ------- ------------- ---------------
    CA                 94301                 Palo Alto
    CO                 80323   9277          Boulder
     
    
  • Inserting data from a query to an existing table

    How do I change my code to make it work correctly? It currently compiles I think because the program believes that the size of v_stats_5d_1 can be different from c_stats_5d_1. I have these errors:

    LINE/COL ERROR

    -------- ------------------------------------

    30/10 PL/SQL: statement ignored

    30/23 PL/SQL: ORA-00947: not enough values

    CREATE OR REPLACE PACKAGE IN THE PKG_RISK_MONITOR

    PROCEDURE CREATE_STATS_5D)

    P_CONTEXT_DATE IN VARCHAR2

    );

    END PKG_RISK_MONITOR;

    /

    CREATE OR REPLACE PACKAGE BODY PKG_RISK_MONITOR AS

    PROCEDURE CREATE_STATS_5D)

    P_CONTEXT_DATE IN VARCHAR2

    )

    IS

    l_ct NUMBER;

    CURSOR c_stats_5d_1

    IS

    SELECT MIND_ACCOUNTS. CLIENT_ID, MIND_ACCOUNTS. CLIENT_NAME, SUM (DATA. CREATED_TRANSACTIONS_NUMBER) AS SUM_CREATED_TRX_NUMBER, SUM (DATA. CREATED_refunds_NUMBER) SUM_CREATED_REFUNDS_NUMBER, SUM (DATA. CREATED_TRANSACTIONS_value * Conversion_rate) CREATED_TRX_EUR_VALUE, DATA. PROCESSING_DATE

    OF (MIND_ACCOUNTS INNER JOIN DATA ON MIND_ACCOUNTS. ACCOUNT_ID = DATA. CURRENCY_conversion INNER JOIN MERCHANT_CID) ON THE DATA. CURRENCY = CURRENCY_conversion. CURRENCY

    GROUP OF MIND_ACCOUNTS. CLIENT_ID, MIND_ACCOUNTS. CLIENT_NAME, DATA. PROCESSING_DATE

    (DATA. PROCESSING_DATE > = TO_DATE (P_CONTEXT_DATE, 'dd-mm-yyyy')-4) and DATA. PROCESSING_DATE < = TO_DATE (P_CONTEXT_DATE, ' dd-mm-yyyy "")

    ;

    v_stats_5d_1 "TMP_STATS_5D_1" % rowtype;

    BEGIN

    -Insert subquery data into an empty table

    OPEN c_stats_5d_1.

    LOOP

    SEEK c_stats_5d_1 INTO v_stats_5d_1;

    EXIT WHEN c_stats_5d_1% NOTFOUND;

    INSERT INTO 'TMP_STATS_5D_1 '.

    VALUES (v_stats_5d_1);

    END LOOP;

    END CREATE_STATS_5D;

    END PKG_RISK_MONITOR;

    /

    DISPLAY ERRORS

    THX. Managed to get there in the end:

    CREATE OR REPLACE PACKAGE IN THE PKG_RISK_MONITOR

    PROCEDURE CREATE_STATS_5D)

    P_CONTEXT_DATE IN VARCHAR2

    );

    END PKG_RISK_MONITOR;

    /

    CREATE OR REPLACE PACKAGE BODY PKG_RISK_MONITOR AS

    PROCEDURE CREATE_STATS_5D)

    P_CONTEXT_DATE IN VARCHAR2

    )

    IS

    l_ct NUMBER;

    v_sql VARCHAR2 (1000);

    BEGIN

    -Determine whether the table exists.

    Select count (*) in l_ct

    from user_tables

    where table_name = 'TMP_STATS_5D_1 ';

    -Remove the table if it exists.

    If l_ct = 1 then

    run immediately "drop table TMP_STATS_5D_1;

    end if;

    v_sql: = q'[CREATE TABLE 'TMP_STATS_5D_1' AS

    SELECT m.client_id,

    m.client_name,

    Sum (d.created_transactions_number) AS sum_created_trx_number,

    Sum (d.created_refunds_number) AS sum_created_refunds_number,

    Sum(d.created_transactions_value * conversion_rate) AS created_trx_eur_value,

    d.processing_date

    M 'MIND_ACCOUNTS '.

    INNER JOIN 'DATA' m.account_id d = d.merchant_cid

    INNER JOIN 'CURRENCY_CONVERSION' c ON d.currency = c.currency

    WHERE (d.processing_date > = To_date ('] '))

    || P_CONTEXT_DATE |

    q'[(', ' dd-mm-yyyy') (-4) AND d.processing_date]<=>

    || P_CONTEXT_DATE |

    q'[',' dd-mm-yyyy ")"]

    GROUP OF m.client_id, m.client_name, d.processing_date] ";

    immediately run v_sql;

    END CREATE_STATS_5D;

    END PKG_RISK_MONITOR;

    /

    DISPLAY ERRORS

  • I need to insert data from the parent to the child table inheritance

    Hi everyone I m using jdeveloper 12

    I have this use EDC:

    I m trying to have mini-programm in which i

    create porject, used to create and assign an employee as the project manager:

    It is therefore my phyiscal using uml data model

    cap1.PNG

    cap2.PNG

    My problem is: I need to see the values in the employee table, choose an employee id s and with the form create in this table: Project Manager: insert the employee with the s project id id

    but when I navigate to the form it is already full of I don't know why

    I did not understand your problem clearly.

    Could you please explain the problem with some screen shots and step by step flow?

    See you soon

    AJ

  • Synchronization between RDF store and relational table

    I start this question in a new thread, as it goes in a field of another problem

    Is one of the option to model the attributes of the object to store the attributes in a separate relational table and a SQL allows to attach graphic query results. Now, here's a situation, if we want to join, we need to keep a few key reference in the RDF data store, so that they can join together. But it leaves a question, how do synchronize us data? Suppose that we keep a user node in RDF with the user ID property and keep all other modules in the relational table. When join us, we can reach by user ID. But if we remove this record from the user in the relational table, probably RDF will not delete this user node in the graph data store. Am I correct on this point or Oracle has a sort of way to maintain data synchronization?

    Thank you.

    Hi HansC,

    Sorry for the late reply.

    When a row is deleted from a relational table, its correspondent/associated triple (s) will NOT will be removed one or more RDF models unless there is a custom logic to handle this.

    For example, we can define a trigger on the relational table to manage the synchronization of the data. Another way is to use the existing track changes

    mechanism (motion Flashback, Golden Gate etc.) to preserve the synchronization data.

    Thank you

    Zhe Wu

  • Insertion of XMLTABLE to RELATIONAL table

    Hello

    I have a Realational table


    CREATE TABLE VALU_RSLT)
    VALU_RSLT_ID NUMBER OF NON-NULL,
    NUMBER OF FRD_RQST_INFO_ID
    NUMBER OF CERT_NBR (12: 0),
    VALUATIONMETHODTYPE VARCHAR2 (4000).
    VALUATIONMODEL VARCHAR2 (4000).
    EARNED NUMBER (20: 5).
    NUMBER OF VALUATIONLOW (20: 5),
    NUMBER OF VALUATIONHIGH (20: 5),
    NUMBER OF CONFIDENCESCORE
    CONFIDENCEDESC VARCHAR2 (255),
    CRT_BY_USR_ID VARCHAR2 (255),
    CRT_TMST TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    LAST_UPD_BY_USR_ID VARCHAR2 (255),
    LAST_UPD_TMST TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );



    VALU_RSLT_ID - is a sequence object.


    Select tx. FRD_RQST_INFO_ID, CERT_NBR, temp.*
    OF FRD_XML_TEST1 tx.
    XMLTABLE ('/ DRIVEResponse/loan/assessments/ValuationResult ')
    TX OF PASSAGE. RSP_XML
    PATH of COLUMNS 'ValuationMethodType' VARCHAR2 (4000) "@ValuationMethodType."
    Path of 'ValuationModel' VARCHAR2 (4000) "@ValuationModel."
    "Assessment" PATH of NUMBER (20.5) "@Valuation."
    Path of "ValuationLow" NUMBER (20.5) "@ValuationLow."
    Path of "ValuationHigh" NUMBER (20.5) "@ValuationHigh."
    PATH of NUMBER "ConfidenceScore" "@ConfidenceScore"
    PATH of VARCHAR2 (255) 'ConfidenceDesc' '@ConfidenceDesc '.
    ) in the temp


    Is a very good job.


    What I try to achieve is to insert the data from the XML for this relational Table (VALU_RSLT) and also to increment the Sequence (VALU_RSLT_ID) and others
    check the fields in the table. (CRT_BY_USR_ID, CRT_TMST, LAST_UPD_BY_USR_ID, LAST_UPD_TMST).

    How can I do this?


    I tried something like this

    INSERT into VALU_RSLT (VALU_RSLT_ID, FRD_RQST_INFO_ID, CERT_NBR, VALUATIONMETHODTYPE, VALUATIONMODEL, EARNED,
    VALUATIONLOW, VALUATIONHIGH, CONFIDENCESCORE, CONFIDENCEDESC, CRT_BY_USR_ID, CRT_TMST, LAST_UPD_BY_USR_ID, LAST_UPD_TMST)
    VALUES (VALU_RSLT_ID_SEQ1.nextval (), select tx. FRD_RQST_INFO_ID, CERT_NBR, temp.*
    OF FRD_XML_TEST1 tx.
    XMLTABLE ('/ DRIVEResponse/loan/assessments/ValuationResult ')
    TX OF PASSAGE. RSP_XML
    PATH of COLUMNS 'ValuationMethodType' VARCHAR2 (4000) "@ValuationMethodType."
    Path of 'ValuationModel' VARCHAR2 (4000) "@ValuationModel."
    "Assessment" PATH of NUMBER (20.5) "@Valuation."
    Path of "ValuationLow" NUMBER (20.5) "@ValuationLow."
    Path of "ValuationHigh" NUMBER (20.5) "@ValuationHigh."
    PATH of NUMBER "ConfidenceScore" "@ConfidenceScore"
    PATH of VARCHAR2 (255) 'ConfidenceDesc' '@ConfidenceDesc '.
    (), Temp, NULL, NULL, NULL, NULL);



    gave me the following error message

    Error in the command line: 3 column: 35
    Error report:
    SQL error: ORA-00936: lack of expression
    00936 00000 - "missing expression.
    * Cause:
    * Action:


    How can I do this insert work?

    You mix styles of syntax INSERT. VALUES is for a single line. You want something like

    INSERT into VALU_RSLT(VALU_RSLT_ID, FRD_RQST_INFO_ID, CERT_NBR, VALUATIONMETHODTYPE, VALUATIONMODEL, VALU,
    VALUATIONLOW, VALUATIONHIGH, CONFIDENCESCORE, CONFIDENCEDESC, CRT_BY_USR_ID, CRT_TMST, LAST_UPD_BY_USR_ID, LAST_UPD_TMST)
    select VALU_RSLT_ID_SEQ1.nextval(),
           tx.FRD_RQST_INFO_ID,CERT_NBR,temp.*,
           NULL,NULL,NULL,NULL
    FROM FRD_XML_TEST1 tx,
         XMLTABLE('/DRIVEResponse/Loan/Valuations/ValuationResult'
                  PASSING TX.RSP_XML
                  COLUMNS
                  "ValuationMethodType" VARCHAR2(4000) PATH '@ValuationMethodType',
                  "ValuationModel" VARCHAR2(4000) PATH '@ValuationModel',
                  "Valuation" NUMBER(20,5) PATH '@Valuation',
                  "ValuationLow" NUMBER(20,5) PATH '@ValuationLow',
                  "ValuationHigh" NUMBER(20,5) PATH '@ValuationHigh',
                  "ConfidenceScore" NUMBER PATH '@ConfidenceScore',
                  "ConfidenceDesc" VARCHAR2(255) PATH '@ConfidenceDesc');
    
  • Procedure with the DML statements that insert values from 1 to 100 in only one table and it is matching word equivalent in the other

    Can someone help me create a procedure with the DML statements that insert values from 1 to 100 in a table "abc" and the procedure must connect the numbers into words in another table "xyz" without doing a commit explicitly. "."

    Currently on trial...

    SQL > create table abc (num number);

    Table created.

    SQL > create table xyz (num varchar2 (100));

    Table created.

    SQL > ed
    A written file afiedt.buf

    1. insert all
    2 values of 1 = 1 then in abc (num) (l)
    3 when the values of 1 = 1 then in xyz (num) (to_char (to_date(l,'j'), 'jsp'))
    4 * Select the level from dual connect by level<=>
    SQL > /.

    200 rows created.

    And the result...

    SQL > select * from abc;

    NUM
    ----------
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    ..
    ..
    ..
    98
    99
    100

    100 selected lines.

    SQL > select * from xyz;

    NUM
    ----------------------------------------------------------------------------------------------------
    one
    two
    three
    four
    five
    six
    seven
    eight
    nine
    ten
    Eleven
    twelve
    ..
    ..
    ..
    98
    Nineteen eighty
    Cent

    100 selected lines.

  • Error when I try to insert records ORA-01008:

    Hello

    Im trying to insert records from parameters with an immediate execution but idk what to try more so I ask for help, that's my statement inside the procedure:

    vSQL: = Q'{INSERT IN TESTQ

    (status, info, dt_entg, cd_prod, cd_fisc, cd_fabr, nm_fabr, cd_bar, cd_dist, nm_dist, cd_dist_ext, nm_dist_ext, nm_prod, cor, Manu, mater, prc_htec, peso, prc_tbl, st, custo_st, prc_cust, desc_prd, desc_esp, real, ideal, lc_v_p, estq)

    VALUES

    (: V_STATUS,: V_INFO,: V_DT_ENTG,: V_CD_PROD,: V_CD_FISC,: V_CD_FABR,: V_NM_FABR,: V_CD_BAR,: V_CD_DIST,: V_NM_DIST,: V_CD_DIST_EXT,: V_NM_DIST_EXT,: V_NM_PROD,: V_COR,: V_TAMN,: V_MATER,: V_PRC_HTEC,: V_PESO,: V_PRC_TBL,: V_ST,: V_CUSTO_ST,: V_PRC_CUST) (: V_DESC_PRD,: V_DESC_ESP,: V_REAL,: V_IDEAL,: V_LC_V_P,: V_ESTQ)}';

    EXECUTE IMMEDIATE vSQL;

    and returns this error ORA-01008:

    I already check the columns with the settings 29 even ive tried to use simple variable as 'V_CD_FABR' tried to use like this ": V_CD_FABR" im receives the value of a parameter in a procedure and by putting this value into a variable after attempts to insert the value of the variable.

    Thank you all!

    You must use the keyword

    execute immediate vsql using v_statu, v_info;
    

    Link: IMMEDIATE statement EXECUTION

  • Insert the data in materialized views at the Table

    Hello

    We have a problem in which some incorrect data has been loaded for tables.

    Users now are pointing to the materialized views and data access using synonyms.

    Is it possible to insert data from a view, materialized at the tables?

    Kind regards

    VN

    Hello

    As sb92075 has said, we can insert in the table of the materialized view.

    Test below data:

    SQL > select * from t1;

    CITY OF AMOUNT ID COMMENTS

    ---------- -------------------- ---------- --------------------

    1 XXX 28 Chicago

    2 AAA LAS 25

    3 YYY 25 NY

    4 35 Texas XXX

    5 XXX 55 Arlington

    6 56 Chicago YYY

    7 XXX 66 NY

    7 selected lines.

    SQL > create mv_t1 view materialized in select * from t1;

    Materialized view created.

    SQL > select * from mv_t1;

    CITY OF AMOUNT ID COMMENTS

    ---------- -------------------- ---------- --------------------

    1 XXX 28 Chicago

    2 AAA LAS 25

    3 YYY 25 NY

    4 35 Texas XXX

    5 XXX 55 Arlington

    6 56 Chicago YYY

    7 XXX 66 NY

    7 selected lines.

    SQL > insert into t1 values(8,'BBB',22,'NY');

    1 line of creation.

    SQL > select * from mv_t1;

    CITY OF AMOUNT ID COMMENTS

    ---------- -------------------- ---------- --------------------

    1 XXX 28 Chicago

    2 AAA LAS 25

    3 YYY 25 NY

    4 35 Texas XXX

    5 XXX 55 Arlington

    6 56 Chicago YYY

    7 XXX 66 NY

    7 selected lines.

    SQL > select * from t1;

    CITY OF AMOUNT ID COMMENTS

    ---------- -------------------- ---------- --------------------

    1 XXX 28 Chicago

    2 AAA LAS 25

    3 YYY 25 NY

    4 35 Texas XXX

    5 XXX 55 Arlington

    6 56 Chicago YYY

    7 XXX 66 NY

    NEW YORK 8 22 BBB

    8 selected lines.

    SQL > commit;

    Validation complete.

    SQL > select * from mv_t1;

    CITY OF AMOUNT ID COMMENTS

    ---------- -------------------- ---------- --------------------

    1 XXX 28 Chicago

    2 AAA LAS 25

    3 YYY 25 NY

    4 35 Texas XXX

    5 XXX 55 Arlington

    6 56 Chicago YYY

    7 XXX 66 NY

    7 selected lines.

    SQL > delete from t1;

    8 deleted rows.

    SQL > select * from mv_t1;

    CITY OF AMOUNT ID COMMENTS

    ---------- -------------------- ---------- --------------------

    1 XXX 28 Chicago

    2 AAA LAS 25

    3 YYY 25 NY

    4 35 Texas XXX

    5 XXX 55 Arlington

    6 56 Chicago YYY

    7 XXX 66 NY

    7 selected lines.

    SQL > insert into t1 select * from mv_t1;

    7 lines were created.

    SQL > select * from t1;

    CITY OF AMOUNT ID COMMENTS

    ---------- -------------------- ---------- --------------------

    1 XXX 28 Chicago

    2 AAA LAS 25

    3 YYY 25 NY

    4 35 Texas XXX

    5 XXX 55 Arlington

    6 56 Chicago YYY

    7 XXX 66 NY

    7 selected lines.

    SQL >

Maybe you are looking for