Cursor scope : cursor is not recognising in for loop.

CREATE or REPLACE PROCEDURE TEST(
date3 IN DATE,
Out_Entity OUT Test1.RefCsr
AS
FirstNameListTable LIST_TABLE;
FinalFirstNameListTable LIST_TABLE := LIST_TABLE();
firstName employee.first_name%TYPE;
date1 employee.start_date%TYPE;
date2 employee.start_date%TYPE;
CURSOR main_cur
   IS
      WITH include_rec
        AS (select first_name,count(1) over (partition by first_name) firstNameCount,start_date  from employee where city='Vancouver')
SELECT distinct first_name
        FROM include_rec
       WHERE firstNameCount>500;
BEGIN
    OPEN main_cur;
    FETCH main_cur BULK COLLECT INTO FirstNameListTable;
    CLOSE main_cur;
FOR i IN FirstNameListTable.FIRST .. FirstNameListTable.LAST
    LOOP
firstName:=FirstNameListTable(i);
SELECT min(start_date),max(start_date) into date1,date2 FROM include_rec where first_name=firstName;
--business logic
    END LOOP;
OPEN Out_Entity FOR SELECT * FROM TABLE(
                                                CAST (
                                                        FinalFirstNameListTable AS LIST_TABLE
                                        ) Nos;
END;
create or replace TYPE "LIST_TABLE" as table of varchar2(20);
SELECT min(start_date),max(start_date) into date1,date2 FROM include_rec where first_name=firstName;In above query, getting error:table or view doesnt exit. When i replaced "include_rec" with "employee",error is resolved.But i have to use include_rec,Because i dont want to query on lage table employee, i know my final query output will be subset of include_rec table.
Means it is clear that cursor is not recognising in for loop and how can i resolve it?

Can u please tell me code about "creating permanent object or view." in this context. I don't really want to. This is not a route you should be encouraged to go down.
A view is the correct mechanism for reusing SQL. So I just mean:
CREATE OR REPLACE VIEW include_rec AS
select first_name,count(1) over (partition by first_name) firstNameCount,start_date  from employee where city='Vancouver';Then you get rid of "WITH include_rec AS ()..." from both statements.
But this is pants.
Surely all this should just be:
CREATE or REPLACE PROCEDURE TEST (
  date3 IN DATE,
  Out_Entity OUT Test1.RefCsr
AS
BEGIN
  OPEN Out_Entity FOR
    SELECT first_name, count(*), min(start_date), max(start_date)
    FROM   include_rec
    WHERE  employee
    GROUP BY first_name
    HAVING COUNT(*) > 500;
END;
/

Similar Messages

  • IPhoto 09 not recognising locations for geo-tagged photos

    I've been geotagging my photos in iPhoto for over a year now, using HoudahGeo. This works really well and integrates great with sites such as Flickr that support geo-tagged photos.
    When I installed iPhoto 09, it only recognises about 30 photos out of several thousand as geo-tagged. These are mainly photos taken with my iPhone, but also some taken with my Sony camera and geotagged with HoudahGeo.
    I've checked a sample of the ones it does not put in a location (all taken with the same Sony camera) and the Exif data is there with the correct latitude and longitude but iPhoto 09 sees these fields as blank when I do a Photos > Shows Extended Photo Info, the latitude and longitude fields are blank.
    Anyone any ideas what I am doing wrong / how I get the photos to show on the map in iPhoto 09?

    I usually import the photos direct to iPhoto from my camera and then use HoudahGeo to geo-tag the original copies of iPhoto in my library. Prior to iPhoto 9 this is not a big issue as it did not use the geo-tag information directly but with iPhoto 9 it's a big issue for users like me as I'd rather not have to export from the camera to a folder, geo-tag and then import to iPhoto 9 as it's messy to say the least.
    As I noted - this will not work - iPhoto is a database and it keeps data about the photo in its database - as all database programs do - and changing the data elsewhere will not update the database
    Anytime you apply modifications directly to the data in the iPhoto database you are risking corruption and it is recommended that you not ever modify the contents of the iPhoto library
    I use an ATP Photo Finder - http://www.atpinc.com/p2-4a.php?sn=00000414 - which applies the Geocodeing data directly to my photos so when I import them they are complete - it simplifies my work flow a lot
    Surely Apple will have thought of users like me who geo-tag using a GPS external to the camera and provided some easy method of re-reading the Exif data in the photos in real time?
    iPhoto menu ==> provide iPhoto feedback
    LN

  • Not Recognising iPod for more than 2 seconds

    I need some help. When I plug my iPod into my computer, and I click on My Computer, the iPod shows up there for about 2 or 3 seconds, and then goes away, and the iPod goes to the main menu. What I want to do is open the iPod in My Computer but when it doesn't show up, I can't do this. Any suggestions?

    I had a problem similar to this. When I open iPod updater it tells me it could not mount my iPod. I replaced the hard drive with that of my iPod U2 and now it works fine.

  • Iphone 5 not recognising password for Hotmail.co.uk email address.

    When I'm trying to use my Hotmail account on my iPhone 5 it keeps telling me the password is incorrect.  I have 2 Hotmail accounts and the other account is working fine but that is a Hotmail.com email and the other is a Hotmail.co.uk email. I have reset the password 4 times and tried to re-entre these on the mail section on my phone but it still isn't working.
    Has anyone else experienced anything like this and can some please help. I need to be able to access my emails while I'm away from work.
    Thanks

    Hi JessWinTea,
    Thanks for using Apple Support Communities. Based on what you stated, it sounds like a hotmail account isn't accepting a password. I would recommend that you read this article, it may be able to help the issue.
    Get help with Mail on iPhone, iPad, and iPod touch - Apple Support
    Log in to your email provider's website to make sure that the account is active and the password is correct.
    Make sure your settings are correct using Mail Settings Lookup.
    Restart your iOS device.
    Delete the affected email account from your device.
    Tap Settings > Mail, Contacts, Calendars.
    Tap the affected email account.
    Tap Delete Account.
    Add your account again.
    Cheers,
    Mario

  • JButton not working with for loop...

    I am still very new to Java and am having trouble grasping it. I am trying to put together a program that paints a graphic and then each time the "Press Me" button is pressed, an oval randomly appears giving the impression that the picture is 'disappearing' a little at a time. When I run it now, 20 ovals randomly appear all at once instead of waiting for the button to be pushed. Does anyone have any advice for me on how to modify the code? Here is what I have so far...
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.geom.*;
    public class JEraseImage extends JApplet implements ActionListener
    private ImageIcon image1 = new ImageIcon("bear.jpg");
    int startPosX = 80;
    int startPosY = 80;
    int imageWidth = 275;
    int imageHeight = 250;
    Container con = getContentPane();
    private JButton pressMeButton = new JButton("Press Me");
    public void init()
    image1 = new ImageIcon("bear.jpg");
    con.setLayout(new FlowLayout());
    con.add(pressMeButton);
    pressMeButton.addActionListener(this);
    public void paint(Graphics gr)
    gr.drawImage(image1.getImage(), 80, 80, (this));
    Graphics2D gr2D = (Graphics2D)gr;
    pressMeButton.repaint();
    gr.setColor (Color.white);
    for(int count = 0; count < 20; ++count)
    int x = (int) (Math.random() * imageWidth) + startPosX;
    int y = (int) (Math.random() * imageHeight) + startPosY;
    gr.fillOval(x, y, 50, 40);
    public void actionPerformed(ActionEvent e)
    Object source = e.getSource();
    if(source == pressMeButton)
    repaint();

    Here ya go, I think this should do it:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.util.*;
    import javax.swing.*;
    import java.awt.geom.*;
    public class Junk extends JApplet implements ActionListener
        private ImageIcon image1;
        BufferedImage bi;
        Graphics g;
        int x;
        int y;
        int startPosX = 80;
        int startPosY = 80;
        int imageWidth;
        int imageHeight;
        Container con = getContentPane();
        JButton pressMeButton = new JButton("Press Me");
        public void init()
           image1 = new ImageIcon("bear.jpg");
           bi = new BufferedImage(image1.getIconWidth(), image1.getIconHeight(), BufferedImage.TYPE_INT_RGB);
           g = bi.getGraphics();
           g.drawImage(image1.getImage(), 0, 0, null);
           con.setLayout(new FlowLayout());
           con.add(pressMeButton);
           pressMeButton.addActionListener(this);
        public void paint(Graphics gr){
            super.paint(gr);
            gr.drawImage(bi, startPosX, startPosY, this);
        public void actionPerformed(ActionEvent e)
           g.setColor(Color.WHITE);
           Object source = e.getSource();
           if(source == pressMeButton)
           for(int count = 0; count < 20; ++count)
                     int x = (int) (Math.random() * imageWidth) + startPosX;
                     y = (int) (Math.random() * imageHeight) + startPosY;
                     g.fillOval(x, y, 50, 40);
                     repaint();
    }Note: I've not run this.

  • Bulk collect usage in cursor for loop

    Hi Team,
    I have one cursor like below assuming cursor is having 3000 records,
    CURSOR csr_del_frm_stg(c_source_name VARCHAR2 , c_file_type VARCHAR2)
    IS
    SELECT stg.last_name,stg.employee_number,stg.email
    FROM akam_int.xxak_eb_contact_stg stg
    MINUS
    SELECT ss.last_name,ss.employee_number,ss.email
    FROM akam_int.xxak_eb_contact_stg_ss ss;
    I declared one record type variable as,
    TYPE emp_rec IS RECORD (LAST_NAME             VARCHAR2(40)
    *,EMPLOYEE_NUMBER VARCHAR2(50)*
    *,EMAIL VARCHAR2(80)*
    TYPE emp_rec_ss IS VARRAY(3000) OF emp_rec;
    Im updating the status of those cursor records to 'C' in the below for loop,
    FOR l_csr_del_frm_stg IN csr_del_frm_stg(p_source_name , p_file_type)
    LOOP
    FETCH csr_del_frm_stg BULK COLLECT INTO emp_rec_ss LIMIT 500;
    FORALL i IN emp_rec_ss.FIRST..emp_rec_ss.LAST
    UPDATE akam_int.xxak_eb_contact_stg stg
    SET akam_status_flag    = 'C'
    WHERE stg.employee_number = emp_rec_ss(i).employee_number;
    EXIT WHEN csr_del_frm_stg%NOTFOUND;
    END LOOP;
    Getting following errors if i compile the code,
    PLS-00321: expression 'EMP_REC_SS' is inappropriate as the left hand side of an assignment statement
    PLS-00302: component 'FIRST' must be declared

    Use cursor variables:
    declare
        v_where varchar2(100) := '&where_clause';
        v_cur sys_refcursor;
        v_ename varchar2(30);
    begin
        open v_cur for 'select ename from emp where ' || v_where;
        loop
          fetch v_cur into v_ename;
          exit when v_cur%notfound;
          dbms_output.put_line(v_ename);
        end loop;
        close v_cur;
    end;
    Enter value for where_clause: deptno = 10
    CLARK
    KING
    MILLER
    PL/SQL procedure successfully completed.
    SQL> /
    Enter value for where_clause: sal = 5000
    KING
    PL/SQL procedure successfully completed.
    SQL> /
    Enter value for where_clause: job = ''CLERK''
    SMITH
    ADAMS
    JAMES
    MILLER
    PL/SQL procedure successfully completed.
    SQL>  SY.

  • Getting the label of a JButton in a for loop

    hi,
    I doing a project for my course at the minute and im in need of a bit of help. I have set up 1-d array of buttons and i have layed them out using a for loop. I have also added an annoymous action listener to each button in the loop. It looks something lke this:
    b = new JButton[43];
    for (int i=1; i<43; i++)
    b[i] = new JButton(" ");
    b.addActionListener(
    new ActionListener()
    public void actionPerformed(ActionEvent e)
              System.out.println("..........");
    }); // addActionListener
    } // for
    I want the "System.out.println( ..." line, to print out the "i" number of the button that was pressed but i cannot figure out how to do it. I cannot put "System.out.println(" "+i);" as it wont recognise i as it is not inside the for loop. Does anyone have any suggestions?
    Thanks!!

    class ButtonExample extends JFrame implements ActionListener{The OP wanted to have anonymous listeners, not a subclassed JFrame
    listening to the buttons. I don't know if the following is the best design,
    since the poster has revealed so little, but here is how to pass the
    loop index to an anonymous class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ButtonExample {
        private JButton[] buttons = new JButton[24];
        public JPanel createGUI() {
            JPanel gui = new JPanel(new GridLayout(6,  4));
            for(int i=0; i<buttons.length; i++) {
                final int ii = i; //!! !
                buttons[i] = new JButton("button #" + i);
                buttons.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent evt) {
    System.out.println("number " + ii);
    gui.add(buttons[i]);
    return gui;
    public static void main(String[] args) {
    ButtonExample app = new ButtonExample();
    JPanel gui = app.createGUI();
    JFrame f = new JFrame("ButtonExample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(gui);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);

  • Reasons why to use Iterator for List rather than for loop ?

    when i use the iterator and for loop for traversing through the list. it takes the same time for iterator and also for for loop. even if there is a change it is a minor millisecond difference.
    what is the actual difference and what is happening behind the traversing list through iterator
    if we are using we are importing extra classes ...if we are using for loop there is no need to import any classes

    If you have an array-backed collection, like an ArrayList, then the difference between using an iterator and get() will be negligible.
    However, if you have a linked list, using get() is O(n^2) whereas iterator is O(n).
    So with an iterator, regardless of what your underlying data structure, a list of 100,000 elements takes 1,000 times as long to iterate over as a list with 100 elements. But using get() on a LinkedList, that same 100,000 element list will take 1,000,000 times as long as the 100 item list.
    There's no real benefit to ever using get()
    Side note: I've been comparing iterators to get(), not iterators to for loops. This is because whether it's a for or a while has nothing to do with whether you use an iterator or get(). The way I use iterators is for (Iterator iter = list.iterator(); iter.hasNext(); ) {
        Foo foo = (Foo)iter.next();
    }

  • Avoid repeating a 'for' loop 3 times

    Any ideas how can I make my code more efficient by not
    repeating the for loop 3 times within a script? Any tutorial links
    or first hand experience – I’d be grateful for any
    pointers:
    1) First I use it to set up a drag n’ drop activity:
    for (var i:Number = 0; i<words.length; i++) {
    //set a var for the instances on stage:
    var eachWord:String = "drag"+[i+1]+"_mc";
    this[eachWord].word_txt.text = words
    [0];
    this[eachWord].onPress = function() {
    startDrag(this, false, leftLimit, topLimit, rightLimit,
    bottomLimit);
    this[eachWord].onRelease =
    this[eachWord].onReleaseOutside=function () {
    this.stopDrag();
    2) Then I use it in the part that makes it accessible by
    keyboard:
    function myOnKeyDown() {
    for (var i:Number = 0; i<words.length; i++) {
    var thisDrag:String = "drag"+[i+1]+"_mc";
    if (Key.isDown …
    ETC along with a listener object
    3) I also have to use it in another function that the user
    can call to toggle something on/off within each drag object.
    Thanks in advance if anyone can help.

    thanks for the reply! I actually figured out a different
    (although probably less efficient) way to do it. I put David's
    script just before the replay button and set it up like this:
    stop();
    gotoAndPlay(1);
    if (!loopCount) {
    var loopCount:Number = 0;
    loopCount++;
    if (loopCount >= 3) {
    this.gotoAndPlay(359);
    this was placed at frame 358, with the button placed at 359,
    so after it looped 3 times it continued on to 359, showed the
    button and stopped the movie there. again, not the most elegant but
    it did the job

  • Teststand XML Translator For LOOP Step

    HI, I'm trying to write an XML translator usinc the C++ example. So far I made work "if" , "while" , "end" and i'm trying to make the "for" loop working as well but i have a issue when i insert the dataProperty.
    The XML code i wrote id the following :
    <Data dataProperty="InitializationExpr" type = "string"> <Value>"Locals = 0"</Value> </Data><Data dataProperty="ConditionExpr" type = "string"> <Value>"Locals &lt; 10"</Value> </Data><Data dataProperty="IncrementExpr" type = "string"> <Value>"Locals += 1"</Value> </Data> 
    so the issie is that is i use the " " it works in the PropertyBrowser window but not in the For Loop window and if i dont use the " " is the opposite.
    I even tried to change the property CustomLoop followinf the same syntax but it doesnt work:
    <Data dataProperty="CustomLoop" type = "bool"> <Value>true</Value> </Data> 
    can anybosy help me with this?
    thank you
    Luca

    If I use Locals.X == 10 it gives me an error in the Number of Loop field in the For Loop window. What i really would like to know is how to set the properties for every step because beside few of them that i can set with dataProperty="ConditionExpr" or dataProperty="TitleExpr" i dont know how to set the other ones.
    For istance if i want to have a Sequence Call (I already wrote code so to have more then one Sequence) in a Sequence that calls another one i can have code like this:
    <Sequence name="MainSequence">
    <Step name="CallSeq2" type="SeqCall">
    </Step>
    </Sequence>
    <Sequence name="MainSequence2">
    </Sequence>
    now I dont know how to pass values to the step so to fill the File Pathname and Sequence fields in the Module window can I use dataProperty? and in cas I can what is the Sintax?
    thank you
    Luca

  • For Loop exits prematurel​y - Arrays and Shift Registers

    I have attached some preliminary code (work in progress) for the RC4 encryption algorithm. For some reason the middle for loop exits prematurely. In other words it exits after 2 iterations instead of the 256 iterations that N is set to.
    I thought this was not possible and therefore I am presuming I have made some not so obvious error in attempting to use a shift register with an array.
    Please have a look. Thanks.
    Attachments:
    RC4 Encryption beta.vi ‏78 KB

    You misunderstand how a for loop operates. You can either wire a number to the N terminal or you can wire an array into it with auto-indexing turned on. With an array input, the for loop will iterate equal to the size of the array. When you wire both (a practice I do not recomend), the for loop will iterate to whichever is smaller - the array size or the N terminal. Both of your for loops on the left side is creating arrays with only two elements. I suspect that what you need in both of them is a shift register instead of exiting the for loop with auto-indexing turned off.

  • Why use cursor and for loop?

    Hi All
    So in general why would we use a cursor and a for loop to do update in a stored procedure?
    Why wouldnt we just use a single update statement ?
    is there compelling reason for using a cursor and a for loop: I am reading some code from a co-worker that the business logic for the select (set need to be updated) is complex but the update logic is simple (just set a flag to (0 or 1 or 2 or 3 or 4).
    But eventually the select come down to a key (row_id) so I re-write it using just a single sql statement.
    The size of the main table is about 2.6 to 3million rows
    Any thoughts on that??
    The code below I just do a google for cursor for update example in case for something to play with
    -Thanks for all your input
    create table f (a number, b varchar2(10));
    insert into f values (5,'five');
    insert into f values (6,'six');
    insert into f values (7,'seven');
    insert into f values (8,'eight');
    insert into f values (9,'nine');
    commit;
    create or replace procedure wco as
      cursor c_f is
        select a,b from f where length(b) = 5 for update;
        v_a f.a%type;
        v_b f.b%type;
    begin
      open c_f;
      loop
        fetch c_f into v_a, v_b;
        exit when c_f%notfound;
        update f set a=v_a*v_a where current of c_f;
      end loop;
      close c_f;
    end;
    exec wco;
    select * from f;
    drop table f;
    drop procedure wco;
    Joining multiple tables
    create table numbers_en (
      id_num  number        primary key,
      txt_num varchar2(10)
    insert into numbers_en values (1, 'one'  );
    insert into numbers_en values (2, 'two'  );
    insert into numbers_en values (3, 'three');
    insert into numbers_en values (4, 'four' );
    insert into numbers_en values (5, 'five' );
    insert into numbers_en values (6, 'six'  );
    create table lang (
       id_lang   char(2) primary key,
       txt_lang  varchar2(10)
    insert into lang values ('de', 'german');
    insert into lang values ('fr', 'french');
    insert into lang values ('it', 'italian');
    create table translations (
      id_num    references numbers_en,
      id_lang   references lang,
      txt_trans varchar2(10) not null
    insert into translations values (1, 'de', 'eins'   );
    insert into translations values (1, 'fr', 'un'     );
    insert into translations values (2, 'it', 'duo'    );
    insert into translations values (3, 'de', 'drei'   );
    insert into translations values (3, 'it', 'tre'    );
    insert into translations values (4, 'it', 'quattro');
    insert into translations values (6, 'de', 'sechs'  );
    insert into translations values (6, 'fr', 'six'    );
    declare
      cursor cur is
          select id_num,
                 txt_num,
                 id_lang,
                 txt_lang,
                 txt_trans
            from numbers_en join translations using(id_num)
                       left join lang         using(id_lang)
        for update of translations.txt_trans;
      rec cur%rowtype;
    begin
      for rec in cur loop
        dbms_output.put (
          to_char (rec.id_num         , '999') || ' - ' ||
          rpad    (rec.txt_num        ,   10 ) || ' - ' ||
          rpad(nvl(rec.txt_trans, ' '),   10 ) || ' - ' ||
                   rec.id_lang                 || ' - ' ||
          rpad    (rec.txt_lang       ,   10 )
        if mod(rec.id_num,2) = 0 then
          update translations set txt_trans = upper(txt_trans)
           where current of cur;
           dbms_output.put_line(' updated');
        else
          dbms_output.new_line;
        end if;
      end loop;
    end;
    /Edited by: xwo0owx on Apr 25, 2011 11:23 AM

    Adding my sixpence...
    PL/SQL is not that different from a SQL perspective than any other SQL client language like Java or C# or C/C++. PL/SQL simply integrates the 2 languages a heck of a lot better and far more transparent than the others. But make no mistake in that PL/SQL is also a "client" language from a SQL perspective. The (internal) calls PL/SQL make to the SQL engine, are the same (driver) calls made to the SQL engine when using Java and C and the others.
    So why a cursor and loops in PL/SQL? For the same reason you have cursors and loops in all these other SQL client languages. There are the occasion that you need to pull data from the SQL engine into the local language to perform some very funky and complex processing that is not possible using the SQL language.
    The danger is using client cursor loop processing as the norm - always pulling rows into the client language and crunching it there. This is not very performant. And pretty much impossible to scale. Developers in this case views the SQL language as a mere I/O interface for reading and writing rows. As they would use the standard file I/O read() and write() interface calls.
    Nothing could be further from the truth. SQL is a very advance and sophisticated data processing language. And it will always be faster than having to pull rows to a client language and process them there. However, SQL is not Turing complete. It is not the procedural type language that most other languages we use, are. For that reason there are things that we cannot do in SQL. And that should be the only reason for using the client language, like PL/SQL or the others, to perform row crunching using a client cursor loop.

  • How to add cursor and for loop

    PROCEDURE "TEST" is
    bala number;
    ins1 number;
    ins2 number;
    BEGIN
    select sum(bal) into bala from (select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
    where c_int_instruid=c_srm_prncplinsid
    and c_srm_prncplinsid=acp_instruid
    and acp_acntnum!='SG030001'
    group by acp_instruid
    union
    select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
    where c_int_instruid=c_srm_prncplinsid
    and acp_acntnum!='SG030001'
    and acp_instruid=c_srm_prntinsid
    group by acp_instruid)view1;
    dbms_output.put_line(bala);
    select acp_instruid into ins1 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
    where c_int_instruid=c_srm_prncplinsid
    and c_srm_prncplinsid=acp_instruid
    and acp_acntnum='SG030001';
    dbms_output.put_line('principal'||ins1);
    select acp_instruid into ins2 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
    where c_int_instruid=c_srm_prncplinsid
    and acp_acntnum='SG030001'
    and acp_instruid=c_srm_prntinsid;
    dbms_output.put_line('parent'||ins2);
    update cs_acpos_bkp
    set acp_totbal=-bala
    where acp_instruid=ins2
    and acp_acntnum='SG030001';
    END;
    i have written this code,i need to use cursor and for loops to get more than one rows and update also.
    if there are more than 1 rows in cs_strmap_t,then the procedure throws an error stating that it cannot take 2 rows.
    Edited by: 850836 on Apr 7, 2011 11:43 PM

    PROCEDURE "TEST" is
    bala number;
    ins1 number;
    ins2 number;
    CURSOR cur_1 IS
    select sum(bal) bala from (select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
    where c_int_instruid=c_srm_prncplinsid
    and c_srm_prncplinsid=acp_instruid
    and acp_acntnum='SG030001'
    group by acp_instruid
    union
    select sum(acp.acp_totbal) bal,acp_instruid from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
    where c_int_instruid=c_srm_prncplinsid
    and acp_acntnum='SG030001'
    and acp_instruid=c_srm_prntinsid
    group by acp_instruid)view1;
    BEGIN
    select acp_instruid into ins1 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
    where c_int_instruid=c_srm_prncplinsid
    and c_srm_prncplinsid=acp_instruid
    and acp_acntnum='SG030001';
    dbms_output.put_line('principal'||ins1);
    select acp_instruid into ins2 from cs_strmap_t map,cs_instru_strips strip,cs_acpos_bkp acp
    where c_int_instruid=c_srm_prncplinsid
    and acp_acntnum='SG030001'
    and acp_instruid=c_srm_prntinsid;
    dbms_output.put_line('parent'||ins2);
    for var_for in cur_1
    loop
    update cs_acpos_bkp
    set acp_totbal=var_for.bala
    where acp_instruid=ins2
    and acp_acntnum='SG030001'
    and abs(acp_totbal)>abs(bala);
    dbms_output.put_line(bala);
    end loop;
    END;
    i wrote the following procedure,but the balance is not getting updated.
    Getting this errors when there are more than 1 row in cs_strmap_t table
    ORA-01422: exact fetch returns more than requested number of rows
    ORA-06512: line 22
    ORA-06512: at line 2

  • How to optimize the select query that is executed in a cursor for loop?

    Hi Friends,
    I have executed the code below and clocked the times for every line of the code using DBMS_PROFILER.
    CREATE OR REPLACE PROCEDURE TEST
    AS
       p_file_id              NUMBER                                   := 151;
       v_shipper_ind          ah_item.shipper_ind%TYPE;
       v_sales_reserve_ind    ah_item.special_sales_reserve_ind%TYPE;
       v_location_indicator   ah_item.exe_location_ind%TYPE;
       CURSOR activity_c
       IS
          SELECT *
            FROM ah_activity_internal
           WHERE status_id = 30
             AND file_id = p_file_id;
    BEGIN
       DBMS_PROFILER.start_profiler ('TEST');
       FOR rec IN activity_c
       LOOP
          SELECT DISTINCT shipper_ind, special_sales_reserve_ind, exe_location_ind
                     INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
                     FROM ah_item --464000 rows in this table
                    WHERE item_id_edw IN (
                             SELECT item_id_edw
                               FROM ah_item_xref --700000 rows in this table
                              WHERE item_code_cust = rec.item_code_cust
                                AND facility_num IN (
                                       SELECT facility_code
                                         FROM ah_chain_div_facility --17 rows in this table
                                        WHERE chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
                                          AND div_id = (SELECT div_id
                                                          FROM ah_div --8 rows in this table
                                                         WHERE division = rec.division)));
       END LOOP;
       DBMS_PROFILER.stop_profiler;
    EXCEPTION
       WHEN NO_DATA_FOUND
       THEN
          NULL;
       WHEN TOO_MANY_ROWS
       THEN
          NULL;
    END TEST;The SELECT query inside the cursor FOR LOOP took 773 seconds.
    I have tried using BULK COLLECT instead of cursor for loop but it did not help.
    When I took out the select query separately and executed with a sample value then it gave the results in a flash of second.
    All the tables have primary key indexes.
    Any ideas what can be done to make this code perform better?
    Thanks,
    Raj.

    As suggested I'd try merging the queries into a single SQL. You could also rewrite your IN clauses as JOINs and see if that helps, e.g.
    SELECT DISTINCT ai.shipper_ind, ai.special_sales_reserve_ind, ai.exe_location_ind
               INTO v_shipper_ind, v_sales_reserve_ind, v_location_indicator
               FROM ah_item ai, ah_item_xref aix, ah_chain_div_facility acdf, ah_div ad
              WHERE ai.item_id_edw = aix.item_id_edw
                AND aix.item_code_cust = rec.item_code_cust
                AND aix.facility_num = acdf.facility_code
                AND acdf.chain_id = ah_internal_data_pkg.get_chain_id (p_file_id)
                AND acdf.div_id = ad.div_id
                AND ad.division = rec.division;ALSO: You are calling ah_internal_data_pkg.get_chain_id (p_file_id) every time. Why not do it outside the loop and just use a variable in the inner query? That will prevent context switching and improve speed.
    Edited by: Dave Hemming on Dec 3, 2008 9:34 AM

  • Hp Pavilion 23 Blank Screen With Mouse Cursor After Hp Logo (Not Windows Logo)

    Hello my computer wont start up all i get is a black screen but i have a mouse cursor. after a little bit the computer will restart and do a automatic repair but nothing happens it just keeps on rebooting. i tired to do a bio update but it seems to not be working. there is no option in the bios to update or even in UEFI. i also did a harddrive test and got a Short DST Check fail (FAILURE ID: 909HVX-0007K0-WPU2XF-60WH03) but i still can get access to the harddrive using a Linux LiveUSB and all files are there. (Product Number Is : H5P60AAR#ABA)

    It is possible to receive a false DST check but not common.
    It doesn't mean your hard has failed but that it is in imminent danger of failing.
    You can try again but this time using the Extended DST test.
    But before doing anything I suggest you back up all your important data using that live Linux boot disk just in case.
    Every hard disk manufacturer has their own diagnostic boot cd/usb. Google it.
    You should create one and run it for your brand hard drive.
    You should be able to determine which brand you have from the BIOS/UEFI hardware tab.
    While your'e in there double check that your boot priority is set to hard drive first.
    Your other issue seems to be the dreaded 'Automatic Repair Loop' which could be caused by your possibly failing hard dirve. I would fully diagnose the hard drive first.
    Here's a link with several suggested fixes. Some of them require a Windows 8 boot disk, other do not.
    Automatic Repair Loop Fixes
    If you found my answer helpful please say thanks by clicking on the Thumb's Up icon. Thanks!

Maybe you are looking for

  • Decimal format time value to convert into time (hr:min:sec)value in a graph

    I need to develop a graph in WAD, in BW7. In the graph the value must be showed as HR:MIN:SEC, which I cannot get it right. The keyfigure value  carries the duration(hr:min:sec) in decimal format.  In the query, I use this keyfigure for calculation.

  • Re: Write - Up Unplanned Depreciation

    Hi All, I tried to write up the Unplanned Depreciation using Transaction Code.ABZU Am getting an Error : You Cannot Post Write- ups You cannot post write-ups Message no. AA402 Diagnosis None of the areas to be posted in accordance with the transactio

  • Select the multiple nodes in a tree

    Hi Experts, We need to select the multiple nodes in a tree.Whatever we are selecting,that has to be added in the table as a tree structure itself. For ex: A |--A1     |--B1 If We select the A then A,A1 and B1 has to be added in a table.Please help me

  • Display webpage in xcode osx

    Hi, i recently posted a questions asking how to display a webpage with Webview in xcode ( not for iphone ) i got some answers and they diddnt help me at all :/ This is what im wondering about: I have been searching the web for day and night without s

  • Bug in latest drivers

    Some time ago (somewhere in 2008 I thought it was a good idea to update my drivers to the latest update (was using the drivers from the cd before that, because I don't get all the software otherwise) After I done the update, it completelly screwed so