For loop for cursor

Hello
I have a table used as follows
SQL> desc employees
 Name                                      Null?    Type
 ----------------------------------------- -------- ---------------------

 EMPLOYEE_ID                               NOT NULL NUMBER(6)
 FIRST_NAME                                         VARCHAR2(20)
 LAST_NAME                                 NOT NULL VARCHAR2(25)
 EMAIL                                     NOT NULL VARCHAR2(25)
 PHONE_NUMBER                                       VARCHAR2(20)
 HIRE_DATE                                 NOT NULL DATE
 JOB_ID                                    NOT NULL VARCHAR2(10)
 SALARY                                             NUMBER(8,2)
 COMMISSION_PCT                                     NUMBER(2,2)
 MANAGER_ID                                         NUMBER(6)
 DEPARTMENT_ID                                      NUMBER(4)
I want to make a slider that retrieves the last_name, salary, and the Manager id
It's the employees who work in a specified service I will enter id
a value of substitution (&).
for 4 departments of loop for.
I tried this code but it does not give me the required result
SQL>  declare
  2     v_deptno  number :=&dept_id ;
  3      last varchar2(20);
  4    sal number;
  5     manager number;
  6     cursor c_emp_cursor is select last_name,salary ,manager_id from employee
s
  7     where department_id = &v_deptno;
  8    begin
  9     open  c_emp_cursor;
 10     for i  in 1..5  loop
 11     Fetch  c_emp_cursor into last,sal,manager   ;
 12     dbms_output.put_line(last||'            '||sal||'         '||manager);
 13     end loop;
 14
 15     end;
 16     /
Enter value for dept_id: 10
old   2:    v_deptno  number :=&dept_id ;
new   2:    v_deptno  number :=10 ;
Enter value for v_deptno: 20
old   7:    where department_id = &v_deptno;
new   7:    where department_id = 20;
Hartstein            13000         100
Fay            6000         201
Fay            6000         201
Fay            6000         201
Fay            6000         201

PL/SQL procedure successfully completed.

Hello

VDH says:
... The code well work OK, but not exactly as I want.
I want, for example, data from five departments. (not only a Department).

It's not what you said in your first post:

VDH says:
... I want to make a slider that retrieves the last_name, salary, and the Manager id
It's the employees who work in a specified service I will enter id
by a value (&) substitution.

You want 1 Department or 5 departments?
If you use a substritution variable (let's call it department_list), you can enter a list of departments, separated by commas (but), for example

10,40,70,20,110

and use it in a condition like

WHERE   department_id IN (&department_list)

This works if the list has 1 point, 5 (or any other number). The user can decide how to enter the runtime.

Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements).
Also post the results you want from these data (in this case, the output you want from put_line), as well as an explanation of how you get these results from these data, with specific examples.
If your problem is with the parameters (such as the intervention of the user) put a couple of different sets of parameters and the results you want the same data for each set of parameters.
If you use a commonly available table (suhc as hr.employees), then you need not to display sample data, just the results and explanations.
Always tell what version of Oracle you are using.

Tags: Database

Similar Questions

  • Any built-in support for cursors on the graph and trend curves

    Hello

    I went through the documentation to verify that no support exists to draw trend lines and using the slider on the axis (bargraph) but could not find anything related to it. Can you please confirm if there is any built-in support for cursors/trend lines in the component ojchart (bar graph) of the current version of JET.

    Thank you

    Subhash

    Hi Adoni,

    Due to the large number of possible algorithms, we do not provide built in calculation for trend lines. Our goal is rather to ensure that the user can display trend lines what they calculated, with the right amount of interactivity support. We have a very basic demo of this feature in the Cookbook: Oracle JET - graphics - Custom graphics: trendline. In this demonstration, we recommend using reference objects, rather than additional series, because the objects of reference do not allow a user to interact with the individual points or use features such as selection or drilling, which would be undesirable for a trend line.

    On the second question, could you give more details on this cursor you are referring? We have two ways to use our zoom and scroll feature:

    Thank you

    Hugh

  • only the update by removing for cursor loop

    Hello

    I have the cursor for loop below update a flag. Need to convert the single update by removing the loop.

    po_date po_number BLACK flag

    123 123 - 1 12 December 2015

    123 123 - 2 December 15, 2015

    123 123 - 3 December 21, 2016

    Result

    =====

    po_date po_number BLACK flag

    123 123 - 1 12 December 2015 MUL

    123 123 - 2 15 December 2015 MUL

    123 123 - 3 December 21, 2016

    So, if there are several BLACK for a PO_number, then Mark flag = "MUL" for the two records which are min as the max po_date.

    I'm in select * from alm_po_quotes

    loop

    Update alm_po_quotes

    flag of the value = 'MUL '.

    where po_number = i.po_number

    and

    po_date < (select MAX (po_date) in the alm_po_quotes where po_number = i.po_number);

    end of loop

    Commit

    Please notify.

    Thank you

    In your update, simply add the clause as below

    -Statement to merge

    MERGE INTO alm_po_quotes apq

    USING (SELECT MAX (po_date), mxpo_date,

    APQ.po_number

    Of alm_po_quotes apq

    GROUP BY apq.po_number

    After HAVING COUNT (DISTINCT apq.crno) > 1

    ) q1

    WE (apq.po_number = q1.po_number

    AND apq.po_date<>

    WHEN MATCHED THEN

    UPDATE SET apq.flag = 'MUL '.

    ;

    -Update statement

    UPDATE alm_po_quotes apq SET apq.flag = 'MUL '.

    WHERE apq.po_date< (select="" max(po_date)="">

    Of alm_po_quotes apq1

    WHERE apq.po_number = apq1.po_number

    GROUP BY apq1.po_number

    After HAVING COUNT (DISTINCT apq1.crno) > 1

    );

    OUTPUT:-

    =======

    PO_NUMBER CRNO PO_DATE FLAG
    123 123 1 12/12/2015 MUL
    123 123 2 15/12/2015 MUL
    123 123 3 21/12/2016 -
  • for loops with cursor

    Hello Experts,

    I'm a beginner in PLSQL. I use the oracle 11g on windows machine 7.

    I wrote a simple code that gives me an output.

    DECLARE
    v_dealer_name southern_orders.dealer_name%type;
    v_total_order southern_orders.total_order%type;
    cursor southern_cursor IS
    SELECT distinct (dealer_name), sum (total_order) OF THE group southern_orders by dealer_name;
    BEGIN
    OPEN southern_cursor.
    IF this is is southern_cursor % ISOPEN THEN OPEN southern_cursor;
    END IF;
    BECAUSE me in 1... LOOP 38
    EXTRACT the southern_cursor in v_dealer_name v_total_order;
    EXIT WHEN southern_cursor % NOTFOUND or southern_cursor % ROWCOUNT > 37.
    dbms_output.put_line (' the dealer is: ' | v_dealer_name |) "and their order is:' | '. v_total_order);
    END loop;
    close southern_cursor;
    end;

    the result is:

    the dealer is: has and their order is: 1000
    the dealer is: B and the order is: 2000
    the dealer is: c and the order is: 3000


    In the code above, I calculated the total number of lines, and then wrote the code. Instead, I would use the sql loop to the code.your above help is appreciated.
    DECLARE
        v_dealer_name southern_orders.dealer_name%type;
        v_total_order southern_orders.total_order%type;
        cursor southern_cursor
          IS
            SELECT  dealer_name,
                    sum(total_order) total_order
              FROM  southern_orders
              group by dealer_name;
    BEGIN
        FOR v_rec in southern_cursor LOOP
          dbms_output.put_line('the dealer is : ' || v_rec.dealer_name || ' and their order is :' || v_rectotal_order);
        END loop;
    end;
    /
    

    SY.

  • for cursor loop

    Hi all!

    IAM using the coding according to the button click on the trigger of my block...
    declare
    
    cursor c1 is
    select employeeid 
    from empmgt.emp_reporting
    where reporting_officer = :purchase_login.username;
    
    begin
    
    first_record;
    
    for c1rec in (select employeeid 
    from empmgt.emp_reporting
    where reporting_officer = :purchase_login.username)
     loop
    :purchase_indent1.employee_id := c1rec.employeeid;
     
    if :purchase_indent1.employee_id=c1rec.employeeid  then
    
    select employee_id,employee_name,designation,division_section,
    indent_no,apply_date,project_no,detailed_spec,quantity,
    estimated_cost,total,proprietor,proprietor_name,distributor,deadline_delivery,required_date,
    install_availability,available_vendors,pl_approval
    into 
     :purchase_indent1.employee_id,:purchase_indent1.employee_name,:purchase_indent1.designation,
     :purchase_indent1.division_section,:purchase_indent1.indent_no,:purchase_indent1.apply_date,
     :purchase_indent1.project_no,:purchase_indent1.detailed_spec,:purchase_indent1.quantity,
    :purchase_indent1.estimated_cost,:purchase_indent1.total,:purchase_indent1.proprietor,
    :purchase_indent1.proprietor_name,:purchase_indent1.distributor,:purchase_indent1.deadline_delivery,
    :purchase_indent1.required_date,:purchase_indent1.install_availability,:purchase_indent1.available_vendors,:purchase_indent1.pl_approval
    from
    purchase.purchase_indent
    where 
    *employee_id=c1rec.employeeid;*
    end if;
    next_record;
    
    end loop;
    exception when no_data_found then
    :purchase_indent1.employee_id:='';
    message('');     
    end;
    first_record;
    declare
    
    cursor c1 is
    select employeeid 
    from empmgt.emp_reporting
    where reporting_officer = :purchase_login.username;
    
    begin
    
    first_record;
    
    for c1rec in (select employeeid 
    from empmgt.emp_reporting
    where reporting_officer = :purchase_login.username)
     loop
    :purchase_indent1.employee_id := c1rec.employeeid;
     
    if :purchase_indent1.employee_id=c1rec.employeeid  then
    
    select employee_id,employee_name,designation,division_section,
    indent_no,apply_date,project_no,detailed_spec,quantity,
    estimated_cost,total,proprietor,proprietor_name,distributor,deadline_delivery,required_date,
    install_availability,available_vendors,pl_approval
    into 
     :purchase_indent1.employee_id,:purchase_indent1.employee_name,:purchase_indent1.designation,
     :purchase_indent1.division_section,:purchase_indent1.indent_no,:purchase_indent1.apply_date,
     :purchase_indent1.project_no,:purchase_indent1.detailed_spec,:purchase_indent1.quantity,
    :purchase_indent1.estimated_cost,:purchase_indent1.total,:purchase_indent1.proprietor,
    :purchase_indent1.proprietor_name,:purchase_indent1.distributor,:purchase_indent1.deadline_delivery,
    :purchase_indent1.required_date,:purchase_indent1.install_availability,:purchase_indent1.available_vendors,:purchase_indent1.pl_approval
    from
    purchase.purchase_indent
    where 
    *pl_approval!='Approved';*
    
    end if;
    next_record;
    
    end loop;
    exception when no_data_found then
    :purchase_indent1.employee_id:='';
    message('');     
    end;
    first_record;
    Now the first code works well separately... The second code does not work now... It shows the error
    ora-01422 TOO MANY ROWS
    So do you mean I should go nested cursors? or is there another solution?

    pls help to solve this problem!

    Thanks and greetings
    user 10685325

    Published by: user10685325 on May 11, 2009 01:03

    I think I understand your problem.

    Rownum is an option, but not the solution as an assistant said.

    See, the first query works well because you have expicitly mentioned in where clause here the condition:

    employee_id = c1rec. EmployeeID;

    so, it will return you a rank only, but in the second query, you gave pl_approval! = 'Approved'; who certainly will return multiple lines like pl_approval me, this is a pretty generic column.

    In my opinion you need to change your code something like this:

            select employeeid into :purchase_indent1.employee_id
            from empmgt.emp_reporting
            where reporting_officer = :purchase_login.username);
    
            if :purchase_indent1.employee_id  is not null then --or you can check something else for validity
    
               For c1 in (
                                select employee_id,employee_name,designation,division_section,
                                          indent_no,apply_date,project_no,detailed_spec,quantity,
                                          estimated_cost,total,proprietor,proprietor_name,distributor,deadline_delivery,required_date,
                                          install_availability,available_vendors,pl_approval
                                     from
                                     purchase.purchase_indent
                                     where
                                     *pl_approval!='Approved'* )
    
                       loop
                                     :purchase_indent1.employee_id := c1.employee_id;
                                      :purchase_indent1.employee_name  := C1.employee_name;
                                     Similarly copy all the data block items from the cursor variable
    
                                     next_record;
                        end loop;
                 end if;
    
    exception when no_data_found then
    :purchase_indent1.employee_id:='';
    message('');
    end;
    first_record;
    

    You can change this code a bit according to your need, but I think that's what you want rather than what you wrote.

    It may be useful

    Please try it once and let me know if it works...

    Check the answer as useful / OK, if this can help you

    Carole

    Published by: Carole Punj on May 11, 2009 03:19

  • Need help for cursors in pl/sql

    Hello

    bad posted... If I have any clarification I can post at all.

    Thank you...

    It's how formatted code looks like.

    I removed the superfluous BEGIN... END (which lead to the code that will not compile)

    It's your code, not mine

    DECLARE
      CURSOR stagingtablerecords IS
        SELECT *
        FROM   mdat_lseveh_options;
    
      r      mdat_lseveh_options%ROWTYPE;
      svar   NUMBER;
    BEGIN
      FOR r IN stagingtablerecords LOOP
        IF r.heading_sw = 'Y' THEN
          INSERT INTO pref_accessory_category (acc_cat_id,
                                               acc_cat_desc,
                                               last_modified,
                                               model_cd,
                                               model_yr,
                                               interior,
                                               ext_accessory
                                              )
          VALUES      (refcatidseq.NEXTVAL,
                       r.std_equip_txt,
                       SYSDATE,
                       r.model_cd,
                       r.model_year,
                       NULL,
                       NULL
                      );
    
          svar := acc_cat_id; -- Problem here
        ELSIF r.heading_sw = 'N' THEN
          INSERT INTO pref_accessory (acc_id,
                                      acc_desc,
                                      acc_cat_id,
                                      model_cd,
                                      model_yr,
                                      last_modified
                                     )
          VALUES      (refaccidseql.NEXTVAL,
                       r.std_equip_txt,
                       svar,
                       r.model_cd,
                       r.model_year,
                       SYSDATE
                      );
        END IF;
      END LOOP;
    
      COMMIT;
    END;
    /
    

    You have a problem with your intermediate table, since there is no information on what accessories belongs to which categories.

    You seem to have some order, but that order do not exist, except if explicit.

    If the data come from a file and are sorted in there, then you could add a line number or a sequential number or such as you load in the table of the scene.
    This number must be used when reading the table in step to ensure that the rows are processed as

    Y1
    N1
    N1
    N1
    Y2
    N2
    N2

    Right now, you have no control over the picture of the scene

    Edit:

    I would try with something like: (not tested, or anything else - and never tried this with sequences, suspect it may not work)

    INSERT ALL
    WHEN heading_sw = 'Y' THEN
      INTO   pref_accessory_category (acc_cat_id,
                                      acc_cat_desc,
                                      last_modified,
                                      model_cd,
                                      model_yr,
                                      interior,
                                      ext_accessory
                                     )
      VALUES (refcatidseq.NEXTVAL,
              std_equip_txt,
              SYSDATE,
              model_cd,
              model_year,
              NULL,
              NULL
             )
    WHEN heading_sw = 'N' THEN
      INTO   pref_accessory (acc_id,
                             acc_desc,
                             acc_cat_id,
                             model_cd,
                             model_yr,
                             last_modified
                            )
      VALUES (refaccidseql.NEXTVAL,
              r.std_equip_txt,
              refcatidseq.CURRVAL,
              r.model_cd,
              r.model_year,
              SYSDATE
             )
      SELECT   std_equip_txt,
               model_cd,
               model_year
      FROM     stagingtablerecords
      ORDER BY your_new_column;
    

    Concerning
    Peter

  • Tuninng performance for cursor and insert in the procedure

    Hi all

    I need to set the oracle procedure. The procedure is as below.

    CREATE OR REPLACE PROCEDURE XYZ
    AS

    CURSOR ABCD_CUR IS
    SELECT a, b, c and d
    OF ABCD;
    RV_abcd ABCD_CUR % TYPE;

    BEGIN
    OPEN abcd_cur.
    loop
    extract the abcd_cur in rv_abcd;
    out on abcd_cur % NOTFOUND;
    BEGIN
    insert into one
    (
    SEQ_ID,
    A
    )
    VALUES
    (
    A_SEQ. NEXTVAL,
    rv_abcd. A
    );

    Insert into B
    (
    REF_SEQ_ID,
    SEQ_ID,
    B
    )
    VALUES
    (
    A_SEQ. CURVAL,
    B_SEQ. NEXTVAL,
    B
    );

    Insert into C
    (
    REF_SEQ_ID,
    SEQ_ID,
    C,
    D
    )
    values
    (
    A.SEQ. CURVAL,
    C_SEQ. NEXTVAL,
    C,
    D
    );
    EXCEPTION

    END;
    EXCEPTION
    END;


    the cursor query may sing either query or a query to join.

    For a single query, I used advice PARALLELS. but I'm not able to find out which suggests that I can use to join as well as what suspicion that I have to use for the INSERT statement.
    also, in addition to and delete, can what advice we use?

    Your entire code can be narrowed in a single SQL

    insert all
      into a(seq_id, a) values (a_seq.nextval, a)
      into b(REF_SEQ_ID, seq_id, b) values (a_seq.currval, b_seq.nextval, b)
      into c(ref_seq_id, seq_id, c, d) values (a_seq.currval, c_seq.nextval, c, d)
    select a, b, c, d
      from abcd
    
  • Fix for cursors defective tool in PS Elements 7 with Windows 8.1?

    I have Photoshop Elements 7 and have been perfectly happy with it for editing photos/images as a hobby on my old Windows XP and Windows 7 PCs. I have no real need to upgrade to Photoshop elements 12. I just installed Windows on my new Surface Pro 8.1 and now all the cursors tool in PS Elements 7 are broken. Relocation of PS Elements 7 has failed. All tools that use a real picture of a slider appear distorted. What can I do to fix this?

    In general which is caused by the dpi scale system

    (the effect triple slider)

    Go in Panel > appearance and personalization > make text and other items more or less

    Then try to adjust the size to the smallest

    You may need to use I would choose a level of scaling for all my views and use the Custom resize options and choose something like 124 percent, or 149%

  • Change nested JPanels headphones (for cursors)

    H4. Hello everyone,

    The question with my program, is that when trying to change the frame rate of the program on the fly, by changing the time of timer swing using the value of a slider found inside the Panel, nested, there is no change. I'm not sure if it is a problem because of how I implement the listener to change, or if it's because I'm not using nested panels correctly.

    I created this basic program to represent the problem that I have, if you want to ask questions about my actual program, so don't hesitate. The NestedPanels class simply opens the applet, you can ignore this, because I'm sure this isn't the root of my problem. The nest class is then the main JPanel, that contains the nested JPanel.

    Thank you all,
    BoxCat
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.image.BufferedImage;
    
    public class NestedPanels extends JApplet
    {
    
        public static void main(String []args)
        {
            EventQueue.invokeLater(new Runnable() 
                {
                    public void run() 
                    {
    
                        JFrame window = new JFrame();
                        window.setDefaultCloseOperation(3); 
    
                        JApplet applet = new NestedPanels();
                        applet.init();
                        window.getContentPane().add(applet);
                        window.pack();
                        window.setVisible(true);
                    }
                }
            );
        }  
    
        public void init() 
        {   
            JPanel panel = new Nest();
            getContentPane().add(panel);
        }
    
    }
    
    
    //The main panel 
    
    class Nest extends JPanel implements ActionListener
    {
        private static Timer timer;
    
        private static Image buffer;
    
        private int _delay = 0; //used to set timer delay
        private int _initFrameRate = 35; 
        private int _frameRate = 0; //will take value from nested panel's slider to update program fps
    
        //these 3 variables are used in paintComponent to calculate frameRate as verification of program run speed
        private int _displayFrameRate = 0;
        private int _frameCount = 0;
        private long startTime = System.currentTimeMillis();
    
        //the panel's nested panel
        private Nested nestedPanel = new Nested();
    
        public Nest()
        {
            setPreferredSize(new Dimension(700, 700));
            setBounds(0, 0, 700, 700);
            setBackground(Color.BLUE);
            setVisible(true);
            setOpaque(true); 
            setLayout(null);
            add(nestedPanel);
      
            //irrelevant, only the painting buffer
            buffer = new BufferedImage(700, 700, 1); 
    
           //setting the programs initial frame rate
            _delay = 1000 / _initFrameRate;
            timer = new Timer(_delay, this);
            timer.setCoalesce(true);
            timer.start();
        } 
    
        public void paintComponent(Graphics g) 
        {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
    
            //frame rate calculation
            _frameCount++;
            if (System.currentTimeMillis() > startTime + 1000) 
            {
                startTime = System.currentTimeMillis();
                _displayFrameRate = _frameCount;
                _frameCount = 0;
            }
    
            g2 = (Graphics2D)buffer.getGraphics();
    
            //output of the calculated frame rate
            g.setColor(Color.WHITE);
            g.drawString("FPS: " + _displayFrameRate, 100, 100);
            getGraphics().drawImage(buffer, 0, 0, null); 
    
        }
    
        //IMPORTANT - Potential area of failure
        //called before repaint, attempts to set frame rate using the nested panel's slider value
        void updatePanelFPS()
        {
            _frameRate = nestedPanel.sliderValue;
            _delay = 1000 / _frameRate;
            timer.setDelay(_delay); 
        }
    
        public void actionPerformed(ActionEvent e) 
        {
            updatePanelFPS();
            repaint();
        }
    
        //IMPORTANT - Potential area of failure
        //The nested panel class containing the slider
        class Nested extends JPanel implements ChangeListener
        {
    
            //This slider will basically function as a way of altering FPS
            JSlider slider;
            int sliderValue = 0; // initialized at 0 before setting to the altered slider value
    
            public Nested()
            {   
                setBackground(Color.GREEN);
                setVisible(true);
                setOpaque(true);
                setEnabled(true);
                setBounds(200, 200, 200, 200);
    
                slider = new JSlider(JSlider.VERTICAL, 0, 60, 30);
                slider.setMajorTickSpacing(1);
                slider.setMinorTickSpacing(1);
    
                add(slider);
            }
    
            public void stateChanged(ChangeEvent event) 
            { 
                //if the change was the slider value
                if (event.getSource() == slider)
                {
                    //assign the sliderValue 
                    JSlider source = (JSlider)event.getSource();
                    sliderValue = (int)source.getValue();          
                }
    
            }
    
        }
    
    }

    Hello
    I do not see the code for adding a listener on the slider.
    No doubt, because the Nested class implements ChangeListener , you probably want to each instance of this class to be an auditor on its own cursor, then you need to add a line like:

    slider.addChangeListener(this);
    

    See the tutorial on Auditors: http://download.oracle.com/javase/tutorial/uiswing/events/changelistener.html
    + «A change listener is registered on an object...» » +

    J.

  • LOOPS OF CURSOR SQL PROCEDURE

    I create the tables and the following types...


    CREATE TYPE ACTOR_QUOTE_TYPE AS OBJECT)
    Movie_Title CHAR (36),
    NUMBER of the year
    Role CHAR (36),
    City CHAR (255)
    )
    /

    CREATE TABLE AS AQ_NT TYPE OF ACTOR_QUOTE_TYPE
    /

    CREATE TABLE ACTOR_QUOTES)
    ACTORID CHAR (5),
    CITY AQ_NT
    ) NESTED TABLE QUOTE STORE AS ACTOR_QUOTES_NT
    /

    I need to create a...

    A PL/SQL procedure called INIT_ACTOR_QUOTES without parameter which:

    Reads ALL the ACTORIDs the ACTOR table and inserts in the ACTORID attribute for each row in the ACTOR_QUOTES table (tables have the same cardinality) and at the same time inserts the following initial values in the first row of the nested quotes in each row of the table table ACTOR_QUOTES;

    (Movie_Title, year, role, quote) are fixed respectively at (' ', NULL, '',' ')

    Also and at the same time immediately after each use of the INSERT DELETE to delete ALL the lines of the nested table in each line from each ACTORID in ACTOR_QUOTES table.

    I get an error of compilation with the code...

    CREATE OR REPLACE PROCEDURE INIT_ACTOR_QUOTES
    AS
    CURSOR actorID_cursor IS
    SELECT actorID actor;
    BEGIN
    FOR line IN actorID_cursor LOOP
    INSERT INTO ACTOR_QUOTES (ACTORID) VALUES (actorID);
    INSERT INTO actor_Quotes_NT VALUES (", NULL,",");
    DELETE FROM actor_Quotes_NT WHERE ACTORID = actorID;
    END LOOP;
    END INIT_ACTOR_QUOTES;
    /
    CAUTION: Procedure created with compilation errors.






    SQL > show errors;
    Errors in PROCEDURE INIT_ACTOR_QUOTES:

    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    7/1 PL/SQL: statement ignored
    7/44 PL/SQL: ORA-00984: column not allowed here
    8/1 PL/SQL: statement ignored
    8/13 PL/SQL: ORA-22812: cannot refer to the column in the nested table storage table
    9/1 PL/SQL: PL/SQL: statement ignored
    7/9 PL/SQL: ORA-00925: missing IN the key
    9/13 PL/SQL: ORA-22812: cannot refer to the column in the nested table storage table
    SQL >

    Any help would be appreciated

    >
    not my choice just the requirements I have received so much need help if possible
    >
    See Table Collections: examples in the doc of the SQL language reference
    http://docs.Oracle.com/CD/B28359_01/server.111/b28286/statements_10002.htm#i2071643

    It works for me

    CREATE TABLE ACTOR (ACTORID CHAR(5))
    
    CREATE TYPE ACTOR_QUOTE_TYPE AS OBJECT (
    Movie_Title CHAR(36),
    Year NUMBER,
    Role CHAR(36),
    Quote CHAR(255)
    )
    /
    
    CREATE TYPE AQ_NT AS TABLE OF ACTOR_QUOTE_TYPE
    /
    
    CREATE TABLE ACTOR_QUOTES (
    ACTORID CHAR(5),
    QUOTES AQ_NT
    ) NESTED TABLE QUOTES STORE AS ACTOR_QUOTES_NT
    /
    
    CREATE OR REPLACE PROCEDURE INIT_ACTOR_QUOTES
    AS
    v_actorID actor.actorID%TYPE;
    CURSOR actorID_cursor IS
    SELECT actorID FROM Actor;
    BEGIN
    OPEN actorID_cursor;
     LOOP
     FETCH actorID_cursor INTO v_actorID;
     EXIT WHEN actorID_cursor%NOTFOUND;
    INSERT INTO ACTOR_QUOTES (ACTORID, QUOTES) VALUES (v_actorID, AQ_NT(ACTOR_QUOTE_TYPE('', NULL, '', '')));
    --INSERT INTO ACTOR_QUOTES (QUOTES) VALUES (ACTOR_QUOTE_TYPE('', NULL, '', ''));
    DELETE FROM actor_Quotes WHERE ACTORID=v_actorID;
    END LOOP;
    CLOSE actorID_cursor;
    END INIT_ACTOR_QUOTES ;
    
  • Cursors open loop (the cursor as a variable name)

    Hello

    I have a problem:
    In my home, I said 200 sliders.
    Now, I want to open, extract, and close a loop.
    I think of a table containing the names of all of the cursor.

    That's what I have (example maybe stupid but just to explain the problem):

    DECLARE
    v_empno VARCHAR2 (10);
    v_empname VARCHAR2 (10);

    Cursor c1 IS
    SELECT EMPNO '1', 'Adam' EMPNAME
    DOUBLE;
    Cursor c2 IS
    SELECT EMPNO '2', 'John' EMPNAME
    DOUBLE;
    BEGIN
    OPEN c1;
    LOOP
    FETCH c1 INTO v_empname, v_empno;
    OUTPUT WHEN c1% NOTFOUND;
    dbms_output.put_line (v_empno |) » '|| v_empname);
    END LOOP;
    CLOSE c1;

    OPEN c2;
    LOOP
    C2-FETCH INTO v_empname, v_empno;
    OUTPUT WHEN c2% NOTFOUND;
    dbms_output.put_line (v_empno |) » '|| v_empname);
    END LOOP;
    CLOSE C2;
    END;

    And that's what I want to achieve:

    DECLARE
    v_empno VARCHAR2 (10);
    v_empname VARCHAR2 (10);

    TYPE cursors_tab IS TABLE OF varchar (5);
    t_cursors cursors_tab: = cursors_tab ('c1', 'c2');

    Cursor c1 IS
    SELECT EMPNO '1', 'Adam' EMPNAME
    DOUBLE;
    Cursor c2 IS
    SELECT EMPNO '2', 'John' EMPNAME
    DOUBLE;

    BEGIN
    for me in t_cursors.first... loop of t_cursors. Last
    OPEN: t_cursors (i);
    LOOP
    FETCH: t_cursors (i) INTO v_empno, v_empname;
    EXIT WHEN t_cursors (i) % NOTFOUND;
    dbms_output.put_line (v_empno |) » '|| v_empname);
    END LOOP;
    CLOSE: t_cursors (i);
    end loop;
    END;

    Is this possible? I am trying to solve it, but I'm losing hope ;)
    DECLARE
    v_empno VARCHAR2(10);
    v_empname VARCHAR2(10);
    
    TYPE stmt_tab IS TABLE OF VARCHAR(32767);
    t_stmt stmt_tab := stmt_tab(
                                'SELECT ''1'' EMPNO,''Adam'' EMPNAME FROM dual',
                                'SELECT ''2'' EMPNO,''John'' EMPNAME FROM dual'
                               );
    t_cur sys_refcursor;
    BEGIN
    for i in t_stmt.first .. t_stmt.last loop
    OPEN t_cur for t_stmt(i);
    LOOP
    FETCH t_cur INTO v_empno, v_empname;
    EXIT WHEN t_cur%NOTFOUND;
    dbms_output.put_line (v_empno||' '|| v_empname);
    END LOOP;
    CLOSE t_cur;
    end loop;
    END;
    /
    1 Adam
    2 John
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • For loops with the cursor line and indexing

    Hi all

    I have a question about the loops with the cursor, line and indexing.

    How can I scan via a cursor with an iterator?

    I would use an iterator as

    Whole LoopIndex;
    Whole LoopIndex2;

    for LoopIndex at the beginning of the cursor at the end of the cursor
    loop
    line =: cursor [LoopIndex];
    for LoopIndex2 of LoopIndex at the end of the cursor
    etc...
    end loop;

    I need to use an iterator because I need to use a nested for loop.



    OR


    How can I solve the following problem?

    Class name % ofClass average test Score
    1 Niobe 7 8 8.4
    1 alena 4 7 7.5
    1 9 7 8.9 Estia
    1 Lilly 10 8 9.8
    1 Sandra 6 8 8.3
    1 Melanie 8 8 8.1
    Nadia 2 8 3 4.4
    Sayuki 2 9 8 8.4
    Diasy 2 7 8 8.0
    Flower 2 7 8 6.5
    Diana 2 6 8 7.3
    3 Flora 7 8 5.8
    Sukiya 3 4 8 8.4
    Samantha 3 10 8 7.7
    Roxanne 3 7 8 6.9
    Eline 3 8 8 7.4

    I need to
    -By class, I need to recalculate each average people
    -By class, I need to calculate the % of class score (sum averages / people in the class)

    So it can be done in a nested for loop?
    Or do I just step by step?

    Well, based on this information it would be something like...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 1 as Class, 'Niobe' as Nm, 7 as Score, 8 as Tests, 8.4 as Average from dual union all
      2             select 1, 'Alena', 4, 7, 7.5 from dual union all
      3             select 1, 'Estia', 9, 7, 8.9 from dual union all
      4             select 1, 'Lilly', 10, 8, 9.8 from dual union all
      5             select 1, 'Sandra', 6, 8, 8.3 from dual union all
      6             select 1, 'Melanie', 8, 8, 8.1 from dual union all
      7             select 2, 'Nadia', 3, 8, 4.4 from dual union all
      8             select 2, 'Sayuki', 9, 8, 8.4 from dual union all
      9             select 2, 'Diasy', 7, 8, 8.0 from dual union all
     10             select 2, 'Blossom', 7, 8, 6.5 from dual union all
     11             select 2, 'Diana', 6, 8, 7.3 from dual union all
     12             select 3, 'Flora', 7, 8, 5.8 from dual union all
     13             select 3, 'Sukiya', 4, 8, 8.4 from dual union all
     14             select 3, 'Samantha', 10, 8, 7.7 from dual union all
     15             select 3, 'Roxanne', 7, 8, 6.9 from dual union all
     16             select 3, 'Eline', 8, 8, 7.4 from dual)
     17  --
     18  -- END OF TEST DATA
     19  --
     20  select class, nm as "NAME", score, tests, average
     21        ,round(((average*tests)+score)/(tests+1),1) as avg_person
     22        ,round((average / sum(average) over (partition by class))*100,1) as class_average
     23  from t
     24* order by class, nm
    SQL> /
    
         CLASS NAME          SCORE      TESTS    AVERAGE AVG_PERSON CLASS_AVERAGE
    ---------- -------- ---------- ---------- ---------- ---------- -------------
             1 Alena             4          7        7.5        7.1          14.7
             1 Estia             9          7        8.9        8.9          17.5
             1 Lilly            10          8        9.8        9.8          19.2
             1 Melanie           8          8        8.1        8.1          15.9
             1 Niobe             7          8        8.4        8.2          16.5
             1 Sandra            6          8        8.3          8          16.3
             2 Blossom           7          8        6.5        6.6          18.8
             2 Diana             6          8        7.3        7.2          21.1
             2 Diasy             7          8          8        7.9          23.1
             2 Nadia             3          8        4.4        4.2          12.7
             2 Sayuki            9          8        8.4        8.5          24.3
             3 Eline             8          8        7.4        7.5          20.4
             3 Flora             7          8        5.8        5.9            16
             3 Roxanne           7          8        6.9        6.9          19.1
             3 Samantha         10          8        7.7          8          21.3
             3 Sukiya            4          8        8.4        7.9          23.2
    
    16 rows selected.
    
  • declareing cursor for loop inside another cursor for loop

    Hi friends,

    Is it possible declareing cursor loop within another cursor for loop for.

    Please guide for example?

    You can even declare cursor within the cursor loop

    declare
    cursor c1 is select deptno from the Department;
    BEGIN
    for cr1 in c1
    loop
    declare
    cursor c2 is select ename from emp where deptno = cr1.deptno;
    Start
    for cr2 in c2
    loop
    dbms_output.put_line (CR1. DEPTNO | ' ' || CR2.ename);
    end loop;
    end;
    end loop;
    end;

  • Cursor object and cursor for loop back

    I am beginner in Oracle and the serious database of programming in general. Right now I'm studying the sliders. I more or less understand how works when the cursor returns a record, but I can't understand why this does not work when the cursor return object and I use "cursor for loop.

    Here's the test code:

    CREATE or REPLACE TYPE typ_Test () AS OBJECT
    text VARCHAR2 (50)
    );

    CREATE TABLE t_Test to typ_Test;

    INSERT INTO t_Test VALUES (typ_Test('111'));
    INSERT INTO t_Test VALUES (typ_Test('222'));

    -work, simple loop
    DECLARE
    CURSOR cur IS SELECT VALUE (o) FROM t_Test o;
    typ_Test obj;
    BEGIN
    Heart OPEN;
    LOOP
    Fetch cur INTO obj;
    OUTPUT WHEN heart % NOTFOUND;
    dbms_output.put_line (obj. (Text);
    END LOOP;
    CLOSE cur;
    END;



    -doesn't work, cursor for loop
    DECLARE
    CURSOR cur IS SELECT VALUE (o) FROM t_Test o;
    BEGIN
    FOR news of obj IN LOOP
    dbms_output.put_line (obj. (Text);
    END LOOP;
    END;



    Error report:
    ORA-06550: line 5, column 30:
    PLS-00302: 'TEXT' element must be declared.
    ORA-06550: line 5, column 5:
    PL/SQL: Statement ignored
    06550 00000 - "line %s, column % s:\n%s".
    * Cause: Usually a PL/SQL compilation error.


    EDIT:
    In fact I found no examples on the net of its use "cursor for loop" with cursor that returns the object. Only when the record is returned...

    Published by: user10393567 on February 10, 2009 07:38

    user10393567 wrote:
    Now, in the 'loop' example for what looks "obj" is a folder, not an object, and 'x' is attribute of this recording... But the cursor must return an object, not a record... What Miss me?

    In the FOR loop "obj" is a pointer to the cursor/query, not a subject in its own right. It gives you just a reference in the query.

    So with that you are referring to the query, but then you need to refer to the column in the query that you are interested, so why there need a name (in my case I called it 'x'). 'x' is the object, and then you refer to the attribute of this object "text".

    In the first request that you simply select the value directly object in a variable, so no matter what it's called in the query values are returned by the position that is the first column in the query goes into the first variable in the INTO clause. Once you have that then the variable itself contains the object, and you can just refer to the attribute within that.

    Hope that makes sense.

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

    Hi friends,

    I run the code below and clocked at the same time for each line of 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 inside the LOOP FOR cursor query took 773 seconds.
    I tried to use COLLECT in BULK instead of a cursor for loop, but it did not help.
    When I took the select query separately and executed with a value of the sample, and then he gave the results in a Flash of a second.

    All tables have primary key index.
    Any ideas what can be done to make this code more efficient?

    Thank you
    Raj.
    DECLARE
      v_chain_id ah_chain_div_facility.chain_id%TYPE := ah_internal_data_pkg.get_chain_id (p_file_id);
    
      CURSOR cur_loop IS
      SELECT * -- better off explicitly specifying columns
      FROM ah_activity_internal aai,
      (SELECT DISTINCT aix.item_code_cust, ad.division, 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.facility_num = acdf.facility_code
          AND acdf.chain_id = v_chain_id
          AND acdf.div_id = ad.div_id) d
      WHERE aai.status_id = 30
        AND aai.file_id = p_file_id
        AND d.item_code_cust = aai.item_code_cust
        AND d.division = aai.division;         
    
    BEGIN
      FOR rec IN cur_loop LOOP
        ... DO your stuff ...
      END LOOP;
    END;  
    

    Published by: Dave hemming on December 4, 2008 09:17

Maybe you are looking for

  • MacBook Pro 2015 system crash

    Hello my Macbook Pro 13 2015 "with screen Retina, that had been built less than a year ago keeps freezing completely. All this so far and I have reinstalled El Capitan for a second time but that has not worked. The trackpad works as well and there is

  • How to secure the wiring of digital output BNC-2090

    Hi, I'm working on using the digital output of data acquisition to control the digital DAC input, but I have a problem on how to fix the wiring for the digital output of the DAC. When I plug the cable into the hole, it is vaguely related. Any suggest

  • Why Windows Live Mail does not close my msn email?

    I have been using for years msn mail. Recently, when I go on the site, I get the following message. Internet Explorer has shut down the Web page. The message said that an add-on has been close. He ordered me to try to go back to windows live or retur

  • Pavilion 15-E078EA: spare parts

    I have a 15-e078ea Pavilion, product = E9J38EA #ABU [personal information] Model United Kingdom I need a new cover of base, but cannot find the part number or replacement parts Can someone advise me on parts, order and fresh numbers please Thank you

  • CD-ROM/DVD-Rom drive not detected

    I have a Toshiba Satellite l300d with an OS Vista Home premium. It worked fine for 3 years, but last week, I can't find the cd drive in 'my computer' and am unable to read DVDs, games, etc. The Toshiba MK1652GSK ATA device appears in Device Manager a