PL/SQL LOOP or INSERT MONTH

I have a table below that has START_DATE and END_DATE for each record but not individual row for each month. So, a record can have 6 months payment with start date - '20100101' to end_date 20100630.
I need to find out payment for each month for recon.
I want to add that month field and keep everything else exactly the same as what's in table.
For above example it should add
01-JAN-2010 ................................................ <--- everything else same
01-FEB-2010 ........................
|
|
|
01-JUN-2010 ..........................................................
The helpful fields are START_DATE, END_DATE, NO_OF_MONTHS1 and NO_MONTHS_2. Somethimes, NO_MONTH1 and NO_MONTHS_2 differ. Normally whe they differ, one is 00.
--oracle 10g
--DROP TABLE PAYMENTS;
CREATE TABLE PAYMENTS
CMPNY VARCHAR2,
S_ID VARCHAR2,
NO_MONTHS_1 VARCHAR2,
NO_MONTHS_2 VARCHAR2,
ADJ_CODE VARCHAR2,
START_DATE VARCHAR2,
END_DATE VARCHAR2,
AMOUNT NUMBER
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S001','06','06','20','20100101','20100630','30');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S001','04','04','12','20090101','20090430','50');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C002','S001','02','02','20','20090801','20100930','100');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C002','S002','02','02','20','20090801','20100930','100');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S002','01','01','12','20090101','20090131','50');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S001','00','04','18','20090101','20090430','50');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S003','00','02','12','20090501','20090731','50');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S004','01','01','12','20090101','20090131','50');
commit;
RESULTS should be something like
CREATE TABLE PAYMENTS1
ELIGIBLE_MONTH DATE,
CMPNY VARCHAR2,
S_ID VARCHAR2,
NO_MONTHS_1 VARCHAR2,
NO_MONTHS_2 VARCHAR2,
ADJ_CODE VARCHAR2,
START_DATE VARCHAR2,
END_DATE VARCHAR2,
AMOUNT NUMBER
commit;
--BELOW IS AN EXAMPLE OF HOW THE SOLUTION SHOULD COMEOUT FOR FIRST 3 RECORD IN ABOVE TABLE
---for first record in above table, it should create 6 rows, and apply eligible_month to it
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-JAN-2010','C001','S001','06','06','20','20100101','20100630','30');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-FEB-2010','C001','S001','06','06','20','20100101','20100630','30');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-MAR-2010','C001','S001','06','06','20','20100101','20100630','30');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-APR-2010','C001','S001','06','06','20','20100101','20100630','30');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-MAY-2010','C001','S001','06','06','20','20100101','20100630','30');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-JUN-2010','C001','S001','06','06','20','20100101','20100630','30');
---IT SHOULD CREATE 4 ROWS
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-JAN-2009','C001','S001','04','04','12','20090101','20090430','50');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-FEB-2009','C001','S001','04','04','12','20090101','20090430','50');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-MAR-2009','C001','S001','04','04','12','20090101','20090430','50');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-APR-2009','C001','S001','04','04','12','20090101','20090430','50');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-AUG-2010','C002','S001','02','02','20','20100801','20100930','100');
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-SEP-2010','C002','S001','02','02','20','20100801','20100930','100');

Hi,
788729 wrote:
I have a table below that has START_DATE and END_DATE for each record but not individual row for each month. So, a record can have 6 months payment with start date - '20100101' to end_date 20100630.
I need to find out payment for each month for recon.
I want to add that month field and keep everything else exactly the same as what's in table.
For above example it should add
01-JAN-2010 ................................................ <--- everything else same
01-FEB-2010 ........................
|
|
|
01-JUN-2010 ..........................................................This seems to be an easier variation of your last question:
Re: PL/SQL LOOP MONTH
You should have some idea about how to do it by now. Post your best attempt.
The helpful fields are START_DATE, END_DATE, NO_OF_MONTHS1 and NO_MONTHS_2. Somethimes, NO_MONTH1 and NO_MONTHS_2 differ. Normally whe they differ, one is 00.What is the role each of those columns plays in this problem? Which one(s) tell how many rows need to be inserted? Why are the others helpful?
>
>
--oracle 10g
--DROP TABLE PAYMENTS;
CREATE TABLE PAYMENTS
CMPNY VARCHAR2,
S_ID VARCHAR2,
NO_MONTHS_1 VARCHAR2,
NO_MONTHS_2 VARCHAR2,
ADJ_CODE VARCHAR2,
START_DATE VARCHAR2,
END_DATE VARCHAR2,
AMOUNT NUMBER
);Don't use VARCHAR2 columns to store dates; alwyas use DATE (or TIMESTAMP) columns.
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S001','06','06','20','20100101','20100630','30');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S001','04','04','12','20090101','20090430','50');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C002','S001','02','02','20','20090801','20100930','100');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C002','S002','02','02','20','20090801','20100930','100');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S002','01','01','12','20090101','20090131','50');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S001','00','04','18','20090101','20090430','50');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S003','00','02','12','20090501','20090731','50');
INSERT INTO PAYMENTS (CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('C001','S004','01','01','12','20090101','20090131','50');
commit;Thanks for posting the CREATE TABLE and INSERT statemnets.
RESULTS should be something like
CREATE TABLE PAYMENTS1
ELIGIBLE_MONTH DATE,
CMPNY VARCHAR2,
S_ID VARCHAR2,
NO_MONTHS_1 VARCHAR2,
NO_MONTHS_2 VARCHAR2,
ADJ_CODE VARCHAR2,
START_DATE VARCHAR2,
END_DATE VARCHAR2,
AMOUNT NUMBER
commit;
--BELOW IS AN EXAMPLE OF HOW THE SOLUTION SHOULD COMEOUT FOR FIRST 3 RECORD IN ABOVE TABLEWhy only 3? Post the results that you want from the sample data. If 3 rows is enough to show what the problem is, why did you post 8 rows above? If 8 rows give a better picture of the problem, why not show the results from 8 rows?
>
---for first record in above table, it should create 6 rows, and apply eligible_month to it
INSERT INTO PAYMENTS (ELIGIBLE_MONTH, CMPNY,S_ID,NO_MONTHS_1,NO_MONTHS_2, START_DATE, END_DATE,AMOUNT) VALUES ('01-JAN-2010','C001','S001','06','06','20','20100101','20100630','30');There are 8 columns listed before the VALUES keyword, but 9 values given after it.
There is no eligible_month column in paymemts. Did you mean payments<b>1</b>?
Do you want a query that produces these INSERT statements as strings, or do you actually want to populate payments1 (or payments)?
If you just want to populate a table, show the contents of the populated table in a form people can read and understand, for example:
ELIGIBLE_MONTH  CMPNY  S_ID  NO_MONTHS_1  NO_MONTHS_2  START_DATE  END_DATE  AMOUNT
01-JAN-2010     C001   S001  06            06            20100101        20100630  30
01-FEB-2010     C001   S001  06            06            20100101        20100630  30
...When you post formatted text on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • PL SQL with multiple inserts, how to continue after exception is raised

    Hi,
    I have a simple PL SQL function with various inserts. ex:
    Insert Into "DI01"."DUA_DIM_UNITE_ADMIN" (Ide_Unite_Admin_Sk, Num_Unite_Admin, Des_Unite_Admin) Values ('-1', '00000000', 'Défaut');
    INSERT INTO "DI01"."DUA_DIM_UNITE_ADMIN" (IDE_UNITE_ADMIN_SK, NUM_UNITE_ADMIN, DES_UNITE_ADMIN) VALUES ('-2', 'S. O.', 'Sans Objet');
    Insert Into "DI01"."DCU_DIM_CATGR_UNSPS" (Ide_Catgr_Sk, Num_Code, Des_Code, Num_Catgr, Des_C.........
    I want to be able to run the function multiple times, and have all the inserts executed everytime, even if I get a ORA-00001 unique constraint (string.string) violated error in on of the inserts. That means that if I get an error in the first insert, I want the function to continue running and executing the consecutive inserts.
    I though of including each insert in a different block, like:
    BEGIN
    Insert......
    When Exception then null;
    END;
    BEGIN
    Insert......
    When Exception then null;
    END;
    But I have at least 50 inserts, so the final code becomes huge.
    Another solution is to use merge inseat of insert, but the code seems too complex for such a simple task.
    Is there any other solution for this that I am not seeing?
    Thank you for your time,
    Joao Moreira

    You can use DML error logging approach or FORALL SAVE EXCEPTIONS.
    Since you didn't mention the version I assume you are using 11g.
    Below is the sample code for DML error logging mechanism
    SQL> select * from v$version;
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production   
    PL/SQL Release 11.2.0.3.0 - Production                                         
    CORE 11.2.0.3.0 Production                                                     
    TNS for Linux: Version 11.2.0.3.0 - Production                                 
    NLSRTL Version 11.2.0.3.0 - Production                                        
    SQL> DROP TABLE tableA;
    Table dropped.
    SQL> DROP TABLE Err$_tableA;
    Table dropped.
    SQL>
    SQL> CREATE TABLE tableA
      2  (
      3     col1   NUMBER PRIMARY KEY,
      4     col2   NUMBER,
      5     col3   VARCHAR2 (10)
      6  );
    Table created.
    SQL>
    SQL> -- Create error log table
    SQL>
    SQL> BEGIN
      2     DBMS_ERRLOG.create_error_log (dml_table_name => 'TABLEA');
      3  END;
      4  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> BEGIN
      2     FOR i IN (SELECT 1 AS col1 FROM DUAL
      3               UNION ALL
      4               SELECT 1 FROM DUAL)
      5     LOOP
      6        INSERT INTO tableA (col1)
      7             VALUES (i.col1)
      8                LOG ERRORS INTO Err$_tableA REJECT LIMIT UNLIMITED;
      9     END LOOP;
    10 
    11     COMMIT;
    12  END;
    13  /
    PL/SQL procedure successfully completed.
    SQL> column column_name format a30
    SQL> set linesize 300
    SQL> select * from tableA;
    SQL> select * from err$_tablea;
    Thanks,
    GPU

  • PL/SQL Looping a table and copying some values to another one...

    hi all!!!
    i'm totally new to pl/sql, and i need to create an interaction to do the following..
    my scenario is:
    i have a table called "references" that contains 2 columns (new_id, old_id).
    then i have another table called "ref" which also contains 2 columns (old_id, other_id).
    ok the point is this:
    in the table references i have stored the references between 2 products (the old one and the new one) by storing their ids.
    now what i have to do by knowing this, is to insert in the table "ref" a new entry for every old_id that is already stored there, but changing it with the new_id that i can get from the other table (references).
    let's see an example:
    table references:
    new_id - old_id
    11 - 3
    12 - 7
    13 - 5
    table ref:
    old_id - other_id
    3 - tu7r
    7 - asduih
    7 - anotherone
    7 - 44444
    5 - 6754f
    so the result that i want is that the new ids (11,12,13) has to be copied to the table "ref" with the same "other_id" as their correspondants in "references" table.. the result would be:
    table ref:
    old_id - other_id
    3 - tu7r
    7 - asduih
    7 - anotherone
    7 - 44444
    5 - 6754f
    11 - tu7r
    12 - asduih
    12 - anotherone
    12 - 44444
    13 - 6754f
    i don't know how to build up a loop or something to reach this aim!!
    thanks for your time guys!!!
    Edited by: ElMazzaX on Nov 17, 2011 3:15 PM

    You do not need pl/sql to do this.
    If I understand your datamodel correctly, this join will get you those records you need to insert:
    select
    references.new_id, ref.other_id
    from references
    join ref
       on ref.old_id = references.old_id;Try that select - it it works, then you can simply do:
    insert into ref (old_id, other_id)
    select
    references.new_id, ref.other_id
    from references
    join ref
       on ref.old_id = references.old_id;SQL is quite enough - no PL/SQL loop necessary ;-)

  • Can we assign value to a variable in PL/SQL Loop

    Hi
    Can we assign value to a variable in PL/SQL Loops?
    DECLARE
    V_Num NUMBER;
    BEGIN
    LOOP
    V_Num := 10;
    DBMS_OUTPUT.put_line(V_num);
    V_Num := V_Num - 1;
    EXIT WHEN V_Num = 0;
    END LOOP;
    END;
    In the above program, Can we assign V_num with a value 10????????
    Thanks & Regards,
    Hari Babu
    Edited by: 1004977 on Jun 5, 2013 2:40 AM

    Hi,
    1004977 wrote:
    Hi
    Can we assign value to a variable in PL/SQL Loops?
    DECLARE
    V_Num NUMBER;
    BEGIN
    LOOP
    V_Num := 10;
    DBMS_OUTPUT.put_line(V_num);
    V_Num := V_Num - 1;
    EXIT WHEN V_Num = 0;
    END LOOP;
    END;
    In the above program, Can we assign V_num with a value 10????????Yes; the example you posted does that.
    When the loop starts, the value 10 is assigned to v_num. You should see that value displayed by the put_line statement.
    After that, v_num is set to 10 - 1 = 9.
    Next, the EXIT condition is evaluated. At this point, v_num is 9, not 0, so the loop runs again. V_num is set to 10 again, and the loop continues forever (or, in some versions, until the dbms_output buffer is filled and an error occurs.)

  • Custom PL/SQL API that inserts the data into a custom interface table.

    We are developing a custom Web ADI integrator for importing suppliers into Oracle.
    The Web ADI interface is a custom PL/SQL API that inserts the data into a custom interface table. We have defined the content, uploader and an importer. The importer is again a custom PL/SQL API that will process the records inserted into the custom table and updates the STATUS column of the custom interface table. We want to show the status column back on the spreadsheet.
    Defined the 'Document Row' import rule and added the rows that would identify the unique record.
    Errored row import rule, we are using a SELECT * from custom_table where status<>'Success' and vendor_name=$param$.vendor_name
    The source of this parameter is import.vendor_name
    We have also defined an Error lookup.
    After the above setup is completed, we invoke the create document and click on Oracle->Upload.
    The records are getting imported, but the importer program is failing with An error has occurred while running an API import. The ERRORED_ROWS step 20003:ER_500141, parameter number 1 must contain the value BIND in attribute 1.'

    The same issue.
    Need help.
    Also checked bne.log, no additional information.
    <bne:document xmlns:bne="http://www.oracle.com/bne">
    <bne:message bne:type="DATA" bne:text="BNE_VALID_ROW_COUNT" bne:value="11" />
    <bne:message bne:type="DATA" bne:text="BNE_INVALID_ROW_COUNT" bne:value="0" />
    <bne:message bne:type="ERROR" bne:text="An error has occurred while running an API import"
    bne:cause="The ERRORED_ROWS step 20003:ER_500165, parameter number 1 must contain the value BIND in attribute 1."
    bne:action="" bne:source="BneAPIImporter" >
    <bne:context bne:collection="collection_1" />
    </bne:message><bne:message bne:type="STATUS"
    bne:text="No rows uploaded" bne:value="" >
    <bne:context bne:collection="collection_1" /></bne:message>
    <bne:message bne:type="STATUS" bne:text="0 rows were invalid" bne:value="" >
    <bne:context bne:collection="collection_1" /></bne:message></bne:document>

  • Insert Month and Year

    Table ( In-focus)
    CREATE TABLE "LIBRARY"."INFOCUS_LOG"
    ("LOGDATETIME" DATE,
    "COUNTER" NUMBER(6,0)
    Procedure
    create or replace PROCEDURE IN_FOCUS_PAGE
    (ldt INFOCUS_LOG.logdatetime%TYPE,
    COT INFOCUS_LOG.counter%TYPE)
    IS
    BEGIN
    INSERT
    INTO INFOCUS_LOG
    VALUES(ldt, COT);
    DBMS_OUTPUT.PUT_LINE('RECORD IS ADDED......!');
    COMMIT;
    END IN_FOCUS_PAGE;
    What do I need to do if I want to insert month and year only for this particular table.
    Result Example:
    JAN-2007
    FEB-2007
    MAR-2007
    Message was edited by:
    user579538

    A DATE is always going to have a full day and time component, so you cannot store just the month and year. You can, of course, choose to display just the month and year, i.e.
    SELECT TO_CHAR( date_column, 'MON-YYYY' )
      FROM some_tableor to extract the month and year separately
    SELECT EXTRACT( year from date_column ) yr,
           EXTRACT( month from date_column ) dt
      FROM some_tableJustin

  • SQL Loader and Insert Into Performance Difference

    Hello All,
    Im in a situation to measure performance difference between SQL Loader and Insert into. Say there 10000 records in a flat file and I want to load it into a staging table.
    I know that if I use PL/SQL UTL_FILE to do this job performance will degrade(dont ask me why im going for UTL_FILE instead of SQL Loader). But I dont know how much. Can anybody tell me the performance difference in % (like 20% will decrease) in case of 10000 records.
    Thanks,
    Kannan.

    Kannan B wrote:
    Do not confuse the topic, as I told im not going to use External tables. This post is to speak the performance difference between SQL Loader and Simple Insert Statement.I don't think people are confusing the topic.
    External tables are a superior means of reading a file as it doesn't require any command line calls or external control files to be set up. All that is needed is a single external table definition created in a similar way to creating any other table (just with the additional external table information obviously). It also eliminates the need to have a 'staging' table on the database to load the data into as the data can just be queried as needed directly from the file, and if the file changes, so does the data seen through the external table automatically without the need to re-run any SQL*Loader process again.
    Who told you not to use External Tables? Do they know what they are talking about? Can they give a valid reason why external tables are not to be used?
    IMO, if you're considering SQL*Loader, you should be considering External tables as a better alternative.

  • Splitting a list (loop and insert)

    I have a text file with about 65000 records to be looped and
    inserted into a
    database. I am using cfhttp to read the list and turn it into
    a query. I am
    then using that query to loop and insert the records into a
    database.
    However, its too large and the server is timing out. Is there
    a break the
    list into 2 pieces and do it in serial?
    I am using:
    <cffunction name="getResidential" access="private"
    returntype="void"
    output="false" hint="">
    <cfargument name="ResFile" type="string"
    required="yes">
    <cfhttp timeout="6600"
    url="
    http://www.mywebsite.com/assets/property/#ResFile#"
    method="GET"
    name="Property" delimiter="|" textqualifier=""
    firstrowasheaders="yes" />
    <cfloop query="Property">
    <cfquery name="loopProperty" datasource="bpopros">
    INSERT STATEMENT HERE
    </cfquery>
    </cfloop>
    </cffunction>
    Is it possible to do something like:
    Function 1
    <cfloop from="1" to="40000" index="i">
    </cfloop>
    Function 2
    <cfloop from="40001" to="#Query.RecordCount#"
    index="i">
    </cfloop>
    Any ideas? Thanks
    Wally Kolcz
    MyNextPet.org
    Founder / Developer
    586.871.4126

    I like your second solution, but wouldn't I need access to
    the actual web
    server? I need to do this on hosting. I am downloading the
    files from a Real
    Comp and then looping the data into my client's database for
    searching. I
    wanted to just use the files as a flat database and just
    query or query off
    of it, but there is a new file everyday. Only one update
    (Sunday) is the
    master list of 45-60k records. All the rest (Mon-Sat) are
    just small
    updates.
    "Dan Bracuk" <[email protected]> wrote in
    message
    news:fdrgde$6qu$[email protected]..
    > It's possible, but it's a better idea to look for ways
    to do it without
    > cold
    > fusion.
    >
    > Food for thought, I have a requirement to move data from
    one db to
    > another. I
    > use Cold Fusion to query the first db, output to text,
    and ftp the text
    > files
    > to another server. I also have a scheduled job that
    looks for these text
    > files
    > and loads them into db2.
    >

  • Using SQL Loader to insert data based on conditionally statements

    I would like to use sql loader to insert records from a single text file into an Oracle database table. Sounds easy but the problem is that I need to check the existence of data in another table (Table A) before data can be loaded into Table B.
    Table A has two columns: dept_no (primary key value) and dept_name (char)
    Table B has five columns: emp_no (primary key value), dept_no (foreign key value to Table A), employee (char), job_title (char) and salary (number)
    Text File looks like this:
    Finance Jones President 10000
    HR Smith Admin 2000
    HelpDesk Jenkins Technician 3000
    Problem:
    1. I need sql loader to insert records into Table B by first checking if the first field in the file is in Table A.
    2. If value exists get it's dept_no value.
    3. If value doesn't exist discard record ( I might want to have sql loader insert a new record for this into Table A)
    4. Using value from #2, insert the value in Table B for dept_no column.
    5. Also assign a sequence value for the emp_no value in Table B.
    Any guidance is greatly appreciated.
    Thanks,

    Hello,
    I am not sure this is possible with SQL loader. I would rather use an external table based on your file.
    Then, I would use SQL to load your data into your table, based on your conditions.
    Your request is not very complicated, writing the SQL to do that will be really more simple than trying to do it with SQL loader.
    Hope it will help.
    Regards,
    Sylvie

  • |Error SQL: ORA-14400: inserted partition key does not map to any partition

    I have an installation of ECC6 with BI7 in which consolidated through SEM-BCS OBCS_C10 with the cube, which I have version 100 for fiscal data, 101 data for IFRS and IFRS Copying a 301 version.
    The client will ask me the empty version of the 301 in the cube OBCS_C10.
    Before switching to empty the cube "Target Real-Time Data Can Be Loaded With Data; Planning Not Allowed."
    To empty the cube using transaction RSA1 / manage / contents / Delete Selection.
    However, the data is not erased and revise the job gives me the error:
    Resumen log job para job BI_INDXD51A1NTCIYWU06OKZZESN1R94 / 07520600
    Log job
    Hora
    Txt.mje.no codificado
    04.02.2009
    07:52:06
    El job ha sido lanzado.
    04.02.2009
    07:52:06
    Paso 001 iniciado (programa RSINDEX1, variante &0000000000108, usuario ACHUY)
    04.02.2009
    07:52:10
    SQL: 04.02.2009 07:52:10 ACHUY
    04.02.2009
    07:52:10
    DELETE FROM DDSTORAGE WHERE DBSYSABBR = 'ORA'
    04.02.2009
    07:52:10
    AND INDEXNAME = ' ' AND TABNAME =
    04.02.2009
    07:52:10
    '/BI0/D0BCS_C101
    04.02.2009
    07:52:10
    SQL-END: 04.02.2009 07:52:10 00:00:00
    04.02.2009
    07:52:10
    SQL: 04.02.2009 07:52:10 ACHUY
    04.02.2009
    07:52:10
    DELETE FROM DDSTORAGE WHERE DBSYSABBR = 'ORA'
    04.02.2009
    07:52:10
    AND INDEXNAME = ' ' AND TABNAME =
    04.02.2009
    07:52:10
    '/BI0/D0BCS_C101
    04.02.2009
    07:52:10
    SQL-END: 04.02.2009 07:52:10 00:00:00
    04.02.2009
    07:52:10
    SQL: 04.02.2009 07:52:10 ACHUY
    04.02.2009
    07:52:10
    CREATE TABLE "/BI0/0100000076" PCTFREE 00
    04.02.2009
    07:52:10
    PCTUSED 00 INITRANS 001 TABLESPACE PSAPSR3
    04.02.2009
    07:52:10
    STORAGE (INITIAL     0000000016 K NEXT
    04.02.2009
    07:52:10
    0000000016 K MINEXTENTS  0000000001 MAXEXTENTS
    04.02.2009
    07:52:10
    UNLIMITED PCTINCREASE 0000 FREELISTS   001
    04.02.2009
    07:52:10
    FREELIST GROUPS 01) AS SELECT DISTINCT DIMID FROM
    04.02.2009
    07:52:10
    "/BI0/D0BCS_C101" "DIM" , "/BI0/SCS_VERSION"
    04.02.2009
    07:52:10
    "MD1" WHERE "DIM"."SID_0CS_VERSION" = "MD1"."SID"
    04.02.2009
    07:52:10
    AND ( "MD1"."CS_VERSION" BETWEEN '301' AND '301'
    04.02.2009
    07:52:10
    SQL-END: 04.02.2009 07:52:10 00:00:00
    04.02.2009
    07:52:25
    SQL: 04.02.2009 07:52:25 ACHUY
    04.02.2009
    07:52:25
    DELETE FROM DDSTORAGE WHERE DBSYSABBR = 'ORA'
    04.02.2009
    07:52:25
    AND INDEXNAME = ' ' AND TABNAME = '/BI0/F0BCS_C10
    04.02.2009
    07:52:25
    SQL-END: 04.02.2009 07:52:25 00:00:00
    04.02.2009
    07:52:25
    SQL: 04.02.2009 07:52:25 ACHUY
    04.02.2009
    07:52:25
    DELETE FROM DDSTORAGE WHERE DBSYSABBR = 'ORA'
    04.02.2009
    07:52:25
    AND INDEXNAME = ' ' AND TABNAME = '/BI0/F0BCS_C10
    04.02.2009
    07:52:25
    SQL-END: 04.02.2009 07:52:25 00:00:00
    04.02.2009
    07:52:25
    SQL: 04.02.2009 07:52:25 ACHUY
    04.02.2009
    07:52:25
    CREATE TABLE "/BI0/0100000030" PCTFREE 10
    04.02.2009
    07:52:25
    PCTUSED 00 INITRANS 001 TABLESPACE PSAPSR3
    04.02.2009
    07:52:25
    STORAGE (INITIAL     0000000016 K NEXT
    04.02.2009
    07:52:25
    0000000000 K MINEXTENTS  0000000001 MAXEXTENTS
    04.02.2009
    07:52:25
    2147483645 PCTINCREASE 0000 FREELISTS   001
    04.02.2009
    07:52:25
    FREELIST GROUPS 01) PARTITION BY RANGE
    04.02.2009
    07:52:25
    ("KEY_0BCS_C10P") ( PARTITION "/BI0/F0BCS_C100"
    04.02.2009
    07:52:25
    VALUES LESS THAN (0) TABLESPACE "PSAPSR3",
    04.02.2009
    07:52:25
    PARTITION "/BI0/F0BCS_C100000000019" VALUES LESS
    04.02.2009
    07:52:25
    THAN (0000000019) TABLESPACE "PSAPSR3", PARTITION
                  |
    04.02.2009
    07:52:25
    "/BI0/F0BCS_C100000000276" VALUES LESS THAN
    04.02.2009
    07:52:25
    (0000000276) TABLESPACE "PSAPSR3", PARTITION
    04.02.2009
    07:52:25
    "/BI0/F0BCS_C100000000277" VALUES LESS THAN
    04.02.2009
    07:52:25
    (0000000277) TABLESPACE "PSAPSR3") AS SELECT *
    04.02.2009
    07:52:25
    FROM "/BI0/F0BCS_C10" WHERE "KEY_0BCS_C101" NOT
    04.02.2009
    07:52:25
    IN ( SELECT "DIMID" FROM "/BI0/0100000076"
    04.02.2009
    07:52:29
    SQL-END: 04.02.2009 07:52:29 00:00:04
    04.02.2009
    07:52:29
    Error SQL: ORA-14400: inserted partition key does not map to any partition
    04.02.2009
    07:52:29
    Error de sistema: CREATE_TABLE_AS_SELECT/RSDU_EXEC_SQL /BI0/0100000030 14400
    04.02.2009
    07:52:29
    El job ha sido cancelado tras excepción de sistema ERROR_MESSAGE.
    Someone has an idea how to fix this?

    This is the SQL of the insert
    The partition condition of the table is the column ("KEY_0BCS_C10P")
    SELECT * FROM "/BI0/F0BCS_C10" WHERE "KEY_0BCS_C101" NOT IN ( SELECT "DIMID" FROM "/BI0/0100000076" )
    This is the info of the /BIO/0100000076 TABLE
    SQL> SELECT "DIMID" FROM sapsr3."/BI0/0100000076";
         DIMID
             6
    SQL>
    And this are the rows that I think are not included in the partitions of the table
      1  SELECT DISTINCT KEY_0BCS_C10P, KEY_0BCS_C101 FROM SAPSR3."/BI0/F0BCS_C10"
      2  WHERE KEY_0BCS_C10P > 277
      3* AND "KEY_0BCS_C101" NOT IN ( SELECT "DIMID" FROM SAPSR3."/BI0/0100000076" )
    SQL> /
    KEY_0BCS_C10P KEY_0BCS_C101
              284             4
              285             4
              293             3
              292             4
              293             4
              293             5
              285             3
              290             4
              292             5
              283             4
              285             5
    KEY_0BCS_C10P KEY_0BCS_C101
              291             5
              292             3
              291             4
    14 rows selected.
    SQL>

  • TopLink does not generate SQL statements for inserting new objects

    TopLink does not generate SQL statements for inserting new objects. Why?
    Thanks in advance...

    Please see the response in
    Why does not unitofwork.commit write data to the database?
    Regards,
    Chris

  • SSIS - Script Task creates a DTS var and using Foreach loop, Execute SQL needs to INSERT into table from this DTS var.

    I have a script task written in C# that creates an array of strings "arrayFields" after parsing a text file. It saves the array of strings in a DTS variable.
    Each row in array represents a row is comma separated and is a row that must be inserted into a table. For example,
    X and Z are fields in the table
    X1, X2,....Xn
    Z1,Z2,...Zn
    I am using a Foreach Loop  to grab each row and then  Execute SQL Task to take each row from the array and insert each field per row in a table,
    The SQL is something like,
    INSERT dbo.table values(field1, field2,...fieldn) arrayFields?
    What should this this INSERT look like?

    I guess you implemented
    Shredding a Recordset
    Based on what I understood (correct me if I am wrong) you have difficulties mapping the input parameters, if so here is the guide
    http://www.sqlis.com/sqlis/post/The-Execute-SQL-Task.aspx
    In short it might look like
    INSERT dbo.table  (ColumnA, ColumnB,...) VALUES (?,?...)
    The syntax for the T-SQL INSERT is http://technet.microsoft.com/en-us/library/dd776381%28v=sql.105%29.aspx
    Arthur
    MyBlog
    Twitter

  • PL/SQL LOOP MONTH

    One more favor, PLEASe...
    CREATE TABLE USR_FAC
    FACILITY_ID VARCHAR2(16),
    FACILITY_NAME VARCHAR2(30),
    DOCTOR_ID VARCHAR2(16),
    EFFECTIVE_DATE DATE,
    STATUS VARCHAR2(1)
    INSERT INTO usr_fac (FACILITY_ID, FACILITY_NAME,doctor_id, effective_date, STATUS) VALUES ('F1001','UNC_HOSPITAL','D1001', '01-JAN-2009','1');
    INSERT INTO usr_fac (FACILITY_ID, FACILITY_NAME,doctor_id, effective_date, STATUS) VALUES ('F1001','UNC_HOSPITAL','D1001', '01-OCT-2009','0');
    INSERT INTO usr_fac (FACILITY_ID, FACILITY_NAME,doctor_id, effective_date, STATUS) VALUES ('F1002','UNC_HOSPITAL_2','D1001', '01-OCT-2009','1');
    INSERT INTO usr_fac (FACILITY_ID, FACILITY_NAME,doctor_id, effective_date, STATUS) VALUES ('F1003','UNC_HOSPITAL_3','D1002', '01-JAN-2010','1');
    INSERT INTO usr_fac (FACILITY_ID, FACILITY_NAME,doctor_id, effective_date, STATUS) VALUES ('F1003','UNC_HOSPITAL_3','D1003', '01-FEB-2010','1');
    COMMIT;
    Here status: 1 - ACTIVE and 0 - TERMINATED.
    Similarly, I want to have monthly rows when the docotor is active.
    So D1001 should have 1 row each of the month- from 01-jan-2009 to 01-oct-2009 with same facility_id and name.
    When he gets terminated, one row is fine.
    When he becomes active again, it should restart monthly rows up to sysdate.
    THIS WILL BE GREAT HELP.
    THANKS

    Hi,
    788729 wrote:
    People are mess. Alright, I think I know what's going on now.
    One issue I am having not because of our IS dep't but our iffy Config dep't.
    So for few record like 78 to be exact, either the effective date of status = 1 or effective date of status = 0 is not consistent meaning date is not always '01' in 'DD-MON-YYYY' = '01-JAN-2010'. This is a big issue which I have addressed to config but, meanwhile is there a quick fix to this?
    In above case, our first sub-query calculated incorrect MONTHS_NEEDED. For example, IF Config has term doctor on 5/5/2010, then that (DATE - 1) function will keep that provider active in May but infact, he should not be active 4/1/2010.Did you mean "he should not be active <b>5</b>/1/2010"?
    That is, if a Termination row is dated May, 1, then you want to insert an Active row for April 1, don't you? If the Termination date is a little later (that is May 5), wouldn't you still want an Active row for April 1?
    The query I posted yesterday added
    new rows for the 1st of each month up to, but not including, the day of the termination. I think what you're saying now is that you want
    new rows for the 1st of each month up to, but not including, the month of the termination.
    If that's correct, then just change the place where months_needed is calculated. Instead of subtracting 1 day from the termination date, subtract 1 month .
    INSERT INTO  usr_fac
    (       facility_id, facility_name, doctor_id
    ,      effective_date
    ,     status               -- If needed
    WITH     got_months_needed     AS
         SELECT    a.facility_id, a.facility_name, a.doctor_id, a.effective_date
    --     ,       MONTHS_BETWEEN ( TRUNC ( NVL ( MIN (t.effective_date) - 1          -- Old way, August 16
         ,       MONTHS_BETWEEN ( TRUNC ( NVL ( ADD_MONTHS ( MIN (t.effective_date)     -- New way, August 17
                                                        , -1                 -- New way  
                                           )                     -- New way                    
                                                  , SYSDATE
                                 , 'MONTH'
                            , a.effective_date
                            )          AS months_needed
         FROM           usr_fac     a
         LEFT OUTER JOIN  usr_fac     t     ON     a.facility_id       = t.facility_id
                                           AND     a.facility_name       = t.facility_name     -- If needed
                                  AND     a.doctor_id       = t.doctor_id
                                  AND     a.effective_date  < t.effective_date
                                  AND     0            = t.status
         WHERE     a.status          = 1
         GROUP BY  a.facility_id, a.facility_name, a.doctor_id, a.effective_date
    ,     cntr          AS
         SELECT     LEVEL     AS n
         FROM     (
                  SELECT  MAX (months_needed)     AS max_months_needed
                  FROM    got_months_needed
         CONNECT BY     LEVEL <= max_months_needed
    SELECT     m.facility_id, m.facility_name, m.doctor_id
    ,      ADD_MONTHS ( m.effective_date
                 , c.n
                 )          AS effective_date
    ,     '1'                 -- If needed
    FROM     got_months_needed  m
    JOIN     cntr             c     ON     c.n     <= m.months_needed
    ;Of course, you don't need the commented-out line that says "Old way", or the comments that say "New way"; I just added them so that you could see where I changed the statement. Except for the computation of months_needed, the statement is the same. (Actually, I got rid of the ORDER BY clause; that was just a relic of the testing process. It only wastes time in an acutal INSERT.)
    Given your new sample data, the staement above leaves the usr_fac table looking like this:
    FACILITY_ID  FACILITY_NAME   DOCTOR_ID EFFECTIVE_D STATUS
    F1001        UNC_HOSPITAL    D1001     01-Jan-2009 1
    F1001        UNC_HOSPITAL    D1001     01-Feb-2009 1
    F1001        UNC_HOSPITAL    D1001     01-Mar-2009 1
    F1001        UNC_HOSPITAL    D1001     01-Apr-2009 1
    F1001        UNC_HOSPITAL    D1001     01-May-2009 1
    F1001        UNC_HOSPITAL    D1001     01-Jun-2009 1
    F1001        UNC_HOSPITAL    D1001     01-Jul-2009 1
    F1001        UNC_HOSPITAL    D1001     01-Aug-2009 1
    F1001        UNC_HOSPITAL    D1001     01-Sep-2009 1
    F1001        UNC_HOSPITAL    D1001     01-Oct-2009 0
    F1002        UNC_HOSPITAL_2  D1001     01-Oct-2009 1
    F1002        UNC_HOSPITAL_2  D1001     01-Nov-2009 1
    F1002        UNC_HOSPITAL_2  D1001     01-Dec-2009 1
    F1002        UNC_HOSPITAL_2  D1001     01-Jan-2010 1
    F1002        UNC_HOSPITAL_2  D1001     01-Feb-2010 1
    F1002        UNC_HOSPITAL_2  D1001     01-Mar-2010 1
    F1002        UNC_HOSPITAL_2  D1001     01-Apr-2010 1
    F1002        UNC_HOSPITAL_2  D1001     05-May-2010 0
    F1003        UNC_HOSPITAL_3  D1002     01-Jan-2010 1
    F1003        UNC_HOSPITAL_3  D1002     01-Feb-2010 1
    F1003        UNC_HOSPITAL_3  D1002     01-Mar-2010 1
    F1003        UNC_HOSPITAL_3  D1002     01-Apr-2010 1
    F1003        UNC_HOSPITAL_3  D1002     01-May-2010 1
    F1003        UNC_HOSPITAL_3  D1002     01-Jun-2010 1
    F1003        UNC_HOSPITAL_3  D1002     01-Jul-2010 1
    F1003        UNC_HOSPITAL_3  D1002     01-Aug-2010 1
    F1003        UNC_HOSPITAL_3  D1003     01-Feb-2010 1
    F1003        UNC_HOSPITAL_3  D1003     01-Mar-2010 1
    F1003        UNC_HOSPITAL_3  D1003     01-Apr-2010 1
    F1003        UNC_HOSPITAL_3  D1003     01-May-2010 1
    F1003        UNC_HOSPITAL_3  D1003     01-Jun-2010 1
    F1003        UNC_HOSPITAL_3  D1003     01-Jul-2010 1
    F1003        UNC_HOSPITAL_3  D1003     01-Aug-2010 1That seems to be what you want, but "Esse non videre", as the Tar Heels say. Correct me if you need different results.

  • Nested Loops...looping through one month of data at a time year by year

    Hi all,
    I'm trying to create an insert statement that loops through a table that has 10 years of data (2001 to 2010) month by month to minimize impact on server and commits more frequently to avoid filling up the redo logs and rollback tablespaces. The table is large, has about 40 millions records per year. Lets say the structure of the table is the following:
    Customer_ID number(9),
    Order_Item_1 number(6),
    Order_Item_2 number(6),
    Order_Item_3 number(6),
    Order_date date
    The table is in flat format but I want to normalize it so that it looks like the following:
    Customer_ID Order_Seq Order_Item Order_date
    999999999 1 555555 01-jan-2001
    999999999 2 666666 01-jan-2001
    999999999 3 444444 01-jan-2001
    888888888 1 555555 03-jan-2001
    888888888 2 666666 03-jan-2001
    But because I want to loop through month by month....I need to set it up so that it loops through month by month, year by year (Using the Order Date Field) and Order_item by Order_item. Something like:
    so my insert statements would be something like if I hardcoded instead of put the insert statement into a loop:
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,1,Order_item,Order_date where Order_item_1 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='01';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,2,Order_item,Order_date where Order_item_2 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='01';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,3,Order_item,Order_date where Order_item_3 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='01';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,1,Order_item,Order_date where Order_item_1 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='02';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,2,Order_item,Order_date where Order_item_2 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='02';
    insert into orders_normalized
    (Customer_id,Order_seq,Order_item,Order_date) select customer_id,3,Order_item,Order_date where Order_item_3 is not null and to_char(order_date,'yyyy') = '2001' and to_char(order_date,'mm')='03';
    Hope this makes sense.
    Thanks

    Does the sequence of items in an order really matter? In other words, do we really need to preserve that an item was in position 2 versus position 1? I bet that the sequence or position of each item in an order is not meaningful. They were probably numbered 1, 2, and 3 just to make them uniquely named columns so there would be three slots to hold up to 3 items in the denormalized table.
    You only have about 400 million rows to insert, so it could feasibly be done in a single transaction (depending on your database environment).
    You can always do a create table as select (CTAS) to help with undo / redo issues and get better performance. You could run it in parallel, and spit it out to a new table partitioned by month. Single DDL statement running in parallel making your new table--sounds good to me.
    How about something like this:
    CREATE TABLE ORDERS_NORMALIZED
    (CUSTOMER_ID, ORDER_ITEM, ORDER_DATE)
    PARTITION BY RANGE(ORDER_DATE)
    PARTITION p200901 VALUES LESS THAN (TO_DATE('200902','YYYYMM')),
    PARTITION p200902 VALUES LESS THAN (TO_DATE('200903','YYYYMM')),
    PARTITION p201012 VALUES LESS THAN (TO_DATE('201101','YYYYMM'))
    as SELECT CUSTOMER_ID, ORDER_ITEM_1, ORDER_DATE
       FROM OTHER_TABLE
       WHERE ORDER_ITEM_1 IS NOT NULL
       UNION ALL
       SELECT CUSTOMER_ID, ORDER_ITEM_2, ORDER_DATE
       FROM OTHER_TABLE
       WHERE ORDER_ITEM_2 IS NOT NULL
       UNION ALL
       SELECT CUSTOMER_ID, ORDER_ITEM_3, ORDER_DATE
       FROM OTHER_TABLE
       WHERE ORDER_ITEM_3 IS NOT NULL.....................
    Out of curiosity, why not normalize it further? You could have used two tables instead of one.
    One (ORDER) with:
    ORDER_ID
    CUSTOMER_ID
    DATE
    Order_id would be a new surrogate key / primary key.
    Another table (ORDER_ITEM) with:
    ORDER_ID
    ORDER_ITEM
    It would be a table that links ORDERS to ITEMS. You get the idea.

  • Using Cursor and FOR LOOP to INSERT the data into table

    Hi all,
    I have SELECT statement that returns 3 rows:
    PROCESSNAME
    PROTDATE
    IMM
    2013-12-18
    Metrology
    2013-11-18
    CT
    2013-12-04
    SELECT  processName, MAX(NVL(protStartDate, protCreateDate)) AS protDate
        FROM TABLE(SEM_MATCH("{
                ?ipc rdf:type s:Protocol .
                ?ipc s:protocolNumber ?protNum .
                ?ipc s:protocolCreateDate ?protCreateDate .
                OPTIONAL {?ipc s:protocolSchedStartDate ?protStartDate }
                ?ipra rdf:type s:ProcessAggregate .
                ?ipra s:hasProtocol ?iprot .
                ?iprot s:protocolNumber ?protNum .
                ?ipra s:processAggregateProcess ?processName.
        }",sem_models("PROTS", "LINEARS"),NULL, SEM_ALIASES(SEM_ALIAS("","http://VISION/Data/SEMANTIC#"),SEM_ALIAS("s","http://VISION/DataSource/SEMANTIC#")),NULL))
            Group by processName
    Now I need to INSERT these values into the table along with the other values.
    these other values come from different table.
           INSERT INTO MODEL_CLASS_COUNTS (MODEL_NAME, CLASS_NAME, INS_COUNT, COUNT_DATETIME, PROCESS_NAME, PROT_DATE)
           VALUES
           ("$MODEL",     
                "${i}",
            (SELECT COUNT (DISTINCT S)  FROM TABLE(SEM_MATCH(
                            "{?s rdf:type :${i} . }",SEM_Models("$MODEL"),NULL, SEM_ALIASES(SEM_ALIAS("","http://VISION/DataSource/SEMANTIC#")),NULL))),
             SYSTIMESTAMP, %%here need to insert PROCESSNAME, PROTDATE%%
    t was giving me error:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    so i enclosed sparql query into single quotes.
    The code is as follows:
    declare
    type c_type is REF CURSOR;
    cur c_type;
    v_process varchar2(200);
    v_pdate varchar2(200);
    begin
    open cur for
           ' SELECT processName,  MAX(NVL(protStartDate, protCreateDate)) AS protDate   <-- it's complaining about this being too long identifier, i think...
            FROM TABLE
              (SEM_MATCH (
                            ?ipc rdf:type s:Protocol .
                            ?ipc s:protocolNumber ?protNum .
                            ?ipc s:protocolCreateDate ?protCreateDate .
                            OPTIONAL {?ipc s:protocolSchedStartDate ?protStartDate }
                            ?ipra rdf:type s:ProcessAggregate .
                            ?ipra s:hasProtocol ?iprot .
                            ?iprot s:protocolNumber ?protNum .
                            ?ipra s:processAggregateProcess ?processName.
                        }",SEM_Models("XCOMPASS", "XPROCESS"),NULL,    
              SEM_ALIASES(SEM_ALIAS("","http://VISION/Data/SEMANTIC#"),
              SEM_ALIAS("s", "http://VISION/DataSource/SEMANTIC#")),NULL))
               Group by processName';  
    loop
    fetch cur into v_process, v_pdate;
    exit when cur%NOTFOUND;
    --here I need to insert v_process , v_pdate into my table along with other values...
    dbms_output.put_line('values for process and prod_date are: ' || v_process || v_pdate );
    end loop;
    close cur;
    end;
    exit;
    Now, I get an error:
    ORA-00972: identifier is too long
    Does anyone know way around this?

    Hi,
      I tested something similar with insert into select  and it worked fine :
    insert into t_countries(ID,CITY ,POPULATION, DESCRIPTION, located, insdate )
    SELECT 1 id, city, o , city||' is a nice city' description,  max(nvl(locatedAt,'unknown')) as located,
      SYSTIMESTAMP
      FROM TABLE(SEM_MATCH(
        '{GRAPH :gCH {<http://www.semwebtech.org/mondial/10/countries/CH/> :hasCity ?cityID .
           ?cityID :name ?city .
           OPTIONAL{?cityID :locatedAt ?locatedAt .}
           ?cityID :population ?o .
        SEM_Models('VIRT_MODEL_MONDIAL'),
        SEM_Rulebases(null),
        SEM_ALIASES(SEM_ALIAS('','http://www.semwebtech.org/mondial/10/meta#'),
        SEM_ALIAS('prv','http://www.semwebtech.org/mondial/10/countries/CH/provinces/')
        null))
        group by city,o
        order by city;
    Or with execute immediate :
    declare
      v_country varchar2(200) :='http://www.semwebtech.org/mondial/10/countries/F/';
      v_text varchar2(2000);
    begin
    v_text := 'insert into t_countries(ID,CITY ,POPULATION, DESCRIPTION, located, insdate )
    SELECT 1 id, city, o , city||'' is a nice city'' description,  max(nvl(locatedAt,''unknown'')) as located,
      SYSTIMESTAMP
      FROM TABLE(SEM_MATCH(
        ''{<'||v_country||'> :hasCity ?cityID .
           ?cityID :name ?city .
           OPTIONAL{?cityID :locatedAt ?locatedAt .}
           ?cityID :population ?o .
        SEM_Models(''VIRT_MODEL_MONDIAL''),
        SEM_Rulebases(null),
        SEM_ALIASES(SEM_ALIAS('''',''http://www.semwebtech.org/mondial/10/meta#'') ),
        null))
        group by city,o
        order by city';
        dbms_output.put_line(v_text);
        delete from t_countries;
        execute immediate v_text ;
        commit;
    end;
    Marc

Maybe you are looking for

  • Need opinions on how to get sketches in Illustrator to become vectors

    Have Illustrator CS6, Medium Baboo tablet. I can draw well but it seems almost impossible to get the quality of my sketch work to go to Illustrator in a way I am happy with. I do not like what I see from scanner to Imagetrace either. This is largely

  • My library is.. well.. I don't know the word.

    My iTunes library is fine. But my iTunes music folder.. is missing things. Like songs I added to my Library years ago are not in the music folder. Is there a way to make iTunes put everything in the Library into its music folder? I saw this link: htt

  • Interactive reports do not execute with Z business role

    Hi all, We have created interactive reports which are working fine and displaying results with a standard business role. However, the report does not even execute when we use a custom business role - no blank screen no error, but the report does not

  • How to request iOS5 Feature?  (ActiveSync Policy)

    I would like to request a feature for iOS5 but do not know how.  What is the process to request a feature? We don't have any Mac's in our organization at this point but do have personally owned iPhone/iPod/iPad users requesting access to our Exchange

  • ITunes Skipping Songs/Part Songs

    Hi, I purchased an Apple iPod 3-4 years ago and loaded music into iTunes and purchased songs from the iTunes store. Late 2007 I started experiencing problems with songs starting then skipping partly through and moving on to the next song. This occure