How to find if cursor returned rows

If i have a procedure like
create procedure test as
cursor cur_test is
select col
from table;
begin
     delete from tab1 a;
     for var_cur_test in cur_test
     loop
          insert into temp
          values(var_cur_test.col);
     end loop;
     commit;
end;
How do I check if the cursor has returned any rows?
I dont want to delete from tab1 if cursor 'cur_test' does not return any rows and I want to exit out of the proc.
If the cursor returns rows > 0 then I want to delete and do the insert.
Thanks for the help.

The scenario is like this.
There is a schema A which has to run a process and populate its tables and at the end of the process(java program) run the procedure which is in schema B to pull data from schema A and populate the tables in schema B. If there is a case where Schema A's process fails( then Schema A's tables end up with no data), the process is still running the procedure in schema B and deleting the data in tables with no data being inserted.
So, I have to check in the procedure if the tables in Schema A have any data before the process can run the proc.
I tried the solution you provided but it returns no data
CREATE OR REPLACE PROCEDURE MMA_TEST
VAR_CONTRACT_ID VARCHAR2
AS
CURSOR CUR_TEST IS
SELECT CMS_CONTRACT_ID,CMS_PLAN_ID
FROM MMA_PLANS
WHERE CMS_CONTRACT_ID = VAR_CONTRACT_ID;
BEGIN
     for var_cur_test in cur_test
     loop
          if (cur_test%rowcount = 1) then
          delete from temp ;
          end if ;
          insert into temp
          values(var_cur_test.cms_contract_id,var_cur_test.cms_plan_id);
     end loop;
end;

Similar Messages

  • How to find accurate number of Rows, and size of all the tables of a Schema

    HI,
    How to find the accurate number of Rows, and size of all the tables of a Schema ????
    Thanks.

    SELECT t.table_name AS "Table Name",
    t.num_rows AS "Rows",
    t.avg_row_len AS "Avg Row Len",
    Trunc((t.blocks * p.value)/1024) AS "Size KB",
    t.last_analyzed AS "Last Analyzed"
    FROM dba_tables t,
    v$parameter p
    WHERE t.owner = Decode(Upper('&1'), 'ALL', t.owner, Upper('&1'))
    AND p.name = 'db_block_size'
    ORDER by 4 desc nulls last;
    ## Gather schema stats
    begin
    dbms_stats.gather_schema_stats(ownname=>'SYSLOG');
    end;
    ## Gather a particular table stats of a schema
    begin
    DBMS_STATS.gather_table_stats(ownname=>'syslog',tabname=>'logs');
    end;
    http://www.oradev.com/create_statistics.jsp
    Hope this will work.
    Regards
    Asif Kabir
    -- Mark the answer as correct/helpful

  • How to find rowid of locked rows?

    Hello All,
    I have the "before update trigger" I want to know the rowid of all the locked row before update so that I dont try to update the same row which is locked by some other user. In Ask Tom forum I have seen how to know the rowid of locked row, but it will work only when Some body got hanged in that Perticular row while trying to update it. I dont want the User to get hanged, for that I want to user before update trigger. Help me.

    I believe this is a duplicate of another question in this forum
    How to find out rowid of locked row
    which I answered.
    Justin

  • I need to know how many  lines a cursor returns

    Hi,
    I need to know how many lines a cursor will return without counting it within a loop or putting a count clause within the cursor . Is there a way to do ?

    Please post this question in the database forum for an appropriate response: General Database Discussions
    Regards,
    OTN

  • How To find rowid of Locked row.

    Hello,
    can somebody tell me the "select statement", how to find the rowid of a locked row, which is locked by "select for update" and also the rowid of a row which is going to be updated by "update statement".

    check out v$session and the following columns.
    It is documented here
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96536/ch3171.htm#1122127
    ROW_WAIT_OBJ#
    NUMBER
    Object ID for the table containing the ROWID specified in ROW_WAIT_ROW#
    ROW_WAIT_FILE#
    NUMBER
    Identifier for the datafile containing the ROWID specified in ROW_WAIT_ROW#. This column is valid only if the session is currently waiting for another transaction to commit and the value of ROW_WAIT_OBJ# is not -1.
    ROW_WAIT_BLOCK#
    NUMBER
    Identifier for the block containing the ROWID specified in ROW_WAIT_ROW#. This column is valid only if the session is currently waiting for another transaction to commit and the value of ROW_WAIT_OBJ# is not -1.
    ROW_WAIT_ROW#
    NUMBER
    The current ROWID being locked. This column is valid only if the session is currently waiting for another transaction to commit and the value of ROW_WAIT_OBJ# is not -1.

  • How to find the no of rows updated

    Hello,
    Is there any way to find the no of rows updated using a anony.. block
    example
    begin
    update test set cost=3244 where dept='IT';
    update test set cost=3434 where dept='retail';
    end;
    is there any way here.

    user7351276 wrote:
    yes I had tried this but have around 6000 statements like this.Are you looking to get 6000 counts? Then you'd need 6000 calls to SQL%ROWCOUNT.
    Of course, I would be extremely suspicious of a process that had 6000 very similar SQL statements. It would almost certainly be preferable to do something like load a mapping table and to issue a single update, i.e.
    CREATE TABLE mapping_table (
      cost number,
      dept varchar2(10)
    INSERT INTO mapping_table( cost, dept ) VALUES( 3244, 'IT' );
    INSERT INTO mapping_table( cost, dept ) VALUES( 3434, 'retail' );
    UPDATE test t
       SET cost = (
        SELECT m.cost
          FROM mapping_table m
         WHERE m.dept = t.dept )
    WHERE EXISTS (
        SELECT 1
          FROM mapping_table m
         WHERE m.dept = t.dept );
    dbms_output.put_line( 'A total of ' || sql%rowcount || ' rows updated.' );Justin

  • How to find duplicated values in rows obtained from multiple tables

    Hi.
    I need to find the duplicates stored in different tables of my database. I have some tables like the following model (I know it could be nonsense, but that's because it's simplified):
    table person { id, name, surname }.
    table zoo {id, owner, name, city} (zoo.owner -> person.id)
    table area {id, zoo, type, name} (area.zoo -> zoo.id).
    table dog {id, area, name, colour} (dog.area -> area.id)
    table elephant {id, area, name, height} (elephant.area -> area.id)
    As ids are autoincremental, it could happen that a person has two zoos with identical areas (meaning, these areas has the same type and name, same dogs (same name and colour) and same elephants (same name and height)). In an example with data:
    person
    id     name     surname
    p1     john     doe
    zoo
    id     owner     name          city
    z1     p1          central     NY
    z2     p1          central     NY
    area
    id     zoo     type     name
    a1     z1     open     main
    a2     z2     open     main
    dog
    id     area     name          colour
    d1     a1     jaro          brown
    d2     a1     chispa     white
    d3     a2     jaro          brown
    d4     a2     chispa     white
    elephant
    id     area     name          height
    e1     a1     dumbo     5
    e2     a1     elphy          4
    e3     a2     dumbo     5
    e4     a2     elphy          4
    That is: John Doe has two zoos in the same city and with the same name. These two zoos, has one open main area each. Each of these areas has two dogs with the same names and colours and two elephants with the same names and heights. So this zoos would be identical. What I want is to delete z2 zoo.
    I'd like to find a SQL function which returns me the id of one of these zoos, so it can respond to the question. Has the person called "John Doe" more than one area with the same type, name, dogs and elephants?
    Is it possible?

    Hi,
    Interesting problem!
    Two distinct zoos are duplicates of each other if they have the same owner, the same name, the same areas, and the same animals in each of those areas.
    It's pretty easy to tell if two zoos are distinct, but have the same owner and name. We could do that with a self-join:
    SELECT       z1.*
    ,       z2.id          AS id_2
    FROM       zoo     z1
    JOIN       zoo     z2  ON   z1.owner     = z2.owner
                    AND      z1.name     = z2.name
                  AND      z1.id          < z2.idBut how can we tell if two zoos that meet these criteria have the same aminals in the same areas? (It amuses me to call these the "critter criteria".)
    One way is to make a list, for each zoo, of all the animals, with all their attributes (that is, the attributes that matter for determining if they are the same), in each area, and then see if the lists for those two zoos is identical. Like this:
    WITH     all_animals     AS
         SELECT     d.id, d.area
         ,     d.name          -- || '~' || d.colour || ...
                   AS attributes
         ,     'DOG'     AS animal
         FROM     dog     d
        UNION ALL
         SELECT     e.id, e.area
         ,     e.name          -- || '?`' || e.height || ...
                        AS attributes
         ,     'ELEPHANT'     AS animal
         FROM     elephant     e
    -- UNION ALL   ... cat ... monkey ...
    ,     got_analytics     AS
         SELECT     z.id          AS zoo_id
         ,     ar.type          -- , ar.name, ...
         ,     an.animal
         ,     an.attributes
         ,     COUNT (*)     OVER ( PARTITION BY  z.id )     AS cnt
         ,     ROW_NUMBER () OVER ( PARTITION BY  z.id
                                   ORDER BY          ar.type     -- , ar.name, ...
                             ,                an.animal
                                         ,                    an.attributes
                           )                    AS r_num
         FROM           zoo          z
         LEFT OUTER JOIN      area          ar  ON   ar.zoo          = z.id
         LEFT OUTER JOIN      all_animals     an  ON       an.area     = ar.id
    SELECT       z1.*
    ,       z2.id          AS id_2
    FROM       zoo     z1
    JOIN       zoo     z2  ON   z1.owner     = z2.owner
                    AND      z1.name     = z2.name
                  AND      z1.id          < z2.id
    WHERE     NOT EXISTS
              SELECT  type     -- , name, ...
              ,          animal, attributes
              ,          cnt, r_num
              FROM    got_analytics
              WHERE   zoo_id     = z1.id
           MINUS         
              SELECT  type     -- , name, ...
              ,          animal, attributes
              ,          cnt, r_num
              FROM    got_analytics
              WHERE   zoo_id     = z2.id
    ORDER BY  z1.id
    ,            z2.id
    ;The first sub-query, all_animals, combines all the animals from all of the separate species tables. For each one, it makes a delimited list (the attributes column) of the columns that count in determining if 2 animals are the same. Different species may have different attributes and different numbers of attributes. The lists have to be delimited by some sub-string (not necessarily a single character) that can never occur in any of the attributes for that species. For example, dogs may never have '~' in their names (or their colours, if you expand the example to include colour). Elephants might have any character, but never have a '?' followed immediately by a grave accent '`'.
    The next sub-query, got_analytics, joins the zoo and area tables to this combined list of animals. The joins are outer joins, so we can detect as duplicates two zoos that have no areas, or two areas that have no animals.
    In the main query, I used MINUS to tell if the lists for two given zoos were identical. If x MINUS y produces no results, then every row in x has a matching row in y. To say that x and y are identical, we also have to know that every row in y has a matching row in x. Rather than do another MINUS, I counted the rows (got_analytics.cnt), so that if y has more rows than x, no rows will match when we do the MINUS.
    Here's the output I got from your sample data:
    `       ID      OWNER NAME             ID_2
             1          1 CENTRAL NY          2This shows the distinct ids, and the common attributes, of all distinct pairs of zoos that match. You can join this to the person table, if you want to see details about the owner.
    If a query is correct, it will not only find all the results it is supposed to find; it will also not find all the results it is not supposed to find, for all the various reasons. I added some more sample data to test one such reason:
    INSERT INTO ZOO (ID, OWNER, NAME) VALUES (91, 1, 'CENTRAL NY');
    INSERT INTO AREA (ID, ZOO, TYPE) VALUES (92, 91, 'MAIN');
    INSERT INTO DOG (ID, AREA, NAME) VALUES (93, 92, 'JARO');
    INSERT INTO DOG (ID, AREA, NAME) VALUES (94, 92, 'CHISPA');Zoo 91 is identical to zoos 1 and 2, except that 91 has no elephants. To thoroughly test this solution, you need to add some more test data, especially zoos that will not be selected for various reasons: for example, two zoos that have all the same animals, but different numbers of areas, or that both have two areas, but the animals are distributed differently between the areas.

  • How to find a carriage return and Line feed?

    I need to detect if a crriage retunr and line feed present on each row in my text file before allowing user to upload the text file
    I know how to remove them from each line but what I need is to detect them no removing them from file.
    Our concern is when the a row does not have carriage return and line feed.
    Is there a way to find this using CF? Please help
    thanks

    That is exactly the problem Dave, if some rows do not have line feed, they're not being inserted into DB, it skips other steps and go right to finish. It looks
    like the file is done processing.
    So I need to do early rejection to this kind of file.
    I used cfloop to catch anything else that do not follow the formatting rules.
    Here is what I already done:
    Right after the file got uploaded, I have these codes:   
    <cfloop  index="x" file="#MyFile#" >
      <CFSETMyLine = Replace(x,chr(9),"|", "ALL")>
      I'm using a few functions, such as, Left(), Mid(), Right(), etc to make sure certain rules are followed.
      Up till here, it's done and tested, everything is working.
      The only problem is when 1 or more rows don't end up with line feed and or carriage return.
      I plan to add some codes to check the end of each row for chr(10) since it is looping for every row anyway.
      If detected, process file normally otherwise stop processing.
    </cfloop>
    So this can't be done in CF?

  • How to find and delete matching row in ADF BC

    Hi,
    I have a table with simple fields and I have created the java class for this entity also
    Person
         - Person_Id (PK)
         - Person_NameI wanted to create an application module method to search for the entity that matches certain name
    but I cant find the code to do this.
    public class AppModuleImpl{
      public boolean deletePersonByName(String personName)
        EntityDefImpl personDef = PersonImpl.getDefinitionObject();
        //How to get all rows and find the matching name then delete the row
        return false;
    }Thanks
    Jdev 11.1.1.5

    Ramandeep Nanda wrote:
    getfilteredRows does that, you can iterate and delete the rows after filtering on any attribute in view object it does not have to be a primary key.Hi Ramandeep,
    I got the idea and I somehow was able to do what I want.
      public boolean deletePersonByName(String personName)
        PersonViewImpl personView = this.getPersonView();
        Row[] matchingRows = personView.getFilteredRows("PersonName", personName);
        if(matchingRows!=null)
          for(Row rowTemp : matchingRows)
            PersonViewRowImpl personRow = (PersonViewRowImpl) rowTemp;
            personRow.remove();
            try
              getDBTransaction().commit();
            }catch(JboException ex)
              throw ex;
        return true;
      }But somehow I got this idea, supposed I have this data
    PersonId          PersonName
    1               MANDER
    2               MANDERRY
    3               JERRYThe code getFilteredRows somehow only perform an 'exact' match but what if I want to delete both of the data
    with PersonName 'MANDER' above.
    My current code only removes the person with name 'MANDER' and not the 'MANDERRY'
    Thanks

  • How to find the no.of rows of bank details existed previously for XK02

    Hi all,
    In bdc(table control) i am updatibg the data for the t.code xk02.
    In xk02 transaction i am adding bank details data.the no.of rows of bank details changing for each vendor.now i want to know how many rows of bank details are existed previously. so that i can continue the bank details from the next row onwards.
    pls help with logic
    Thanks
    Mythily

    Hi,
    Its difficult to get it done by BDC!
    Use LSMW instead, it would take care of it.
    Cheers,S
    Somnath

  • How BITMAP INDEX SINGLE VALUE returns rows ?

    Hi guys,
    here is piece from serial execution plan (display_cursor)
    | Id  | Operation                                        | Name                         | Starts | E-Rows | A-Rows |
    |  48 |                  PARTITION LIST ALL              |                              |   3712 |        |   4089K|
    |  49 |                   BITMAP CONVERSION TO ROWIDS    |                              |  40832 |        |   4089K|
    |  50 |                    BITMAP AND                    |                              |  40832 |        |  23708 |
    |* 51 |                     BITMAP INDEX SINGLE VALUE    | IDX1                         |  40832 |        |  26014 |
    |* 52 |                     BITMAP INDEX SINGLE VALUE    | IDX2                         |  40832 |        |  28076 |
    ...What does mean such difference in A-Rows in steps 50->49, from 23708 to 4089K.
    Do steps 51-52 return not regular rows but rows with bitmaps, which consist many regular rows?

    853118 wrote:
    here is piece from serial execution plan (display_cursor)
    What does mean such difference in A-Rows in steps 50->49, from 23708 to 4089K.
    Do steps 51-52 return not regular rows but rows with bitmaps, which consist many regular rows?First of all have you noticed that you have more than 40,000 starts of these operations accounted for? That explains why you see more than 1 "row" accounted for the "single value" operation. But to answer your question: Yes, a single value in a bitmap index will have one or more bitmap pieces, and each bitmap piece covers a range of ROWIDs with the bitmap (0 or 1) pattern that tells whether the value is stored in that row or not.
    So a single value of a bitmap can potentially return many, if not all rows of a table. The "rows" output in the A-Rows column for bitmap indexes is probably the number of bitmap pieces (sometimes also called "fragments" I think) and therefore can look pretty small in comparison to the rows actually accessed in the table based on the information extracted from those bitmap pieces.
    For more info, I recommend to have a look at Julian Dyke's presentation about bitmap index internals: http://www.juliandyke.com/Presentations/BitmapIndexInternals.ppt
    Also Greg Rahn has an interesting blog post that also covers the discrepancy between "rows" of a bitmap operation and "rows" of the corresponding table access: http://structureddata.org/2008/05/29/using-bitmap-indexes-effectively/
    Hope that helps,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    Co-author of the "OakTable Expert Oracle Practices" book:
    http://www.apress.com/book/view/1430226684
    http://www.amazon.com/Expert-Oracle-Practices-Database-Administration/dp/1430226684

  • How to Find Source Table Updated Rows using Tsql Script

    Hi Folks,
    i have 2 tales Source table and Staging Table. yeaterday I have Imported 24 Million Records From Source table into Staging table. These Table Contain approxmately 42 columns. So today may be some of the updates happend  in Source table rows. ID is the
    Unique column.
    So may I know which rows are Updated compared to Both tables using Tsql Query. (all 42 Columns might be updated ) .
    usually new rows also appeard in sourcetable. I want only Which are Updated not New rows!.
    Thanks in Advance.

     SELECT Source.*, Stage.*
       FROM Source
            FULL OUTER JOIN
            Stage
            ON Source.c1 = Stage.c1
               AND Source.c2 = Stage.c2
               AND Source.cn = Stage.cn
     WHERE Source.key IS NULL 
        OR Stage.key IS NULL; 
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to find the cursor on the screen?

    On a PC, I could set it up so that if I could not readily see the location of the cursor on the screen I would just touch the CTRL key and a big moving circle would appear to point out the cursor location.  What is the equivalent trick on iMac?
    -new to Imacs

    You can adjust the size of the cursor here - System Preferences > Universal Access > Mouse, near the bottom of that window. However, this is not a temporary size change - it will stay the new size until you change it again.
    For a temporary (on demand) locator, try something like Mouse Locator -
    http://mac-free.com/download/Mouse-Locator.html

  • How to find out which sub query returns more than one row

    Hi all,
    Can any one give me clue ,how to find out which sub query returns more than one row in the following query .
    /* Formatted on 2011/05/17 19:22 (Formatter Plus v4.8.8) */
    SELECT a.*, ROWNUM AS rnm
      FROM (SELECT DISTINCT '1' AS "Page View", ou.org_unit_name AS "Org",
                            prxm.mbr_idntfr AS "Beneficiary ID",
                               md.last_name
                            || ', '
                            || md.first_name AS "Beneficiary Name",
                            pci.idntfr AS "Tracking No.",
                            TO_CHAR (TRUNC (req.pa_rqst_date),
                                     'MM/dd/yyyy'
                                    ) AS "Request Date",
                            sts.status_name AS "Status",
                            req.pa_rqst_sid AS "Request #",
                            prxm.mbr_sid AS "Mbr_sid",
                            TO_CHAR
                                  (TRUNC (req.pa_revision_date),
                                   'MM/dd/yyyy'
                                  ) AS "Last Updated",
                            TO_CHAR (psd.TO_DATE, 'MM/dd/yyyy') AS "TO_DATE",
                            prxpl.prvdr_lctn_iid AS "PRVDR_LCTN_IID",
                            pd.prvdr_sid AS "PRVDR_SID", 'Y' AS "State View",
                            DECODE
                               ((SELECT DISTINCT pd.national_prvdr_idntfr
                                            FROM pa_request_x_provider_location prxplo
                                           WHERE prxplo.pa_rqst_sid =
                                                                   req.pa_rqst_sid
                                             AND prxplo.oprtnl_flag = 'A'
                                             AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                0, (SELECT prxplo.prvdr_lctn_idntfr
                                      FROM pa_request_x_provider_location prxplo
                                     WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                       AND prxplo.oprtnl_flag = 'A'
                                       AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                NULL, (SELECT prxplo.prvdr_lctn_idntfr
                                         FROM pa_request_x_provider_location prxplo
                                        WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                          AND prxplo.oprtnl_flag = 'A'
                                          AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                (SELECT DISTINCT pd.national_prvdr_idntfr
                                            FROM pa_request_x_provider_location prxplo
                                           WHERE prxplo.pa_rqst_sid =
                                                                   req.pa_rqst_sid
                                             AND prxplo.oprtnl_flag = 'A'
                                             AND prxplo.pa_prvdr_type_lkpcd = 'RR')
                               ) AS "NPI/ID",
                            DECODE
                               ((SELECT pd.org_bsns_name
                                   FROM pa_request_x_provider_location prxplo
                                  WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                    AND prxplo.oprtnl_flag = 'A'
                                    AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                NULL, (SELECT    pd.last_name
                                              || ', '
                                              || pd.first_name
                                              || ' '
                                              || pd.middle_name
                                         FROM pa_request_x_provider_location prxplo
                                        WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                          AND prxplo.oprtnl_flag = 'A'
                                          AND prxplo.pa_prvdr_type_lkpcd = 'RR'),
                                (SELECT pd.org_bsns_name
                                   FROM pa_request_x_provider_location prxplo
                                  WHERE prxplo.pa_rqst_sid = req.pa_rqst_sid
                                    AND prxplo.oprtnl_flag = 'A'
                                    AND prxplo.pa_prvdr_type_lkpcd = 'RR')
                               ) AS "Prvdr Name",
                            TO_CHAR (psd.from_date,
                                     'MM/dd/yyyy'
                                    ) AS "Srvc From Date",
                            TO_CHAR (req.validity_start_date,
                                     'MM/DD/YYYY'
                                    ) AS "Due Date",
                            (fn_get_busniess_days (TRUNC (req.validity_start_date))
                            ) AS "Days<br>Left",
                            req.pa_mode_type_lkpcd AS "Source",
                            TO_CHAR (TRUNC (wmdtl.rtng_date),
                                     'MM/dd/yyyy'
                                    ) AS "Assigned On",
                            NVL (wmdtl.assigned_to_user_name,
                                 'Not Assigned'
                                ) AS "Assigned To",
                            req.org_unit_sid AS "OrgUnitSid",
                            TO_CHAR
                                 (wmdtl.modified_date,
                                  'MM/dd/yyyy hh24:mi:ss'
                                 ) AS "WTRD_MODIFIED_DATE",
                            TO_CHAR (wmdtl.rtng_date,
                                     'MM/dd/yyyy'
                                    ) AS "WTRD_RTNG_DATE",
                            req.status_cid AS "PA_STATUS_CID",
                            TO_CHAR (req.modified_date,
                                     'MM/dd/yyyy'
                                    ) AS "PA_REQ_MODIFIED_DATE",
                            prs.state_pa_srvc_type_code
                                                     AS "STATE_PA_SRVC_TYPE_CODE",
                            wmdtl.wm_pa_task_rtng_dtl_sid
                                                        AS "WM_TASK_RTNG_DTL_SID",
                            wmdtl.assigned_to_user_acct_sid
                                              AS "WTRD_Assigned_to_user_acct_sid",
                            (fn_get_busniess_days (TRUNC (req.validity_start_date))
                            ) AS "Days<br>LeftSort",
                            wmdtl.assigned_to_org_unit_sid
                                                  AS "WTRD_Assigned_to_OrgUntSid",
                            DECODE
                               ((SELECT COUNT (*)
                                   FROM pa_request_status prs
                                  WHERE prs.pa_rqst_sid = req.pa_rqst_sid
                                    AND prs.status_cid = 5
                                    AND prs.oprtnl_flag = 'I'),
                                0, 'N',
                                'Y'
                               ) AS "SHOW_UTILIZATION"
                       FROM   pa_request req,
                             pa_certification_identifier pci,
                             status sts,
                             pa_request_x_member prxm,
                             wm_pa_task_routing_detail wmdtl,
                             pa_service_date psd,
                             org_unit ou,
                             pa_request_service prs,
                             pa_request_x_provider_location prxpl,
                             provider_location pl,
                             provider_detail pd,
                             provider p,
                             mbr_dmgrphc md
                      WHERE req.oprtnl_flag = 'A'
                        AND req.status_cid NOT IN
                                     (20, 30, 70, 25, 80, 96, 85, 5, 97, 98, 101)
                        AND req.org_unit_sid IN
                               (3057, 3142, 3058, 3143, 3059, 3144, 3060, 3145,
                                3061, 3146, 3062, 3147, 3063, 3148, 3064, 3149,
                                3065, 3150, 3066, 3151, 3067, 3152, 3068, 3153,
                                3069, 3154, 3070, 3155, 3071, 3156, 3072, 3157,
                                3073, 3158, 3074, 3159, 3075, 3160, 3076, 3161,
                                3077, 3162, 3078, 3163, 3079, 3164, 3080, 3165,
                                3081, 3166, 3082, 3167, 3083, 3168, 3084, 3169,
                                3085, 3170, 3086, 3171, 3087, 3172, 3088, 3173,
                                3089, 3174, 3090, 3175, 3091, 3176, 3092, 3177,
                                3093, 3178, 3094, 3179, 3095, 3180, 3096, 3181,
                                3097, 3182, 3098, 3183, 3099, 3184, 3100, 3185,
                                3101, 3186, 3102, 3187, 3103, 3003, 75000104,
                                75000108, 2006, 75000103, 75000102, 75000113,
                                75000111, 75000109, 2001, 2009, 75000105,
                                75000107, 2004, 2010, 2013, 2014, 2005, 2011,
                                75000112, 2002, 1001, 2012, 75000106, 2007,
                                75000101, 2003, 75000110, 2008, 3001, 3002, 3019,
                                3104, 3020, 3105, 3021, 3106, 3022, 3107, 3023,
                                3108, 3024, 3109, 3025, 3110, 3026, 3111, 3027,
                                3112, 3028, 3113, 3029, 3114, 3030, 3115, 3031,
                                3116, 3032, 3117, 3033, 3118, 3034, 3119, 3035,
                                3120, 3036, 3121, 3037, 3122, 3038, 3123, 3039,
                                3124, 3040, 3125, 3041, 3126, 3042, 3127, 3043,
                                3128, 3044, 3129, 3045, 3130, 3046, 3131, 3047,
                                3132, 3048, 3133, 3049, 3134, 3050, 3135, 3051,
                                3136, 3052, 3137, 3053, 3138, 3054, 3139, 3055,
                                3140, 3056, 3141)
                        AND req.pa_rqst_sid = prs.pa_rqst_sid
                        AND prs.oprtnl_flag = 'A'
                        AND prs.pa_rqst_srvc_sid = psd.pa_rqst_srvc_sid
                        AND psd.oprtnl_flag = 'A'
                        AND req.pa_rqst_sid = pci.pa_rqst_sid
                        AND pci.oprtnl_flag = 'A'
                        AND req.pa_rqst_sid = prxm.pa_rqst_sid
                        AND prxm.oprtnl_flag = 'A'
                        AND md.oprtnl_flag = 'A'
                        AND md.status_cid = 2
                        AND TRUNC (SYSDATE) BETWEEN md.from_date AND md.TO_DATE
                        AND prxm.mbr_sid = md.mbr_sid
                        AND ou.org_unit_sid = req.org_unit_sid
                        AND ou.oprtnl_flag = 'A'
                        AND req.pa_rqst_sid = prxpl.pa_rqst_sid
                        AND prxm.pa_rqst_sid = prxpl.pa_rqst_sid
                        AND pci.pa_rqst_sid = prxm.pa_rqst_sid
                        AND pci.pa_rqst_sid = wmdtl.subsystem_task_sid
                        AND pci.pa_rqst_sid = prxpl.pa_rqst_sid
                        AND prxpl.pa_prvdr_type_lkpcd = 'RR'
                        AND prxpl.oprtnl_flag = 'A'
                        AND req.status_cid = sts.status_cid
                        AND sts.status_type_cid = 3
                        AND sts.oprtnl_flag = 'A'
                        AND prxpl.prvdr_lctn_iid = pl.prvdr_lctn_iid
                        AND p.prvdr_sid = pd.prvdr_sid
                        AND p.prvdr_sid = pl.prvdr_sid
                        AND pd.oprtnl_flag = 'A'
                        AND pd.status_cid = 2
                        AND TRUNC (SYSDATE) BETWEEN pd.from_date AND pd.TO_DATE
                        AND wmdtl.subsystem_task_sid = req.pa_rqst_sid
                        AND wmdtl.subsystem_lkpcd = 'PA'
                        AND wmdtl.oprtnl_flag = 'A'
                        AND req.pa_rqst_date > (SYSDATE - 365)
                                       ORDER BY TO_DATE ("Request Date", 'MM/dd/yyyy hh24:mi:ss') DESC,
                            "Beneficiary Name" ASC) a
    WHERE ROWNUM < 102;regards,
    P Prakash
    Edited by: BluShadow on 17-May-2011 15:01
    added {noformat}{noformat} tags around the code                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    833560 wrote:
    Can any one give me clue ,how to find out which sub query returns more than one row in the following query .This is why smaller, simpler queries are easier to work with than huge ones - when something like this goes wrong smaller queries are much eaiser to debug. Unfortunately using smaller, easier-to-work with queries is not always an option
    Ganesh is right - you will have to dissect the big query bit by bit until you find the offending subquery. If there is another way I would like to find out about it too.
    The easiest way to do this is probably to use block comments to isolate parts of the query bit by bit until you find the offending part. If you carefully examine the subqueries you might be able to figure out which one is returning multiple rows without commenting everything
    Good luck!

  • How do I get the returned cursor from a stored procedure to an asp.

    Sorry if this topic has been answered before but I am new to Oracle and ASP. I have been asked to create some stored procedures and access the results from the ASP. I will be passing one variable in and could be getting upto 200 rows returned.
    I have no trouble with the stored procedure but have no clue how to retrieve the data returned by it.

    Assuming that the stored procedure has a single argument, an OUT cursor, you should be able to do
    SQLExecDirect
    {call <stored_proc>() }
    SQLFetch
    SQLGetData
    We'll handle all the 'magic' underneath.
    Justin Cave
    ODBC Development

Maybe you are looking for