Multiple cursors and xmlforest

This is my first time working with XML in PLSQL. I'm trying to parse values from a plsql procedure into a Word document using XML.
My procedure looks something like:
CREATE OR REPLACE PROCEDURE GET_XML_FA
(PP_ID IN VARCHAR2,
PP_PERIOD IN VARCHAR2
IS
result CLOB;
result1 clob;
CURSOR my_cur_1 IS
   SELECT XMLForest(to_char(sysdate,'fmMonth DD, YYYY') "sysdate",
                    INITCAP(TRIM(p.p_name))||' ('||p.p_id||')' "person",
                    p_period "period",
                    (SELECT DISTINCT INITCAP(TO_CHAR(det.detail_date,'fmMonth DD,YYYY'))
                     FROM details_table det, abc_table abc, people p
                     WHERE det.fa_seq_num = abc.fa_seq_num
                     AND p.p_seq_num = abc.p_seq_num
                     AND p.p_id LIKE pp_id
                     AND REPLACE((TO_CHAR(abc.from_period,'fmMonth YYYY'))||'-'||INITCAP(TO_CHAR(abc.thru_period,'fmMonth YYYY')),' ','') LIKE pp_period
                     AND det.dtl_code = 'bill'
                     ) "bill_date"            
                    ) xrow
FROM PEOPLE p
WHERE p.p_id = PP_ID;
CURSOR my_cur_2 IS 
                    select XMLForest
                    (Initcap(to_char(det.detail_date,'fmMonth DD,YYYY')) "payment_date",
                     det.detail_amt "payment_amt") xrow
                    from details_table det, abc_table abc, people p
                    where det.fa_seq_num = abc.fa_seq_num
                    and p.p_seq_num = abc.p_seq_num
                    and p.p_id = pp_id
                    AND replace((TO_CHAR(abc.from_period,'fmMonth YYYY'))||'-'||INITCAP(TO_CHAR(abc.thru_period,'fmMonth YYYY')),' ','') like pp_period
                    and det.dtl_code = 'payment';
BEGIN
htp.print('<?xml version="1.0" ?>');
htp.print('<DOCUMENT DOCNAME="My_Letter'||pp_id||'_'||pp_period||'.doc" DESTINATION="'||get_const_value('FA_TRACK_DIR')||'" SOURCE="'||get_const_value('DOCBUILDER_DIR')||'" LOGFILE="'||get_const_value('FA_TRACK_DIR')||'">');
htp.print('<NOTE FNAME="My_Letter.doc">');
  for my_rec_1 in my_cur_1 loop
  result := my_rec_1.xrow.getClobVal();
   htp.print(result);
  end loop;
  for my_rec_2 in my_cur_2 loop
  result1 := my_rec_2.xrow.getClobVal();
  htp.print(result1);
  end loop;
  htp.print('</NOTE>');
  htp.print('</DOCUMENT>');
END;my_cur_1 returns a single row of data whereas my_cur_2 returns multiple rows. However, while parsing values into my word document, my_cur_2 passes only the first row and doesn't pass the remaining rows.
I'm not able to understand what I am doing wrong. Can anyone help?
Note: get_const_value is our custom function that determines directory path based on server.
Let me know if more details are required.

Hi Scorpio,
my point was very simple. XMLAgg function pre-aggregates the result elements in one row. See example below with simulated dual data.
select XMLForest
(rownum "payment_date", 'a' "payment_amt" ) xrow
from dual connect by level <= 2
XROW
<payment_date>1</payment_date><payment_amt>a</payment_amt>
<payment_date>2</payment_date><payment_amt>a</payment_amt>
2 rows selected
select XMLAgg(XMLForest
(rownum "payment_date", 'a' "payment_amt" )) xrow
from dual connect by level <= 2
XROW
<payment_date>1</payment_date><payment_amt>a</payment_amt><payment_date>2</payment_date><payment_amt>a</payment_amt>
1 rows selected
If this doesn't help I'd suggest - simplify the example (consider only the cursor causing problem, use the dual table etc) and post the Oracle version.
Regards,
Jaromir

Similar Messages

  • 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.

  • Cursor and Update rows based on value/date

    SQL Server 2012
    Microsoft SQL Server Management Studio
    11.0.3128.0
    Microsoft Analysis Services Client Tools
    11.0.3128.0
    Microsoft Data Access Components (MDAC)
    6.1.7601.17514
    Microsoft MSXML 3.0 4.0 5.0 6.0 
    Microsoft Internet Explorer
    9.11.9600.16518
    Microsoft .NET Framework
    4.0.30319.18408
    Operating System
    6.1.7601
    The objective of this is to test the Cursor and use it on a production environment after this is fixed. What I would like to do is update rows in a column i duplicated originally called 'HiredDate' from AdventureWorks2012 HumanResources.Employee table. I
    made a duplicate column called 'DateToChange' and would like to change it based on a date I have picked, which returns normally 2 results (i.e. date is '04/07/2003'). The code runs but will not change both dates. It did run however with an error but changed
    only 1 of the 2 rows because it said ['nothing available in next fetch'].
    The code to add the columns and perform the query to get the results I am running this against:
    -- ADD column 'DateToChange'
    ALTER TABLE [HumanResources].[Employee] ADD DateToChange Date NOT NULL;
    -- Copy 'HireDate' data to 'DateToChange'
    UPDATE HumanResources.Employee SET DateToChange = HireDate;
    -- Change 'DateToChange' to NOT NULL
    ALTER TABLE [HumanResources].[Employee] ALTER COLUMN DateToChange Date NOT NULL;
    SELECT BusinessEntityID,HireDate, CONVERT( char(10),[DateToChange],101) AS [Formatted Hire Date]
    FROM HumanResources.Employee
    WHERE [DateToChange] = '04/07/2003';
    Code:
    USE AdventureWorks2012;
    GO
    -- Holds output of the CURSOR
    DECLARE @EmployeeID INT
    DECLARE @HiredDate DATETIME
    DECLARE @HiredModified DATETIME
    DECLARE @ChangeDateTo DATETIME
    --Declare cursor
    -- SCROLL CURSOR ALLOWS "for extra options" to pul multiple records: i.e. PRIOR, ABSOLUTE ##, RELATIVE ##
    DECLARE TestCursor CURSOR SCROLL FOR
    -- SELECT statement of what records going to be used by CURSOR
    -- Assign the query to the cursor.
    SELECT /*HumanResources.Employee.BusinessEntityID, HumanResources.Employee.HireDate,*/ CONVERT( char(10),[DateToChange],101) AS [Formatted Hire Date]
    FROM HumanResources.Employee
    WHERE DateToChange = '01/01/1901'
    /*ORDER BY HireDate DESC*/ FOR UPDATE OF [DateToChange];
    -- Initiate CURSOR and load records
    OPEN TestCursor
    -- Get first row from query
    FETCH NEXT FROM TestCursor
    INTO @HiredModified
    -- Logic to tell the Cursor while "@@FETCH_STATUS" 0 the cursor has successfully fetched the next record.
    WHILE (@@FETCH_STATUS = 0 AND @@CURSOR_ROWS = -1)
    BEGIN
    FETCH NEXT FROM TestCursor
    IF (@HiredModified = '04/07/2003')/*05/18/2006*/
    -- Sets @HiredModifiedDate data to use for the change
    SELECT @ChangeDateTo = '01/01/1901'
    UPDATE HumanResources.Employee
    SET [DateToChange] = @ChangeDateTo --'01/01/1901'
    FROM HumanResources.Employee
    WHERE CURRENT OF TestCursor;
    END
    -- CLOSE CURSOR
    CLOSE TestCursor;
    -- Remove any references held by cursor
    DEALLOCATE TestCursor;
    GO
    This query is run successfully but it does not produce the desired results to change the dates
    04/07/2003 to 01/01/1901.
    I would like the query to essentially be able to run the initial select statement, and then update and iterate through the returned results while replacing the necessary column in each row.
    I am also open to changes or a different design all together. 
    For this query I need:
    1. To narrow the initial set of information
    2. Check if the information returned, in particular a date, is before [i.e. this current month minus 12 months or
    12 months before current month]
    3. Next replace the dates with the needed date
    [Haven't written this out yet but it will need to be done]
    4. After all this is done I will then need to update a column on each row:
    if the 'date' is within 12 months to 12 months from the date checked
    NOTE: I am new to TSQL and have only been doing this for a few days, but I will understand or read up on what is explained if given enough information. Thank you in advance for anyone who may be able to help.

    The first thing you need to do is forget about cursors.  Those are rarely needed.  Instead you need to learn the basics of the tsql language and how to work with data in sets.  For starters, your looping logic is incorrect.  You open
    the cursur and immediately fetch the first row.  You enter the loop and the first thing in the loop does what?  Fetches another row.  That means you have "lost" the values from the first row fetched.  You also do not test the success of
    that fetch but immediately try to use the fetched value.  In addition, your cursor includes the condition "DateToChange = '01/01/1901' " - by extension you only select rows where HireDate is Jan 1 1901.  So the value fetched into @HiredModified will
    never be anything different - it will always be Jan 1 1901.  The IF logic inside your loop will always evaluate to FALSE.  
    But forget all that.  In words, tell us what you are trying to do.  It seems that you intend to add a new column to a table - one that is not null (ultimately) and is set to a particular value based on some criteria.  Since you intend the
    column to be not null, it is simpler to just add the column as not null with a default.  Because you are adding the column, the assumption is that you need to set the appropriate value for EVERY row in the table so the actual default value can be anything.
     Given the bogosity of the 1/1/1901 value, why not use this as your default and then set the column based on the Hiredate afterwards.  Simply follow the alter table statement with an update statement.  I don't really understand what your logic
    or goal is, but perhaps that will come with a better description.  In short: 
    alter table xxx add DateToChange date default '19010101'
    update xxx set DateToChange = HireDate where [some unclear condition]
    Lastly, you should consider wrapping everything you do in a transaction so that you recover from any errors.  In a production system, you should consider making a backup immediately before you do anything - strongly consider and have a good reason not
    to do so if that is your choice (and have a recovery plan just in case). 

  • How to add (multiple) cursors programmatically in an XY graph?

     how to add (multiple) cursors programmatically in an XY graph?
    I am building an XY graph. then I would like to add cursors at certain locations (positioned on x axis) I determine through a program.
    How can I add cursors programatically?
    Thank you.

    Initialize a cluster array (CrsrList type) with as many cursors as you think you would ever need.   Setup your cursors dynamically, then delete the unused cursors (array elements) and then update your CursorList property.
    Message Edited by vt92 on 03-20-2009 04:04 PM
    "There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
    Attachments:
    cursors.PNG ‏5 KB

  • [Help] statement.executeQuery(query) opens MULTIPLE cursors

    Hey everyone,
    I'm having a real hard time finding anything about this on the net so I've turned here. When we call:
    resultSet = statement.executeQuery(query)
    from a servlet for some reason that one executeQuery opens anywhere from 9-12 cursors in our oracle DB. All the executeQuery documentation I could find just said it should open 1 cursor for that particular ResultSet. query is a fairly simple SQL statement, it searches multiple tables but that doesn't explain why it should open so many cursors.
    On a side note the resultSet and statement are global to the method and are closed in the finally block, no SQLExceptions are thrown further adding to my confusion.
    If anyone has seen something like this where executing 1 query opens multiple cursors please let me know any information you might have.
    Thanks in advance
    -Dave

    Hi Dave
    I had a similar problem using the Oracle 8i, but my query was a more complicated than yours and opened a lot of cursors.
    The answer is to close every ResultSet and the Statement:
    while (xxResult.next()){ ... }
    xxResult.close();
    xxResult.getStatement().close();
    This worked for me,
    Good luck,
    Daniel.

  • Same EMP NUM in multiple cursors

    My plsql program is designed in such way that there are multiple cursors & each cursor needs input as EMPLOYEE NUMBER.
    This EMPLOYEE NUMBER should be same across all the cursors.
    Code is as below.
    Any kind of help here is appreciated. Thank you in advance.
    -- AGTSP
    SET SERVEROUTPUT ON
    alter session set nls_date_format='YYYY-MM-DD';
    DECLARE
        MY_FILE_DIR varchar2(40) := '/usr/tmp2';
        l_output        utl_file.file_type;
        v_file_handle varchar2(30) default 'Legacy_Job_Data.csv';
        buf varchar2(10230);
        v_ps_id varchar2(10);
        v_job_descr varchar2(40);
      v_belonging_name VARCHAR2(100);
      v_sg VARCHAR2(4);
      v_sg_jc VARCHAR2(6);
      v_EFFECTIVE_START_DATE DATE;
      SG VARCHAR2(10);
      v_count number;
    -- CJL DATA COLLECTION STARTS
    -- CURSOR STARTS
        CURSOR C_MAIN IS        
      select
                        EMP.EMPLOYEE_NUMBER AS EMPLOYEE_NUMBER
      , JOB.BELONGING_NAME
      , JOB.CHANGE_REASON_NAME
      , JOB.EFFECTIVE_START_DATE
      , JOB.EFFECTIVE_END_DATE
                    from
                        apps.zshr_employee_v EMP
                        , apps.ZSHR_ASSIGNMENT_V JOB
                    where
                        EMP.EMPLOYEE_NUMBER = JOB.EMPLOYEE_NUMBER
                    and TO_CHAR( EMP.EFFECTIVE_END_DATE , 'YYYY-MM-DD')='4712-12-31'                and JOB.QUALIFICATION_CODE <>'0151'
      ORDER BY EFFECTIVE_START_DATE DESC
    CURSOR C_SCM IS        
      SELECT
                        EMP.EMPLOYEE_NUMBER AS EMPLOYEE_NUMBER
      , JOB.BELONGING_NAME
      , JOB.CHANGE_REASON_NAME
      , JOB.EFFECTIVE_START_DATE
      , JOB.EFFECTIVE_END_DATE
                    from
                        apps.zshr_employee_v EMP
                        , apps.ZSHR_ASSIGNMENT_V JOB
                    where
                        EMP.EMPLOYEE_NUMBER = JOB.EMPLOYEE_NUMBER
                   and TO_CHAR( EMP.EFFECTIVE_END_DATE , 'YYYY-MM-DD') ='4712-12-31' and TO_CHAR( JOB.EFFECTIVE_END_DATE , 'YYYY-MM-DD') <'2008-08-01'
      and TO_CHAR( JOB.EFFECTIVE_START_DATE , 'YYYY-MM-DD') >= '1987-07-01'
      and JOB.QUALIFICATION_CODE <>'0151'
      and rownum=1
      ORDER BY EFFECTIVE_START_DATE ASC
    CURSOR C_CM IS        
      SELECT
                        EMP.EMPLOYEE_NUMBER AS EMPLOYEE_NUMBER
      , JOB.BELONGING_NAME
      , JOB.CHANGE_REASON_NAME
      , JOB.EFFECTIVE_START_DATE
      , JOB.EFFECTIVE_END_DATE
            from
                        apps.zshr_employee_v EMP
                        , apps.ZSHR_ASSIGNMENT_V JOB
                    where
                        EMP.EMPLOYEE_NUMBER = JOB.EMPLOYEE_NUMBER
                   and TO_CHAR( EMP.EFFECTIVE_END_DATE , 'YYYY-MM-DD') ='4712-12-31' and TO_CHAR( JOB.EFFECTIVE_START_DATE , 'YYYY-MM-DD') < '1987-07-01'
      and rownum =1
      ORDER BY EFFECTIVE_START_DATE ASC
    -- MAIN BODY BEGINS
    BEGIN
    -- FILE INITIALIZATION
        l_output := utl_file.fopen(MY_FILE_DIR,v_file_handle, 'w', 32767);
    -- WRITING THE FILE HEADER STARTS
        buf := 'EMPLID'
                    || ',EMPL_RCD'
                    || ',EFFDT'
                    || ',EFFSEQ'
                    || ',CX_EE_ID_NBR'
                    || ',CX_SECT_NM'
                    || ',LOCATION'
                    || ',CX_WRK_LOC_DESCR'
                    || ',JOBCODE'
                    || ',JOB_DESCR'
                    || ',GRADE'
                    || ',COMPRATE '
                    || ',CURRENCY_CODE'
                    || ',COMP_FREQUENCY'
        utl_file.put_line(l_output,buf);
    FOR C_EMP_rec in C_MAIN LOOP
    -- CJL LEGACY JOB DATA COLLECTION
    --PS ID EXTRACTION STARTS
      BEGIN
      select PS_ID INTO v_ps_id from apps.TB03569A where
            EBS_ID=C_EMP_rec.EMPLOYEE_NUMBER;
      EXCEPTION
      WHEN no_data_found THEN
      v_ps_id := 'NO DATA';
      END;
    --PS ID EXTRACTION END
      IF  C_EMP_rec.EFFECTIVE_START_DATE >= '2008/8/1' THEN
        buf := v_ps_id                               /* EMPLID */
               || ',' || 0                             /* EMPL_RCD */
               || ',' || C_EMP_rec.EFFECTIVE_START_DATE         /* EFFDT*/
               || ',' || 0                             /* EFFSEQ*/
               || ',' || C_EMP_rec.EMPLOYEE_NUMBER             /* CX_EE_ID_NBR */
                 || ',' || C_EMP_rec.BELONGING_NAME     /* CX_SECT_NM */
                 || ',' || ''                 /* LOCATION */
               || ',' || 'CX_WRK_LOC_DESCR'               /* CX_WRK_LOC_DESCR */
                 || ',' || C_EMP_rec.SG_JOB_CODE /* JOBCODE */
                 || ',' || v_job_descr               /* JOB_DESCR */
                 || ',' || C_EMP_rec.SG         /* GRADE */
               || ',' || ''       /* COMPRATE */
                 || ',' || 'JPY'               /* CURRENCY CODE */
                 || ',' || '' /* COMP FREQUENCY */
                 || ',' || C_EMP_rec.EMP_SG_T_O_FLG           /* SG T Oth. Flag */
      utl_file.put_line(l_output,buf);
      END IF;
    END LOOP;
    FOR C_SCM_rec in C_SCM LOOP
    --PS ID EXTRACTION STARTS
      BEGIN
      select PS_ID INTO v_ps_id from apps.TB03569A where
            EBS_ID=C_SCM_rec.EMPLOYEE_NUMBER;
      EXCEPTION
      WHEN no_data_found THEN
      v_ps_id := 'NO DATA';
      END;
    --PS ID EXTRACTION END
    buf := v_ps_id                               /* EMPLID */
               || ',' || 0                             /* EMPL_RCD */
               || ',' || C_SCM_rec.EFFECTIVE_START_DATE         /* EFFDT*/
               || ',' || 0                             /* EFFSEQ*/
               || ',' || C_SCM_rec.EMPLOYEE_NUMBER             /* CX_EE_ID_NBR */
                 || ',' || C_SCM_rec.BELONGING_NAME     /* CX_SECT_NM */
                 || ',' || ''                 /* LOCATION */
               || ',' || 'CX_WRK_LOC_DESCR'               /* CX_WRK_LOC_DESCR */
                 || ',' || C_SCM_rec.SG_JOB_CODE /* JOBCODE */
                 || ',' || 'v_job_descr'               /* JOB_DESCR */
                 || ',' || C_SCM_rec.SG         /* GRADE */
               || ',' || ''       /* COMPRATE */
                 || ',' || 'JPY'               /* CURRENCY CODE */
                 || ',' || '' /* COMP FREQUENCY */
                 || ',' || C_SCM_rec.EMP_SG_T_O_FLG           /* SG T Oth. Flag */
      utl_file.put_line(l_output,buf);
    -- SCM DATA COLLECTION STARTS
    END LOOP;
    -- SCM DATA COLLECTION ENDS
    FOR C_CM_rec in C_CM LOOP
    --PS ID EXTRACTION STARTS
      BEGIN
      select PS_ID INTO v_ps_id from apps.TB03569A where
            EBS_ID=C_CM_rec.EMPLOYEE_NUMBER;
      EXCEPTION
      WHEN no_data_found THEN
      v_ps_id := 'NO DATA';
      END;
    --PS ID EXTRACTION END
      BEGIN
      select count(*) INTO v_count from
      SELECT 
      distinct
      EMP.EMPLOYEE_NUMBER
      , JOB.ASSIGNMENT_NUMBER
      , JOB.ASSIGNMENT_ID
      from
      apps.zshr_employee_v EMP
      , apps.ZSHR_ASSIGNMENT_V JOB
      where
      EMP.EMPLOYEE_NUMBER=JOB.EMPLOYEE_NUMBER
      and EMP.EMPLOYEE_NUMBER=C_CM_rec.EMPLOYEE_NUMBER
      EXCEPTION
      WHEN no_data_found THEN
      v_count := 0;
      END;
      IF v_count > 1 THEN
      v_job_descr := 'MHI';
      ELSE
      v_job_descr := 'CM';
      END IF;
      buf := v_ps_id                           /* EMPLID */
               || ',' || 0                             /* EMPL_RCD */
               || ',' || C_CM_rec.EFFECTIVE_START_DATE         /* EFFDT*/
               || ',' || 0                             /* EFFSEQ*/
               || ',' || C_CM_rec.EMPLOYEE_NUMBER             /* CX_EE_ID_NBR */
                 || ',' || C_CM_rec.BELONGING_NAME     /* CX_SECT_NM */
                 || ',' || ''                 /* LOCATION */
               || ',' || 'CX_WRK_LOC_DESCR'               /* CX_WRK_LOC_DESCR */
                 || ',' || C_CM_rec.SG_JOB_CODE /* JOBCODE */
                 || ',' || v_job_descr               /* JOB_DESCR */
                 || ',' || C_CM_rec.SG         /* GRADE */
               || ',' || ''       /* COMPRATE */
                 || ',' || 'JPY'               /* CURRENCY CODE */
                 || ',' || '' /* COMP FREQUENCY */
                 || ',' || C_CM_rec.EMP_SG_T_O_FLG           /* SG T Oth. Flag */
      utl_file.put_line(l_output,buf);
    -- SCM DATA COLLECTION STARTS
    END LOOP;
        utl_file.fclose(l_output);
    END;

    Well, I'm not sure what you're issue is as you haven't told us.
    Typically cursors within cursors or multiple cursors are a bad idea, and you should look to try and combine SQL statements into one statement where possible.
    I do however, notice that you've specifying an operating system path for your directory (/usr/tmp2).  You should not use o/s paths with Oracle, you should use Oracle directory objects e.g.
    The UTL_FILE_DIR parameter has been deprecated by oracle in favour of direcory objects because of it's security problems.
    The correct thing to do is to create a directory object e.g.:
    CREATE OR REPLACE DIRECTORY mydir AS 'c:\myfiles';
    Note: This does not create the directory on the file system. You have to do that yourself and ensure that oracle has permission to read/write to that file system directory.
    Then, grant permission to the users who require access e.g....
    GRANT READ,WRITE ON DIRECTORY mydir TO myuser;
    Then use that directory object inside your FOPEN statement e.g.
    fh := UTL_FILE.FOPEN('MYDIR', 'myfile.txt', 'r');
    Note: You MUST specify the directory object name in quotes and in UPPER case for this to work as it is a string that is referring to a database object name which will have been stored in uppercase by default.

  • Multiple Cursors in an OracleResultSet

    Is it possible to iterate over multiple cursors in an OracleResultSet at the same time, or do you have to iterate over a result set (get all the data), then iterate over another resultset (get all the data). See example code 1 and example code 2 below:
    Example Code 1
    =============
    Map output = new HashMap();
              try {
                   // make connection
                   // send JDBC call
                   ResultSet cursor1 = null;
                   while (cursor1.next()) {
                        CartBean chart = new CartBean();
                        cart.setCartName(cursor1.getString("Name"));
                        cart.setCartType(cursor1.getString("Type"));
                        output.put(cart.getCartName(), cart);
                   ResultSet cursor2 = null;
                   while (cursor2.next()) {
                        CartBean chart = (CartBean) output.get(cursor2
                                  .getString("CartName"));
                        Map series = cart.getSeriesData();
                        series.put(cursor2.getString("Label"), new HashMap());
    Example Code 2
    =============
    Map output = new HashMap();
              try {
                   // make connection
                   // send JDBC call
                   ResultSet cursor1 = null;
                   while (cursor1.next()) {
                        CartBean chart = new CartBean();
                        cart.setCartName(cursor1.getString("Name"));
                        cart.setCartType(cursor1.getString("Type"));
                        output.put(cart.getCartName(), cart);
                   ResultSet cursor2 = null;
                   while (cursor2.next()) {
                        Map series = cart.getSeriesData();
                        series.put(cursor2.getString("Label"), new HashMap());
    }

    Hi Nathan,
    I don't full understand your requirements.  It would help if you could give a bit more background information about what you want to achieve.  Assuming you want one row in temp_store_newta for each store, then the following should do it (untested).
    declare
      l_union sdo_geometry;
      l_remainder sdo_geometry;
    begin
      for r1 in (
      select rowid, store_id, client_id, geometry
      from tmcs.tmcs_all_stores_ta
      where client_id = 1
      and rownum < 4)
      loop
      dbms_output.put_line('The primary --> ' || r1.store_id);
      select sdo_aggr_union(sdoaggrtype(geometry, 0.005))
      into l_union
      from tmcs.tmcs_all_stores_ta
      where client_id = 1
      and sdo_anyinteract(geometry, r1.geometry) = 'TRUE'
      and rowid != r1.rowid;
      l_remainder := sdo_geom.sdo_difference(r1.geometry, l_union, 0.005);
      if l_remainder is not null then
       dbms_output.put_line('Inserting the remainder for ' || r1.store_id);
       insert into tmcs.temp_store_newta values (r1.store_id, r1.store_number, r1.client_id, l_remainder);
      else
       dbms_output.put_line('Nothing left after punching out all the other geometries');
      end if;
    end loop r1;
    commit;
    end;
    John

  • Help with if statement in cursor and for loop to get output

    I have the following cursor and and want to use if else statement to get the output. The cursor is working fine. What i need help with is how to use and if else statement to only get the folderrsn that have not been updated in the last 30 days. If you look at the talbe below my select statement is showing folderrs 291631 was updated only 4 days ago and folderrsn 322160 was also updated 4 days ago.
    I do not want these two to appear in my result set. So i need to use if else so that my result only shows all folderrsn that havenot been updated in the last 30 days.
    Here is my cursor:
    /*Cursor for Email procedure. It is working Shows userid and the string
    You need to update these folders*/
    DECLARE
    a_user varchar2(200) := null;
    v_assigneduser varchar2(20);
    v_folderrsn varchar2(200);
    v_emailaddress varchar2(60);
    v_subject varchar2(200);
    Cursor c IS
    SELECT assigneduser, vu.emailaddress, f.folderrsn, trunc(f.indate) AS "IN DATE",
    MAX (trunc(fpa.attemptdate)) AS "LAST UPDATE",
    trunc(sysdate) - MAX (trunc(fpa.attemptdate)) AS "DAYS PAST"
    --MAX (TRUNC (fpa.attemptdate)) - TRUNC (f.indate) AS "NUMBER OF DAYS"
    FROM folder f, folderprocess fp, validuser vu, folderprocessattempt fpa
    WHERE f.foldertype = 'HJ'
    AND f.statuscode NOT IN (20, 40)
    AND f.folderrsn = fp.folderrsn
    AND fp.processrsn = fpa.processrsn
    AND vu.userid = fp.assigneduser
    AND vu.statuscode = 1
    GROUP BY assigneduser, vu.emailaddress, f.folderrsn, f.indate
    ORDER BY fp.assigneduser;
    BEGIN
    FOR c1 IN c LOOP
    IF (c1.assigneduser = v_assigneduser) THEN
    dbms_output.put_line(' ' || c1.folderrsn);
    else
    dbms_output.put(c1.assigneduser ||': ' || 'Overdue Folders:You need to update these folders: Folderrsn: '||c1.folderrsn);
    END IF;
    a_user := c1.assigneduser;
    v_assigneduser := c1.assigneduser;
    v_folderrsn := c1.folderrsn;
    v_emailaddress := c1.emailaddress;
    v_subject := 'Subject: Project for';
    END LOOP;
    END;
    The reason I have included the folowing table is that I want you to see the output from the select statement. that way you can help me do the if statement in the above cursor so that the result will look like this:
    emailaddress
    Subject: 'Project for ' || V_email || 'not updated in the last 30 days'
    v_folderrsn
    v_folderrsn
    etc
    [email protected]......
    Subject: 'Project for: ' Jim...'not updated in the last 30 days'
    284087
    292709
    [email protected].....
    Subject: 'Project for: ' Kim...'not updated in the last 30 days'
    185083
    190121
    190132
    190133
    190159
    190237
    284109
    286647
    294631
    322922
    [email protected]....
    Subject: 'Project for: Joe...'not updated in the last 30 days'
    183332
    183336
    [email protected]......
    Subject: 'Project for: Sam...'not updated in the last 30 days'
    183876
    183877
    183879
    183880
    183881
    183882
    183883
    183884
    183886
    183887
    183888
    This table is to shwo you the select statement output. I want to eliminnate the two days that that are less than 30 days since the last update in the last column.
    Assigneduser....Email.........Folderrsn...........indate.............maxattemptdate...days past since last update
    JIM.........      jim@ aol.com.... 284087.............     9/28/2006.......10/5/2006...........690
    JIM.........      jim@ aol.com.... 292709.............     3/20/2007.......3/28/2007............516
    KIM.........      kim@ aol.com.... 185083.............     8/31/2004.......2/9/2006.............     928
    KIM...........kim@ aol.com.... 190121.............     2/9/2006.........2/9/2006.............928
    KIM...........kim@ aol.com.... 190132.............     2/9/2006.........2/9/2006.............928
    KIM...........kim@ aol.com.... 190133.............     2/9/2006.........2/9/2006.............928
    KIM...........kim@ aol.com.... 190159.............     2/13/2006.......2/14/2006............923
    KIM...........kim@ aol.com.... 190237.............     2/23/2006.......2/23/2006............914
    KIM...........kim@ aol.com.... 284109.............     9/28/2006.......9/28/2006............697
    KIM...........kim@ aol.com.... 286647.............     11/7/2006.......12/5/2006............629
    KIM...........kim@ aol.com.... 294631.............     4/2/2007.........3/4/2008.............174
    KIM...........kim@ aol.com.... 322922.............     7/29/2008.......7/29/2008............27
    JOE...........joe@ aol.com.... 183332.............     1/28/2004.......4/23/2004............1585
    JOE...........joe@ aol.com.... 183336.............     1/28/2004.......3/9/2004.............1630
    SAM...........sam@ aol.com....183876.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183877.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183879.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183880.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183881.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183882.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183883.............3/5/2004.........3/8/2004.............1631
    SAM...........sam@ aol.com....183884.............3/5/2004.........3/8/2004............     1631
    SAM...........sam@ aol.com....183886.............3/5/2004.........3/8/2004............     1631
    SAM...........sam@ aol.com....183887.............3/5/2004.........3/8/2004............     1631
    SAM...........sam@ aol.com....183888.............3/5/2004.........3/8/2004............     1631
    PAT...........pat@ aol.com.....291630.............2/23/2007.......7/8/2008............     48
    PAT...........pat@ aol.com.....313990.............2/27/2008.......7/28/2008............28
    NED...........ned@ aol.com.....190681.............4/4/2006........8/10/2006............746
    NED...........ned@ aol.com......95467.............6/14/2006.......11/6/2006............658
    NED...........ned@ aol.com......286688.............11/8/2006.......10/3/2007............327
    NED...........ned@ aol.com.....291631.............2/23/2007.......8/21/2008............4
    NED...........ned@ aol.com.....292111.............3/7/2007.........2/26/2008............181
    NED...........ned@ aol.com.....292410.............3/15/2007.......7/22/2008............34
    NED...........ned@ aol.com.....299410.............6/27/2007.......2/27/2008............180
    NED...........ned@ aol.com.....303790.............9/19/2007.......9/19/2007............341
    NED...........ned@ aol.com.....304268.............9/24/2007.......3/3/2008............     175
    NED...........ned@ aol.com.....308228.............12/6/2007.......12/6/2007............263
    NED...........ned@ aol.com.....316689.............3/19/2008.......3/19/2008............159
    NED...........ned@ aol.com.....316789.............3/20/2008.......3/20/2008............158
    NED...........ned@ aol.com.....317528.............3/25/2008.......3/25/2008............153
    NED...........ned@ aol.com.....321476.............6/4/2008.........6/17/2008............69
    NED...........ned@ aol.com.....322160.............7/3/2008.........8/21/2008............4
    MOE...........moe@ aol.com.....184169.............4/5/2004.......12/5/2006............629
    [email protected]/27/2004.......3/8/2004............1631
    How do I incorporate a if else statement in the above cursor so the two days less than 30 days since last update are not returned. I do not want to send email if the project have been updated within the last 30 days.
    Edited by: user4653174 on Aug 25, 2008 2:40 PM

    analytical functions: http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions2a.htm#81409
    CASE
    http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/02_funds.htm#36899
    http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96624/04_struc.htm#5997
    Incorporating either of these into your query should assist you in returning the desired results.

  • How do we split our iCloud accounts but keep one iTunes account so we can share purchased content for our multiple iPhones and iPads?

    How do we split our iCloud accounts but keep one iTunes account so we can share purchased content for our multiple iPhones and iPads?

    You can migrate a copy of the data to a new account, then delete the other person's data from each account.  To do this, on the phone that will be changing accounts, if you have any photos in photo stream that you want to keep on the phone, save these to your camera roll by opening the photo stream album in the thumbnail view, tapping Edit, then tap all the photos you want to save, tap Share and tap Save to Camera Roll. If you have any synced notes that you want to keep on the phone, email these to yourself so you can create new notes in the new account.
    Once this is done, go to Settings>iCloud, scroll to the bottom and tap Delete Account.  (This will only delete the account from this phone, not from iCloud.  The phone that will be keeping the account will not be effected by this.)  When prompted about what to do with the iCloud data, be sure to select Keep On My iPhone.  Next, set up a new iCloud account using a different Apple ID (if you don't have one, tap Get a Free Apple ID at the bottom).  Then turn iCloud data syncing for contacts, etc. back to On, and when prompted about merging with iCloud, choose Merge.  This will upload the data to the new account.  You will create a new icloud email address with you turn Mail to On.
    Finally, to un-merge the data you will then have to go to icloud.com on your computer and sign into each iCloud account separately and manually delete the data you don't want (such as deleting your wife's data from your account, and vice versa).

  • Ref Cursor and For Loop

    The query below will return values in the form of
    bu     seq     eligible
    22     2345     Y
    22     2345     N
    22     1288     N
    22     1458     Y
    22     1458     N
    22     1234     Y
    22     1333     N
    What I am trying to accomplish is to loop through the records returned.
    for each seq if there is a 'N' in the eligible column return no record for that seq
    eg seq 2345 has 'Y' and 'N' thus no record should be returned.
    seq 1234 has only a 'Y' then return the record
    seq 1333 has 'N' so return no record.
    How would I accomplish this with a ref Cursor and pass the values to the front end application.
    Procedure InvalidNOs(io_CURSOR OUT T_CURSOR)
         IS
              v_CURSOR T_CURSOR;
         BEGIN
    OPEN v_CURSOR FOR
    '     select bu, seq, eligible ' ||
    '     from (select bu, seq, po, tunit, tdollar,eligible,max(eligible) over () re ' ||
    '          from (select bu, seq, po, tunit, tdollar,eligible ' ||
    '          from ( ' ||
    '          select bu, seq, po, tunit, tdollar, eligible, sum(qty) qty, sum(price*qty) dollars ' ||
    '               from ' ||
    '               ( select /*+ use_nl(t,h,d,s) */ ' ||
    '               h.business_unit_id bu, h.edi_sequence_id seq, d.edi_det_sequ_id dseq, ' ||
    '                    s.edi_size_sequ_id sseq, h.po_number po, h.total_unit tUnit, h.total_amount tDollar, ' ||
    '                    s.quantity qty, s.unit_price price,' ||
    '               (select (case when count(*) = 0 then ''Y'' else ''N'' end) ' ||
    '          from sewn.NT_edii_po_det_error ' ||
    '          where edi_det_sequ_id = d.edi_det_sequ_id ' ||
    '               ) eligible ' ||
    '     from sewn.nt_edii_purchase_size s, sewn.nt_edii_purchase_det d, ' ||
    '     sewn.nt_edii_purchase_hdr h, sewn.nt_edii_param_temp t ' ||
    '     where h.business_unit_id = t.business_unit_id ' ||
    '     and h.edi_sequence_id = t.edi_sequence_id ' ||
    '     and h.business_unit_id = d.business_unit_id ' ||
    '     and h.edi_sequence_id = d.edi_sequence_id ' ||
    '     and d.business_unit_id = s.business_unit_id ' ||
    '     and d.edi_sequence_id = s.edi_sequence_id ' ||
    '     and d.edi_det_sequ_id = s.edi_det_sequ_id ' ||
    '     ) group by bu, seq, po, tunit, tdollar, eligible ' ||
    '     ) ' ||
    '     group by bu, seq, po, tunit, tdollar, eligible)) ';
              io_CURSOR := v_CURSOR;
    END     InvalidNOs;

    One remark why you should not use the assignment between ref cursor
    variables.
    (I remembered I saw already such thing in your code).
    Technically you can do it but it does not make sense and it can confuse your results.
    In the opposite to usual variables, when your assignment copies value
    from one variable to another, cursor variables are pointers to the memory.
    Because of this when you assign one cursor variable to another you just
    duplicate memory pointers. You don't copy result sets. What you do for
    one pointer is that you do for another and vice versa. They are the same.
    I think the below example is self-explained:
    SQL> /* usual variables */
    SQL> declare
      2   a number;
      3   b number;
      4  begin
      5   a := 1;
      6   b := a;
      7   a := a + 1;
      8   dbms_output.put_line('a = ' || a);
      9   dbms_output.put_line('b = ' || b);
    10  end;
    11  /
    a = 2
    b = 1
    PL/SQL procedure successfully completed.
    SQL> /* cursor variables */
    SQL> declare
      2   a sys_refcursor;
      3   b sys_refcursor;
      4  begin
      5   open a for select empno from emp;
      6   b := a;
      7   close b;
      8 
      9   /* next action is impossible - cursor already closed */
    10   /* a and b are the same ! */
    11   close a;
    12  end;
    13  /
    declare
    ERROR at line 1:
    ORA-01001: invalid cursor
    ORA-06512: at line 11
    SQL> declare
      2   a sys_refcursor;
      3   b sys_refcursor;
      4   vempno emp.empno%type;
      5 
      6  begin
      7   open a for select empno from emp;
      8   b := a;
      9 
    10   /* Fetch first row from a */
    11   fetch a into vempno;
    12   dbms_output.put_line(vempno);
    13 
    14   /* Fetch from b gives us SECOND row, not first -
    15      a and b are the SAME */
    16 
    17   fetch b into vempno;
    18   dbms_output.put_line(vempno);
    19 
    20 
    21  end;
    22  /
    7369
    7499
    PL/SQL procedure successfully completed.Rgds.
    Message was edited by:
    dnikiforov

  • 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

  • Ref cursor and dynamic sql

    Hi..
    I'm using a ref cursor query to fetch data for a report and works just fine. However i need to use dynamic sql in the query because the columns used in the where condition and for some calculations may change dynamically according to user input from the form that launches the report..
    Ideally the query should look like this:
    select
    a,b,c
    from table
    where :x = something
    and :y = something
    and (abs(:x/:y........)
    The user should be able to switch between :x and :y
    Is there a way to embed dynamic sql in a ref cursor query in Reports 6i?
    Reports 6i
    Forms 6i
    Windows 2000 PRO

    Hello Nicola,
    You can parameterize your ref cursor by putting the query's select statement in a procedure/function (defined in your report, or in the database), and populating it based on arguments accepted by the procedure.
    For example, the following procedure accepts a strongly typed ref cursor and populates it with emp table data based on the value of the 'mydept' input parameter:
    Procedure emp_refcursor(emp_data IN OUT emp_rc, mydept number) as
    Begin
    -- Open emp_data for select all columns from emp where deptno = mydept;
    Open emp_data for select * from emp where deptno = mydept;
    End;
    This procedure/function can then be called from the ref cursor query program unit defined in your report's data model, to return the filled ref cursor to Reports.
    Thanks,
    The Oracle Reports Team.

  • How to pick max value from a column of a table using cursor and iteration

    Hello Everybody
    I have a table loan_detail
    and a column in it loan_amount
    now i want to pick values from this table using cursor and then by using iteration i want to pick max value from it using that cursor
    here is my table
    LOAN_AMOUNT
    100
    200
    300
    400
    500
    5600
    700i was able to do it using simple loop concepts but when i was trying to do this by using cursor i was not able to do it .
    Regards
    Peeyush

    SQL> SELECT MAX(sal) Highest_Sal,MIN(sal) Lowest_Sal FROM emp;
    HIGHEST_SAL LOWEST_SAL
           5000        800
    SQL> set serverout on
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := counter;
    10      counter := counter + 1;
    11    END LOOP;
    12    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    13    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    14  END;
    15  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Even smaller
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := 1;
    10    END LOOP;
    11    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    12    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    13  END;
    14  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Edited by: Saubhik on Jan 5, 2011 4:41 PM

  • Having a problem with Firefox using Hotmail email. Inbox - as checking messages it freezes up or a 1 item window follows cursor and does not allow you to enter

    I am having a problem accessing Hotmail email messages via Fireflox server. When I am in the Inbox, reviewing messages, it either freezes up or a "1 item" small icon window follows cursor and does not allow me to enter messages or do anything. Have to log off and start over. Suggestions>?

    Can you detect any pattern to it, whether related to messages with attachments, or particular advertising on the page, etc.?
    When you have a problem with one particular site, a good "first thing to try" is clearing your Firefox cache and deleting your saved cookies for the site.
    1. Clear Firefox's Cache
    orange Firefox button ''or'' Tools menu > Options > Advanced
    On the Network mini-tab > Offline Storage : "Clear Now"
    2. If needed, delete the site's cookies here
    While viewing a page on the site, right-click and choose View Page Info > Security > "View Cookies"
    (Usually the dialog will refer to live.com rather than hotmail.com, that's normal.)
    Then try reloading the page and logging in again. Does that help?

  • Multi coloured spinning cursor and mac air keeps freezing?

    multi coloured spinning cursor and mac air keeps freezing?

    Force Quit .
    Press command + option + esc keys together at the same time for 3 seconds.  Wait.
    When Force Quit window appears, select the application if not already.
    Press Force Quit button at the bottom of the window.       Wait.
    Application will quit.
    http://support.apple.com/kb/HT3411
    Start up in Safe Mode.
    http://support.apple.com/kb/PH11212?viewlocale=en_US

Maybe you are looking for

  • Issue with instant ringback when using sip trunk to SP

    Hi all, We use CUCM 8.0.2. We have a SIP trunk to a SP connected via one of our Cisco 2911 routers configured as a CUBE. Cisco IOS Software, C2900 Software (C2900-UNIVERSALK9-M), Version 15.0(1)M3, RELEASE SOFTWARE (fc2) c2900-universalk9-mz.SPA.150-

  • How do I view all Components the page of a PDF doc?

    I'm using the text touch-up tool to make a correction to a document which is auto-generated through an internal system as a very complex pdf document. The text disappears behind another component as if it's being pushed below another panel. Is there

  • Flash 8 vs. Flash 7

    Hello, I just completed a nice little project making use of the FLVPlayback features of Flash 8. I imported video files and encoded them to .flv files and stream them from a server. Works great. However, I just learned that some of my customers run L

  • How to get statistics of Z programs ran last 2 months

    Dear sirs How could I get statistics of Z-programs ran last 2 months <REMOVED BY MODERATOR> Edited by: Alvaro Tejada Galindo on Jan 24, 2008 11:19 AM

  • F5 and Cisco ISE Deployment Guide

    Its out! For those of you have been asking and looking for this document as much as I have, it looks like Craig Hyps has delivered! Thank Craig! http://www.cisco.com/c/dam/en/us/td/docs/security/ise/how_to/HowTo-95-Cisco_and_F5_Deployment_Guide-ISE_L