Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using Cursor and FOR LOOP to INSERT the data into table

Angelina84Dec 23 2013 — edited Jan 6 2014

Hi all,

I have SELECT statement that returns 3 rows:

PROCESSNAMEPROTDATE
IMM2013-12-18
Metrology2013-11-18
CT2013-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?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 3 2014
Added on Dec 23 2013
2 comments
17,317 views