Opening refcursor for every loop value

Guys,
I have a refcursor which is getting opened for different values which is coming from the enclosing loops but while executing the refcursor is getting fired for once .Please let me know if there is any caveats.
Here is the code pasted
declare
cursor cur_col_dtls is select column_name FROM user_tab_columns WHERE table_name ='JOURNAL_DATA' AND column_name LIKE UPPER('field_def_id%')
ORDER BY SUBSTR(column_name,-3);
v_commit_point number :=0;
type ref_cur IS ref CURSOR;
v_ref_cur ref_cur;
v_slct VARCHAR2(4000);
v_col_no NUMBER;
v_data tj_data_pivot%ROWTYPE;
BEGIN
FOR v_dtls IN cur_col_dtls LOOP
IF length(v_dtls.column_name)=16 THEN
v_col_no :=SUBSTR(v_dtls.column_name,-3);
ELSIF length(v_dtls.column_name)=15 THEN
v_col_no :=SUBSTR(v_dtls.column_name,-2);
ELSE
v_col_no :=SUBSTR(v_dtls.column_name,-1);
END IF;
v_slct :='select journal_entry_id, partition_date,'|| v_col_no||',field_def_id_'||v_col_no||', value_'||v_col_no||' from tp.journal_data where field_def_id_'||v_col_no||' is not null and journal_entry_id>(select NVL(max(journal_entry_id),0) from tj_data_pivot)';
-- DBMS_OUTPUT.PUT_LINE (v_dtls.column_name|| ' '||v_col_no||' '||v_slct);
IF v_ref_cur%ISOPEN THEN
close v_ref_cur;
END IF;
OPEN v_ref_cur FOR v_slct ;
<<innerloop>>
LOOP
FETCH v_ref_cur INTO v_data;
--dbms_output.put_line (v_slct);
EXIT innerloop WHEN v_ref_cur%NOTFOUND;
INSERT INTO TEST VALUES(v_data.journal_entry_id);
-- DBMS_OUTPUT.PUT_LINE (v_data.journal_entry_id||','||v_data.partition_date||','||v_data.field_value);
--INSERT INTO tj_data_pivot VALUES (v_data.journal_entry_id,v_data.partition_date,v_data.field_seq,v_data.field_def,v_data.field_value);
v_commit_point :=v_commit_point+1;
IF v_commit_point=1000 THEN
COMMIT;
v_commit_point :=0;
END IF;
END LOOP innerloop;
-- close v_ref_cur;
-- exit when v_col_no=1;
END LOOP;
-- v_slct :='select journal_entry_id, partition_date, 1, field_def_id_1, value_1 from tp.journal_data where field_def_id_1 is not null
END;

Congratulations!!
This is an excellent example of how PL/SQL can be abused.
Apart from that your 'code' will turn Oracle from a Ferrari into a T-Ford (black).
Your code doesn't scale as it uses dynamic sql.
You commit one of the gravest sins in Oracle: you commit inside a loop.
You don't use BULK COLLECT.
But more importantly: your data model is an utter complete mess, as it doesn't even adhere to First Normal Form, as it has repeating groups.
There is only one advice possible: before you do continue,
issue the
drop database
command.
Then issue the
Drop brain prafullu
command.
Then start learning databases, unlearning all of the evil practises you've 'learned' so far.
Sybrand Bakker
Senior Oracle DBA

Similar Messages

  • Trigger SEQ column for every new value of ID it should start from 1

    I have
    table table_A
    (ID NUMBER,
    SEQ NUMBER,
    DETAIL VARCHAR2(2000))
    In this table ID and SEQ are combined primary key
    Data looks like
    ID     SEQ     DETAIL
    1000     1     COMMENTS1
    1000     2     COMMENTS2
    1001     1     COMMENTS3
    1002     1     COMMENTS4
    1002     2     COMMENTS5
    1002     3     COMMENTS6
    1003     1     COMMENTS7
    I have ID as oracle generated seq Number , but I need trigger to generate SEQ column value for every new value of ID it should start from 1

    This is probably not something you would want to do in a trigger. You would generally be much better off storing ID and detail in the table and generating SEQ in a view, i.e.
    CREATE VIEW my_view
    AS
    SELECT id,
           DENSE_RANK() OVER( PARTITION BY id ORDER BY <<something>>) seq,
           detail
      FROM table_AUnless you can guarantee that only one session will be inserting data at a time, I don't see how you could make a trigger work here.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • How To Open PopUp for every 15 min Till User Saves The Data

    Hi all,
    I am working on an application where I need to open a popup for every 15 min till user saves the data and stop after users save the data. I am not able to get idea on how it could be done. Kindly post some views in which this could be achieved.
    Thanks in advance.

    Hi,
    one alternative is the uncommittedDataWarning property is a out of the box funcionality, but don´t have time configuration.
    https://blogs.oracle.com/shay/entry/warning_of_uncommitted_unsaved_changes
    if no you can use a af:poll in combination with a popup message

  • It's better or necessary open and close communicat​ion with instrument every loop?

    I must communicate with my instrument, but I must change its value, for example temperature, every loop. See the Figure to understand:
    I think that it is better if I open communication with my instrument out of while loop so I many operation: if I put Open VISA in While loop I open VISA session every loop, instead I think it is not intelligent. Can I open VISA SESSION out of the while loop or it is an error for EXCELLENT LABVIEW VI and I must open and close VISA SESSION every times I must talk (and set) with instrument? What is the better way?
    Message Edited by Michelle1892773 on 02-22-2010 02:00 PM

    Something like this?
    I do have to say, i don't know what is happening in the false case of yours, but if nothing happens with the 100 that is wired to the shift register, once you enter the true case, the value in the shift register will always be great than "i". You might as well do what I have done then. However, if something does happen with that number in your false case, then keep it the way you have it.
    That being said, why is the condition there to see if it has looped 100 times before doing the visa write??
    Message Edited by for(imstuck) on 02-22-2010 04:45 PM
    Message Edited by for(imstuck) on 02-22-2010 04:46 PM
    CLA, LabVIEW Versions 2010-2013
    Attachments:
    visa.PNG ‏13 KB

  • Open cursor for existing procedure

    Is it possible to open a refcursor for an existing procedure as apposed to opening a refcursor for a standard select statement. For example:
    Standard select:
    OPEN refcursor FOR
    select * from my_table;
    RETURN the_cursor;
    Based on an existing procedure:
    OPEN refcursor FOR
    my_package.my_procedure();
    RETURN the_cursor;
    Note: my_procedure returns a table of record type rows defined by myself in the package spec.
    Any help is much appreciated
    Regards
    Tony

    Hi Sven
    Thank you for that information however I am still a little unsure as to how to call the procedure including the necessary parameters. The procedure in question has the following IN parameters with one OUT parameter.
    my_procedure (p_context_id in number,
    p_username in varchar2,
    p_mdata out mtab)
    As you stated, if it is a procedure, which it is, then use the following:
    my_package.my_procedure(the_cursor);
    However if I need to pass parameters in the call that kind of conflicts where 'the_cursor' is?
    Any ideas?
    Tony

  • Procedure Problem - Open Cursor for SQL

    in my form I added a procedure. this is working fine in SQL but when I try to run through form it gives error.
    Code of Procedure:-
    PROCEDURE Proc_Purchase_all IS
    BEGIN
      declare
         v_sql varchar2(4000);
         v_user varchar2(30);
         v_sep varchar2(20);
         v_cur SYS_REFCURSOR;
       pur_rec    purchase%ROWTYPE;
       begin
         for u in (SELECT * FROM ALL_TABLES WHERE OWNER LIKE 'BMP%' and table_name ='PURCHASE') loop
           v_sql := v_sql || v_sep || 'SELECT * from '||u.owner||'.purchase';
          v_sep := ' UNION ALL ';
        end loop;
        open v_cur for v_sql;
      Loop
      Fetch v_cur into pur_rec;
      Exit when v_cur%NOTFOUND;
      --DBMS_OUTPUT.PUT_LINE (PUR_REC.S_CODE||' '||Pur_rec.s_name);
      End Loop;
        close v_cur;
    end;
    END;Error Line
    * open v_cur for v_sql;*
    Error is :-
    Encountered the symbol 'V_SQL' when expecting one of the following.
    select
    Encountered the symbol END when expecting one of the following.
    Begin function package pragma procedure external

    I changed my code ALSO Showing SAME error .
    SQL> Declare 
      2    v_sql varchar2(4000);
      3       v_user varchar2(30);
      4       v_sep varchar2(20);
      5    TYPE R_CURSOR IS REF CURSOR RETURN purchase%ROWTYPE;
      6       C_Pur R_CURSOR;
      7       ER C_pur%ROWTYPE;
      8       BEGIN
      9    for u in (SELECT * FROM ALL_TABLES WHERE OWNER LIKE 'BMP%' and table_name ='PURCHASE') loop
    10         v_sql := v_sql || v_sep || 'SELECT * from '||u.owner||'.purchase';
    11        v_sep := ' UNION ALL ';
    12      end loop;
    13   OPEN C_Pur FOR V_sql;
    14       LOOP
    15       FETCH C_Pur INTO ER;
    16      EXIT WHEN C_Pur%NOTFOUND;
    17    
    18      END LOOP;
    19      CLOSE C_Pur;
    20     END; 
    21  /
    OPEN C_Pur FOR V_sql;
    ERROR at line 13:
    ORA-06550: line 13, column 7:
    PLS-00455: cursor 'C_PUR' cannot be used in dynamic SQL OPEN statement
    ORA-06550: line 13, column 2:
    PL/SQL: Statement ignoredEdited by: Ahmed on Jan 13, 2011 1:58 AM

  • Set Default Opening Application for a certain type of file?

    I need some help saving time! I have lots of .groovy files that my apple doesn't know how to open and i have to select a default opening application for every single file! Is there a way to do this for multiple files or for a certain file type? thanks!
    amber

    Sure. Click on a file, and then go to File-Get Info (or CMD-I) In the box that pops open, choose the app you want the .groovy files to open with, and click change all. That should do it.

  • I'm doing a scan around a line by sampling data 360 degrees for every value of z(z is the position on the line). So, that mean I have a double for-loop where I collect the data. The problem comes when I try to plot the data. How should I do?

    I'm doing a scan around a line by sampling data 360 degrees for every value of z(z is the position on the line). So, that mean I have a double for-loop where I collect the data. The problem comes when I try to plot the data. How should I do?

    Jonas,
    I think what you want is a 3D plot of a cylinder. I have attached an example using a parametric 3D plot.
    You will probably want to duplicate the points for the first theta value to close the cylinder. I'm not sure what properties of the graph can be manipulated to make it easier to see.
    Bruce
    Bruce Ammons
    Ammons Engineering
    Attachments:
    Cylinder_Plot_3D.vi ‏76 KB

  • Unable to set a new value in an extended property from within a For Each Loop

    Setting a new value in an extented property fails when the property is dereferenced within a For Each loop usin the item  iterator. However, if you use the First or Last Iterators from the Find Targets activity works fine.
    The error message is : "Setting a value for this object type is not allowed"
    I believe this is a defect, can you please confirm

    Looks like a bug that needs to be reported.
    While we are figuring out the issue you can work around the bug.
    Add another "Find Targets" inside the loop, and use the ID of the current item in the loop to find the target (again) by ID.
    And then use Set Variable on the target that was just found...
    I know... Not an ideal workaround, so please open a Severity 4 bug for this.

  • Having trouble with inner for loop values in my procedure

    Hi ...
    I am using oracle 10g and here is my procedure ...
    create or replace procedure sales_information is
    v_qty number(10);
    rem_qty number(10):=0;
    cursor pck_quantity is
    select * from sales_info;
    cursor no_of_labels is
    select ceil(sum(nvl(total_quantity,actual_quantity))/400) from sales_info;
    begin
    for j in no_of_labels
    loop
    for i in pck_quantity
    loop
    select nvl(i.total_quantity,i.actual_quantity) into v_qty from sales_info;
    if v_qty>=i.packed_quantity and rem_qty=0 then
    insert into sales_order values------------
    rem-qty:=v_qty-i.packed_quantity;
    v_qty:=rem_qty;
    exit;
    else if v_qty>=i.packed_quantity and rem_qty>=400 then
    insert into sales_order values-----------
    rem_qty:=v_qty-rem_qty;
    v_qty:=rem_qty;
    exit;
    else if v_qty>=i.packed_quantity and rem_qty>0 then
    rem_qty:=v_qty+rem_qty-i.packed_quantity;
    v_qty:=rem_qty;
    insert into sales_order values-----------
    else if v_qty is null and rem_qty>0 and then
    insert into sales_order values-----------
    else if v_qty<i.packed_quantity and rem_qty:=0 then
    rem_qty:=v_qty;
    else if v_qty<i.packed_quantity and rem_qty>0 then
    if (v_qty+rem_qty)>400 then
    insert into sales_order values-----------
    rem_qty:=v_qty+rem_qty-i.packed_quantity;
    v_qty:=rem_qty;
    end if;
    end if;
    end loop;
    end loop;
    The inner for loop will retrieve the same values of v_qty for every iteration of outer for loop when it runs the following select statement:
    select nvl(i.total_quantity,i.actual_quantity) into v_qty from sales_info;
    and thus loses the previously computed values of v_qty and rem_qty
    in the previous iteration of outer for loop whereas i want the inner for loop to iterate over it's previously computed values of v_qty and rem_qty but cant think of a workaround.

    h4. Thanks Dave for explanation. Hope I understood your requirement and below code resolves that
    -- Creating table SALES_INFO
    CREATE TABLE SALES_INFO
    (    S_NO             NUMBER(1),
         ACTUAL_QUANTITY  NUMBER(10),
         TOTAL_QUANTITY   NUMBER(10),
          PACKED_QUANTITY  NUMBER(10)
    -- Creating table sales_order
    CREATE TABLE SALES_ORDER
    (    S_NO             NUMBER(1),
         LABEL            VARCHAR2(30),
         ORDER_QUANTITY   NUMBER(10)
    -- Push SALES_INFO data
    INSERT INTO SALES_INFO VALUES(1,1000,800,400);
    INSERT INTO SALES_INFO VALUES(2,800,600,400);
    INSERT INTO SALES_INFO VALUES(3,800,NULL,400);
    INSERT INTO SALES_INFO VALUES(4,NULL,600,400);
    CREATE OR REPLACE PROCEDURE populate_sales_order AS
    CURSOR get_sales_info IS
    SELECT s_no,
               NVL(total_quantity,actual_quantity) total_quantity,
            packed_quantity
    FROM   sales_info;
    v_s_no          PLS_INTEGER := 0;
    v_rem_qty     PLS_INTEGER := 0;
    v_label_num   PLS_INTEGER := 1;
    BEGIN
    FOR rec IN get_sales_info LOOP
        v_rem_qty := rec.total_quantity + v_rem_qty;
        v_s_no    := rec.s_no;
         WHILE v_rem_qty >= rec.packed_quantity LOOP
           INSERT INTO sales_order( s_no, label, order_quantity)
           VALUES ( v_s_no, 'LABEL' || v_label_num, rec.packed_quantity );
           -- Reduce the packed qty from total qty and increment label counter
           v_rem_qty   := v_rem_qty - rec.packed_quantity ;
           v_label_num := v_label_num + 1;
         END LOOP;
    END LOOP;
    -- Put the last lot remaining qty into last carton
    IF v_rem_qty > 0 THEN
    INSERT INTO sales_order( s_no, label, order_quantity)
    VALUES (v_s_no, 'LABEL' || v_label_num, v_rem_qty );
    END IF;
    COMMIT;
    END;
    S_NO    LABEL                                ORDER_QUANTITY
      1          LABEL1                                    400
      1          LABEL2                                    400
      2          LABEL3                                    400
      3          LABEL4                                    400
      3          LABEL5                                    400
      4          LABEL6                                    400
      4          LABEL7                                    400
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to execute a loop for every 15 minutes

    how to execute a loop for every 15 minutes or 30 minutes constantly...

    I need to insert a number into an array for every 15mins continuously..and the array need to hold all datas for example in 0th position i insert a value 10 by 10.00am, after that at 1st position i need to insert 11 by 10.15am, next at 2nd position i need to insert 12 by 10.30am and so on...how this can be done

  • Loop the table entry and for every entry perform some action.

    Hello Experts,
    I have a requirement where there are let say n no. of entries in my ITAB and now for every entry i have to check certain field value and based on that i have to send respective mail.
    Now this has to run in background mode and the job will run on daily basis so the entries of table that are already processed should not be reprocessed.The scenario is every day the new entries will be added to ITAB and the newly added entries should be processed only.
    Please provide some sample code if possible.
    Thanks,
    Naveen

    Hi,
    I can not add a new field to the existing ztable. Crating a copy of ztable with addtional field status and setting it as processed against the record whenever i populate ITAB from ztable could be a solution but seems very lenthy method.
    There is one filed zdate  so write the code as below:-
    loop at itab where zdate = sy-datum
    email code------
    endloop.
    OR can i make use of
    loop at itab into wa
      ON change  of <filed1>
    email code-----
       ENDON
    endloop.
    Thanks,
    Naveen

  • How to add a default value in a site column for every item in a document library

    HI
    i created a content type with some site columns ,
    and included in a Document library.
    Process ( content type)
    -ProcessNo
    -ProcessName
    after that i uploaded 100 Documents but not  added value in a site column process name.
    now  how i add a default value in a site column for every document in a document library 
    adil

    HI
    i get below error when i change the script 
    PS C:\scripts> C:\Scripts\updatedefaultvalue.ps1
    Cannot index into a null array.
    At C:\Scripts\updatedefaultvalue.ps1:8 char:7
    + IF($i[ <<<< "Title"] -eq $null)
        + CategoryInfo          : InvalidOperation: (Title:String) [], RuntimeExce
       ption
        + FullyQualifiedErrorId : NullArray
    $web = Get-SPWeb http://tspmcwfe:89/
    $list = $web.Lists["test"]
    $item = $list.Items | Where { $_["Name"] -eq "Emc" }
    foreach($i in $items)
    IF($i["Title"] -eq $null)
             $i["Title"] = "test"
           $i.Update()
    adil
    Why are you piping a where in the items? Do you only want to add the "test" to ones matching
    a name?
    If you have ISE installed on your server I recommend you put your code in there and debug it. 
    If this is helpful please mark it so. Also if this solved your problem mark as answer.

  • Maximum open Cursors Excedded error - for every transaction

    Hi All,
    I am getting the maximum opn cursors exceeded error suddenly for every single db transaction i am trying to make in my application. this did not happen previously during my developemnt and testing phase.
    I have a question here that i tried to google but failed to get satisfactory answer.:-
    When we use a cursor in the stored procedure to fetch data, how to make oracle automatically close the cursors once the stored proc finishes executin. Or is there something i have to follow other with my current open cursors limit to ensure this problem does not happen?
    Thanks,
    Chaitanya

    Hi Justin,
    My oracle stored procs are called by java framework. In each place i was closing the connection object but there were a few places where i was not closing the resultset object which directly pointed to my oracle cursor.
    I have closed the objects in such places and tried again but still i am getting the same error. Mit it be an instance where the oracle db is not allowing me to connect to it at all. Something like restarting it would help? Restarting the server where the oracle software is hosted.
    Please excuse my blatant ignorance in this issue.
    Thanks,
    Chaitanya

  • I get "We can't verify who created this file" for every PPT or PPTX file I open on my local network (Win 7 only, not Win 8)

    I've searched around, and perhaps I've missed it, but I have a specific problem that just started today (4/1/2014).  I have 3 PCs in a local home network and they all have been sharing things fine so far.  PC1 is my main storage computer (Windows
    7), another is a laptop (Windows 7) and a third is a laptop (Windows 8.1). 
    On the Windows 7 laptop, when I open Windows Explorer and navigate my way to a file I want to open (which is stored on PC1) and double click on the file to open it USED to just open using the right program (PowerPoint2007) which I have fully installed on
    the Win 7 laptop.  Note also that "Microsoft Office (2010)" came pseudo-loaded on the laptop, but I have set the default for all PPT and PPTX files to be opened using PowerPoint2007.  I've had a few hiccups in the past where this undesired,
    not-fully-loaded version tries to get in the way of me opening files with PowerPoint2007, but right now all files are set to open using PowerPoint2007.
    So I'm not going on the internet, I'm not using IE, and this is only happening with PPT and PPTX files and only on my Win 7 laptop.  DOC/DOCX and XLS/XLSX files open fine with the 2007 version of the Word and Excel respectively.  All files, including
    the PPT and PPTX files on PC1 are openable without trouble on the Win8 laptop with PowerPoint2007.
    Any idea why this would suddenly start happening? 

    Sorry, I should have said that I'm having this issue on Win7 Enterprise SP1 and not XP.
    I'm having trouble understanding how cacheing is related to how windows resolves this security violation, and why changing the Internet's custom security settings makes the caching problem go away? You are correct in that running a mdb file from
    the desktop does not produce the warning; however this is a database housed on a shared drive so that the database is accessable to other users...
    unfortunately unblock is not presented as an option in the file properties, and even if it was that seems a bit impractical to do for every single zip file on a share drive which would accumulate more files as multiple users add to it.
    Also: I have two computers with the same settings in both the trusted sites and the Launch apps, but one opens fine and the other does not.

Maybe you are looking for