How to modify a Procedure "select into" statement to use a cursor

The below code fails with exception too many rows. How do I modify the Procedure's Select Into statement to use a cursor?
CREATE OR REPLACE PROCEDURE Track_Asset(
   business_date IN NUMBER DEFAULT NULL,
   missing_table_name  OUT VARCHAR2)
IS
   ln_business_date NUMBER;
    incorrectdateformat EXCEPTION;
BEGIN
   IF business_date < 0
   THEN
      RAISE incorrectdateformat;
   ELSE
      DECLARE
        ln_business_date NUMBER;
      BEGIN
         SELECT MAX(business_date)
         INTO ln_business_date
         FROM sproof ;
      EXCEPTION
        WHEN NO_DATA_FOUND THEN
         dbms_output.put_line('NO MATCH FOUND');
        WHEN OTHERS THEN
        dbms_output.put_line('ORACLE ERROR :' || SQLERRM);       
      END;
      DECLARE
        missedfeedfnd EXCEPTION;
      BEGIN
         SELECT 'Missing Value : ' || table_name
         INTO missing_table_name
         FROM (
            SELECT UPPER(table_name) table_name
            FROM filespec
            WHERE data_table_name IN ('TABLE1','TABLE2','TABLE3')
            MINUS (
            SELECT DISTINCT UPPER(first_table_name)
            FROM dpca
            WHERE business_date = ln_business_date
            AND first_table_name IN ('TABLE1','TABLE2','TABLE3')
            GROUP BY UPPER(first_table_name) UNION
            SELECT UPPER(first_table_name)
            FROM dpca
            WHERE business_dt_num = TO_NUMBER( SUBSTR('201111', 1, 6) || '01' )
            AND first_table_name = 'TABLE4'
            GROUP BY UPPER(first_table_name) ));
            IF missing_table_name  IS NOT NULL THEN
               dbms_output.put_line('Missing Value : '|| missing_table_name);
               RAISE missedfeedfnd;
            ELSE
              NULL;
            END IF;
      EXCEPTION
         WHEN TOO_MANY_ROWS THEN
   DBMS_OUTPUT.PUT_LINE (' SELECT INTO statement retrieved multiple rows');
          WHEN missedfeedfnd THEN
          raise_application_error ( - 20003, 'Missed Feed');
      END;
    END IF;
      EXCEPTION
   WHEN incorrectdatevalue
   THEN
      raise_application_error ( - 20001, 'Incorrect/Bad Date Entered');
END;

ok try this - OUT param will be populated with comma separated list of table names:
PROCEDURE Track_Asset(
   business_date IN NUMBER DEFAULT NULL,
   missing_table_name  OUT VARCHAR2)
cursor c_table_names is
select datatablename
from   ( select upper(datatablename) datatablename
         from   filespec
         where  data_table_name in ('TABLE1','TABLE2','TABLE3'                                 )
        MINUS
        ( select upper(first_table_name)
          from   dpca
          where  business_dt_num = [-- this date is retrieved by getting the MAX(business_date) from sproof table]
                 and fus_data_table_name in ('TABLE1','TABLE2','TABLE3'
          group  by
                 upper(first_table_name)
         UNION
          select upper(first_table_name)
          from   dpca
          where  business_dt_num = to_number( substr('201111',1,6) || '01' )
                 and first_table_name = 'TABLE4'
          group  by
                 upper(first_table_name)
begin
   for rec in c_table_names
   loop
       missing_table_name  := missing_table_name  || rec.datatablename ||',';
   end loop;
   missing_table_name  := rtim(missing_table_name , ',');
end ;HTH
Edited by: user130038 on Dec 28, 2011 8:46 AM

Similar Messages

  • How to join THREE different tables into internal table using one select statement .

    How to join THREE different tables into internal table using one select statement .
    Hi experts,
    I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
    Scenario:
    Database tables:
    SPFLI
    SFLIGHT
    SBOOK.
    Table Fields:
    SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
    SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
    SEATSOCC_C SEATSMAX_F SEATSOCC_F
    SBOOK - CARRID CONNID CLASS
    MY INTERNAL TABLE IS IT_XX.
    Your help much appreciated.
    Thanks in advance.
    Pawan.

    Hi Pawan,
    please check below codes. hope it can help you.
    TYPES: BEGIN OF ty_xx,
            carrid     TYPE spfli-carrid   ,
            connid     TYPE spfli-connid   ,
            countryfr  TYPE spfli-countryfr,
            cityfrom   TYPE spfli-cityfrom  ,
            countryto  TYPE spfli-countryto,
            cityto     TYPE spfli-cityto   ,
            fldate     TYPE sflight-fldate ,
            seatsmax   TYPE sflight-seatsmax ,
            seatsocc   TYPE sflight-seatsocc ,
            seatsmax_b TYPE sflight-seatsmax_b,
            seatsocc_b TYPE sflight-seatsocc_b,
            seatsmax_f TYPE sflight-seatsmax_f,
            seatsocc_f TYPE sflight-seatsocc_f,
            class      TYPE sbook-class,
          END OF ty_xx,
          t_xx TYPE STANDARD TABLE OF ty_xx.
    DATA: it_xx TYPE t_xx.
    SELECT spfli~carrid
           spfli~connid
           spfli~countryfr
           spfli~cityfrom
           spfli~countryto
           spfli~cityto
           sflight~fldate
           sflight~seatsmax
           sflight~seatsocc
           sflight~seatsmax_b
           sflight~seatsocc_b
           sflight~seatsmax_f
           sflight~seatsocc_f
           sbook~class
      INTO TABLE it_xx
      FROM spfli INNER JOIN sflight
      ON spfli~carrid = sflight~carrid
      AND spfli~connid = sflight~connid
      INNER JOIN sbook
      ON spfli~carrid = sbook~carrid
      AND spfli~connid = sbook~connid.
    Thanks,
    Yawa

  • Using SELECT INTO statement to transfer data from one DB to another?

    Hello,
    I need to move data from an SAP table to another downstream SQL server box without flat file in between. I have set up the DBCON interface, so that my ABAP code on SAP can connect to the remote SQL Server, then I can run INSERT command as Native SQL inside the ABAP.
    However, INSERT has performance problem. The best performer as I can find is SELECT INTO statement. But then I am stuck at how to use SELECT INTO to query my local SAP table and send (via INTO) to remote database. I am not even sure whether I should use Open SQL or Native SQL.
    Any suggestion? BTW, I understand the limitation of Native SQL, but we are OK to use it.
    Thanks!

    It appears that this is some kind of migration project due to the scope of the data contained in the single file? If so whatever you do is like ly to be trow away once the migration of data is completed.
    You have a couple of options:
    1) Get the data extracted from HFM in multiple files instead of one bulk file, broken down by scanario,year & period
    2) Take the single data dump file produced by FDM and manipulate it yourself to get the data in a more usuable format for processing through FDM.
    Option 2 could be achieved via any ETL tool or a custom file parsing script. What may be more attractive to you and allow you to fully leverage your investment in FDM is that you could use the PULL adapter that ships as part of the FDM adapter suite to perform this transformation exercise. The PULL adapter takes a flat file input and allows you to use all the in built functionality of FDM to transform it and output a modified flat file (or series of flat files). You could use it to produce multioload files or a series of files broken down by scenario,year,period.
    Whatever you do I would suggest that break the single data file down into smaller chunks as this will help with the iterative debugging process you will inevitably have to undetake whislt migrating the data to the new application.

  • How to modify Logical database Selection screen

    I am using PNP logical database , it is giving one selection screen ,
    after executioni can able to change the selection screen but i want to change default selection screen so that when i execute i want specific fields in selection.
    How to modify it?

    Hi,
    You need to use report category.In the attributes,click HR report category and select or create the selection screen you need.
    Check this link.
    http://www.sapdevelopment.co.uk/hr/hr_repcat.htm
    Kindly reward points by clicking the star on the left of reply,if it helps.

  • How to modify stored procedures in SQL Azure database in SQL server express 2012

    Hi,
    I want to modify stored procedures in SQL Azure database in SQL Server Express 2012. But when right click on the stored procedure in Object Explorer, there is no option "Modify" as for SQL Server database. I wonder how to modify stored procedures in SQL
    Azure database in SQL Server Express 2012. Thanks.
    York

    Hi,
    Not sure whay there is no modify..
    As a workaround can you try this and see if you can modify proc..
    Script Procedure As-> Alter To->New query window..
    - Chintak (My Blog)

  • Can i include variable in select into statement?

    Hi all,
    Is it possible to include a variable name in the "select into" statement ? For ex:
    "Select empname into variable_Name from employee" In this case variable_Name is the variable.Will this statement work by assigning empname to variable_Name if there is only one record in the employee table?please reply....c ya.

    Surely you have to? You can hardly SELECT INTO a constant. Perhaps I'm missing something,

  • Where clause in SELECT INTO statement

    Hi,
    I am using multiple conditions in where clause for my SELECT INTO statement as follows.
    SELECT count(DTLA.LOCATION_ID)
    INTO LOCATION_ID_count
    FROM DOC2_MGR.DOC_TYPE_LOB_ASSOC DTLA
    WHERE (DTLA.DOC_TYPE_ID = 'XYZ' AND DTLA.lob_code = 'ABC');
    It considers only first condition and returns the result i.e. DTLA.DOC_TYPE_ID = 'XYZ' only.
    Does select into statement suppose to consider only one condition in where clause???
    Thanks in advance!
    --Sandeep                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I got it resolved. Here is list of things I noted
    1. I was using variable names same as column names. It was mixing up temp variable names with column name on the table, which doesn't make sense as I was referring column names in table.column format
    2. I had mixed few datatypes. Input param was suppose to be number where as I was passing it as Text
    Thanks anyway!
    --Sandeep                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How do I scan multiple pages into one document using the CanoScan LiDE 200?

    How do I scan multiple pages into one document using the CanoScan LiDE 200?
    I can't seem to find a way to get them to scan continuously, or a way to stitch them together afterwards.

    Hi dagda24,
    You can scan multiple pages into a single document with the scan to PDF option.  Use the following steps to do so:
    1.  Open MP Navigator.
    2.  Click One Clcik.
    3.  Click Save to PC.
    4.  Change the File Type from PDF to PDF (multiple pages).
    5.  Make any other changes as needed, then click scan.
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • How to update transaction data automatically into MySQL database using PI

    Dear All,
    With reference to subject matter I want a sincere advice regarding how to update transaction data automatically into MySQL database using PI. Is there any link available where I can get step-by-step process.
    Ex: I have a MYSQL database in my organization. Whenever a delivery created in SAP some fields like DO Number, DO quantity, SO/STO number should get updated in MYSQL database automatically.
    This scenario is related to updation of transactional data into MYSQL DB and I want your suggestions pertaining to same issue.
    Thanks and Regards,
    Chandra Sekhar

    Hi .
    Develop a sceanrio between SAP to Database system,When the data updates in SAP Tables read the data and update it in DATA Base using JDBC adapter,but there will be some delay in updating data in MySQL.
    serach in sdn for IDOC-TOJDBC sceannario,many documents available for the same.
    Regards,
    Raja Sekhar

  • How do I separate a PDF into multiple PDFs using Adobe PDF Pack?

    How do I separate a pdf into multiple pdfs using AdobePack?
    [Title edited to reflect actual product name... Mod]

    I do not find "AdobePack" when I look at the list of forums https://forums.adobe.com/welcome
    What is the exact name of the program you are using... Acrobat, or are you using the online version at Acrobat.com?
    ADDED... found Adobe PDF Pack (read only) so will move this message

  • How to modify the Procedure which exists in Package individually?

    Hi,
    I need to modify the procedure which exists in package individually. I.e. I don't want to recompile the entire package.
    This task to be done in SQL Plus not in TOAD. Because in TOAD, we can directly place the script and recompile using the option.
    Do we have any syntax to modify the procedure which exists in package?
    [Like.....     create or replace schema.packagename.procudrename....etc...?]
    Kindly reply if you are not clear on my query.
    Kindly help me on this.

    Explain the reason why this would make any sense. Convenience. I wouldn't mind this option either.
    1) Currently, i am working on a PACKAGE which has
    over 2k lines. In general, changes are made in a
    single PROCEDURE only. I then copy the code (from
    notepad) and paste it into SQL*Plus. This takes a few
    seconds. If i could just ALTER the one PROCEDURE, it
    would save time. (The little adds up to a lot during
    testing.)
    2) If two developers want to modify the two parts of
    the same PACKAGE they would have to rename the
    PACKAGE so one's changes do not overwrite the other.
    Allowing to change the particular PROCEDURE inside
    the PACKAGE would obviate this need.
    3) If PACKAGES are to be stored in a versioning
    system, it might be convenient to store each
    PROCEDURE separately, instead of storing the entire
    PACKAGE as one file.
    It is certainly not required, but it would be a nice
    convenience. That is why it would make sense.OK, then why did you chose to make packages? You do realize you can make stand alone procedures / functions outside of packages don't you?
    I can see how 2 seconds of waiting for a package to compile could set your testing back by weeks (warning, being highly sarcastic).

  • How to add a filter/selection into the report title?

    Hi experts,
    Currently I try to fugure out how to set up a field into the page header (title) of a report in order to dynamically adapt the title to selected filter criteria. I tried to use the Reprot Filter Summary, but since I do have several sheets in my reports the information given through it is not applicable.
    What I would like to achieve is that the end user can select e.g. a category X and Y and the title says: "Report title - categories: X,Y" Somthg like this. I'd appreciate any tips.
    Best regards

    Hi guys,
    thanks so far. I managed to show prompts in the report. But still my problem is nor 100% solved
    I would like t achieve that the filtered criteria in the report title is separated through a comma like in the report filter summary - e.g.: {001, 002, 003, 004} followed by just 1chart/table that is including the whole information.
    When I however just drag a variable into the report it automatically created different sections, right? Like ........ table, chart, whatever... .......table chart whatever........
    Regards

  • Select Into statement in db function - query from granted schema table

    problem with "select into" in db function in 10.2
    There are two schemas. 'mdbdev' is the master database and 'devusr' is granted SELECT table access to execute queries in mdbdev schema.
    with devusr, in SQL, I'm able to execute the following query
    select wm_concat(strConcatedCountryList)
    from (select country_name as strConcatedCountryList from mdbdev.country_master mdbcm
    where mdbcm.country_ship_status = <param?>
    order by country_name)
    but when I use the same query in function/procedure with "select into", the compilation failed with error *"table or view does not exist"*
    FUNCTION GETCOUNTRYLISTTOSHIP (SHIP_STATUS IN NUMBER)
    RETURN VARCHAR2
    IS
    var2CountryList VARCHAR2(1000);
    BEGIN
    select wm_concat(strConcatedCountryList) INTO var2CountryList
    from (select country_name as strConcatedCountryList from mdbdev.country_master mdbcm
    where mdbcm.country_ship_status = <value of SHIP_STATUS>
    order by country_name);
    return var2CountryList;
    END;
    Please advise/help/hint :)

    David, Justine, Thank you. The facts from this forum post helped a lot to get the solution.
    The query helped a lot (select * from all_tab_privs_recd where owner = 'MDBDEV' and table_name = 'COUNTRY_MASTER").
    there was a grant using ???(donno wht DBA said) and no direct SELECT grant on that country_master to "devusr". grant command executed. Now, it works :)

  • SELECT INTO statement

    Hello
    I have entered the following statement into the SQL Command Processor in HTML Db:
    select * into DEMO_CUSTOMERS_COPY from DEMO_CUSTOMERS
    I get the following error:
    ORA-00905: missing keyword
    Can anyone tell me why I'm getting this error? I think the syntax of the statement looks ok to me but I may be wrong
    Thanks,
    Simon

    Hi Simon,
    No problem...glad to help.
    Your original command (with a little modification) is the sort of thing you usually see in PL/SQL where you want to extract a column (or record) from a table, for example
    SQL> set serveroutput on;
    SQL>  declare
       v_value dual.dummy%TYPE;
    begin
      select
        dummy
      into
        v_value
      from dual;
      dbms_output.put_line('The value is: ' || v_value);
    end;
    The value is: XNote that "select..into" requires only one row to be returned, so if multiple rows are returned then you'll get a TOO_MANY_ROWS exception.
    Hope this helps.

  • How can I integrate add-ons into a PDF (Use Adobe Acrobat (in Firefox), such as Babylon English Dictionary?

    How can I integrate the Fox add-ons into a PDF (Use Adobe Acrobat (in Firefox), such as Babylon English Dictionary? Many PDF do support my add-ons. BTW, the PDF in question is one that I have uploaded to my web site.

    Babylon would need to support Adobe Acrobat for that to happen.

Maybe you are looking for

  • Internal error occured when writing

    Hi all I successfully imported an APO planning area into the quality systems, however the same request ends with error 12 in the production system. Landscape is SCM 5.0 sp8 with BI 7.0 sp12. When i checked the import job RDDEXECL (user DDIC), it show

  • How do I set up a BT email account?

    I'm going round and round in circles trying to set up my first BT email account. Please can someone tell me how to do this. I logged a request with support a week ago but never had a reply, which is annoying. When I click on email in My BT all I get

  • Financial Report Templates - Creation and input of accounts

    Hi, At the time of creating Financial Report Templates, these templates can be very time consuming and tedious to create, as for the inputting of accounts within each account category - filling out one or more details... It would be helpful to have s

  • Stereo V. Mono Track

    By all means, someone please direct me to the thread if this has already been covered (which, being that it seems soooo basic, I wouldn't doubt that it has been). I've been selecting all my tracks as stereo. What's the difference/pros and cons? I rea

  • Tables in SQL DEVELOPER DATA MODELER seem to be read only and have a chain symbol in the upper left

    I have a bunch of tables in my data model.  I have three relational models defined in this file.  In one of the models, all the tables seem to be read only.  They all have a chain in the upper left hand corner of their box. I am not using version con