TEXT_IO/cursor problem - Appropriate SELECT...INTO.. returns no rows!

Hi,
I have a button on a form which, when pressed, uses the built-in "GET_FILE_NAME" to locate a comma-delimited flat file. I use TEXT_IO to open the file and process the rows in a FOR LOOP. In the loop, I parse each comma delimited field into it's own variable. One of these fieldsis a week-ending-date, which is converted to a DATE variable. I need to get the year and week # from a support table called "Week" (I could justget the year from the date, but the week number is arbitrary when crossing over years). I have tried using a SELECT..INTO statement and an explicit cursor with the same results - none. The select into I use is:
SELECT year, week
INTO v_year, v_week
FROM schema1.week
WHERE TRUNC(end_date) = TRUNC(v_edate);
--where v_year and v_week are the same %TYPE as their corresponding columns
-- and v_edate is the week-ending-DATE from the flat file
When I do this from SQL*PLUS, it comes out fine, but no data is found when run in the form. I don't get it... if there is nothing wrong with the syntax, shouldn't this work in both places? Or is there some limitation on using cursors while processing a TEXT_IO file? If anyone knows the why of this or can think of a workaround, please let me know.
Oracle Version: 8.1.7.0.0
Server: IRIX - Unix
Forms Version: 6.0.5.35.3
Client: Win 98
Thanks much,
Jason

DECLARE
     v_filename VARCHAR2(100);
     temp_file TEXT_IO.File_Type;
     linebuff VARCHAR2(1800);
     v_edate DATE;
     v_year schema1.week.year%TYPE;
     v_week schema1.week.week%TYPE);
     str_start NUMBER;
     str_end     NUMBER;
     CURSOR week_cur (p_edate IN DATE) IS
          SELECT year, week
          FROM schema1.week
          WHERE TRUNC(end_date) = TRUNC(p_edate);
BEGIN
     v_filename := GET_FILE_NAME ('c:\files\');
     temp_file := TEXT_IO.Fopen (v_filename, 'R');
     FOR i IN 1..3 LOOP
          TEXT_IO.Get_Line (temp_file, linebuff);
          IF i > 1 THEN
               GO_BLOCK ('DATA_DUMP');
               NEXT_RECORD;
          END IF;
          str_end := INSTR(linebuff, ',') - 1;
          :DATA_DUMP.stnum := SUBSTR (linebuff, 1, str_end);
          str_start := str_end +2;
          str_end := INSTR(linebuff, ',', 1, 2);
          :DATA_DUMP.dnum := SUBSTR (linebuff, str_start, str_end - str_start);
          str_start := str_end +1;
          str_end := INSTR(linebuff, ',', 1, 3);
          :DATA_DUMP.spp := SUBSTR (linebuff, str_start, str_end - str_start);
          str_start := str_end +1;
          str_end := INSTR(linebuff, ',', 1, 4);
          v_edate := TO_DATE (SUBSTR(linebuff, str_start, str_end - str_start), 'MM/DD/YYYY');
          str_start := str_end +1;
          str_end := INSTR(linebuff, ',', 1, 5);
          :DATA_DUMP.lbs_land := SUBSTR (linebuff, str_start, str_end - str_start);
          str_start := str_end +1;
          str_end := LENGTH(linebuff);
          :DATA_DUMP.date_in := TO_DATE (SUBSTR(linebuff, str_start, str_end - str_start), 'MM/DD/YY HH:MI');
          OPEN week_cur (v_edate);
               FETCH week_cur INTO v_year, v_week;
          CLOSE week_cur;
          :DATA_DUMP.year := v_year;
          :DATA_DUMP.week := v_week;
     END LOOP;
END;          

Similar Messages

  • Problem with database control returning multiple rows as Array  using Oracle

    Has anybody using Oracle gotten a Database control that
    returns multiple rows to work returning an array?
    The only way I can seem to return multiple rows is by returning
    a RowSet. Returning an array gives me a NullPointerException
    (when called within a pageFlow). When calling a database control
    that returns an array from a web service I get a
    "java.sql.SQLException: ResultSet has no more data." error.
    The samples using the pointbase database seem to work, but when I
    converted the CustomerDBClient web service to use Oracle, it starts
    failing on calling the database control that returns an array
    with: "java.sql.SQLException: ResultSet has no more data."
    Has anybody gotten this to work using Oracle?
    I'm also having some problem returning an Iterator. It seems
    to work when called from a web service, but returns nothing
    if called from a page flow.
    I'm using Oracle 8.1.7 and WebLogic 8.1.
    Eric

    Do you need a particular service pack installed to return an array of custom object?
    I am getting a ResultSet contained no data error when trying.
    Thanks,
    -Thomas
    "Robin Karlin" <[email protected]> wrote:
    >
    Eddie O'Neil <[email protected]> wrote:
    All--
    Unfortunately, returning an Iterator to a JPF (or JSP) from a
    database control is broken in WLW 8.1, though it will work inside of
    a
    JWS or JCS.
    There shouldn't be a problem with returning an array of objects out
    of Oracle to the JPF, and if you need an Iterator specifically, youcan
    wrap the array in an Iterator implementation.
    Sorry for the inconvenience.
    Eddie
    Lenny wrote:
    I have gotten it to work on Oracle using Array:)
    However, I haven't gotten it to work on Oracle using Iterator:( Itis so
    simple, but doesn't work:(
    "Eric Dokken" <[email protected]> wrote in message
    news:[email protected]...
    Has anybody using Oracle gotten a Database control that
    returns multiple rows to work returning an array?
    The only way I can seem to return multiple rows is by returning
    a RowSet. Returning an array gives me a NullPointerException
    (when called within a pageFlow). When calling a database control
    that returns an array from a web service I get a
    "java.sql.SQLException: ResultSet has no more data." error.
    The samples using the pointbase database seem to work, but when I
    converted the CustomerDBClient web service to use Oracle, it starts
    failing on calling the database control that returns an array
    with: "java.sql.SQLException: ResultSet has no more data."
    Has anybody gotten this to work using Oracle?
    I'm also having some problem returning an Iterator. It seems
    to work when called from a web service, but returns nothing
    if called from a page flow.
    I'm using Oracle 8.1.7 and WebLogic 8.1.
    Eric
    I get the same error that Eric reported when trying to return an Array
    of objects.
    It is really frustrating because I can't use much of the built-in control
    logic
    that WLW provides. All I did was create a data pool for Oracle and a
    datasource.
    I modified the sample app in C:\bea81\weblogic81\samples\workshop\SamplesApp\WebApp\callJavaControl
    to point to that datasource and I get the error that Eric reports above.
    Can
    anyone help me out????
    Thanks,
    Robin

  • How to select 0's when a select statement returns no rows

    Hi,
    I'm using the following query in one of the report.
    SELECT mtrl.inventory_item_id
         ,mtrl.organization_id
         ,mtrl.to_subinventory_code
         ,NVL(SUM(mtrl.quantity),0)quantity
         ,NVL(SUM(mtrl.quantity_delivered),0)quantity_delivered
    FROM mtl_txn_request_lines mtrl, mtl_system_items_b msi
    WHERE mtrl.inventory_item_id = msi.inventory_item_id
    AND mtrl.organization_id     = msi.organization_id
    AND mtrl.reference_type_code = 2
    AND UPPER(mtrl.TO_subinventory_code) = NVL(UPPER(DECODE(:p_sub_inv,'ALL','',:p_sub_inv)),UPPER(mtrl.TO_subinventory_code))
    AND TRUNC(mtrl.CREATION_date) BETWEEN NVL(TRUNC(TO_DATE(:p_from_date,'yyyy/mm/dd hh24:mi:ss')),TRUNC(mtrl.CREATION_DATE) )
    AND NVL(TRUNC(TO_DATE(:p_to_date,'yyyy/mm/dd hh24:mi:ss')),TRUNC(mtrl.CREATION_DATE))
    GROUP BY mtrl.inventory_item_id,
         mtrl.organization_id,
         mtrl.to_subinventory_code
    For the perticular subinventory in that period there may not be data so the query returns no rows(ALL NULLs) in that case I need to get all 0's instead of NULL.
    I tried with UNION but it results in extra row when there is data. I need 0's only when the above query returns no rows.
    Any help in this regard is highly appreciated.

    My report uotput looks like this:
    Subinventory | Part Code |Part Description |Ordered Qty | Received Qty
    Mentone St | BATT | non serialised item | |
    Mentone St | SONY | spare parts MIN MAX | 30| 0
    In the above report
    subinventory, Part Code, Part description are in one repeating frame and Ordered and received qty are in other repeating frame.
    for a perticular part code there may not be ordered or received quantities. in that case report is showing null(blank) but I want to print ZERO there.
    If I use NVL in the query it'll effect only when the query fetches some rows.

  • Problem with SELECT INTO Query

    Why am I always getting 0 for returnvalue in the following query?
    create or replace
    PACKAGE BODY MyPKG AS
    PROCEDURE SelectCount
       returnvalue       OUT      INTEGER
    AS
      BEGIN
    select COUNT(*) from MyTable into returnvalue;
    IF( SQL%ROWCOUNT >= 1 )
      THEN
        returnvalue := 1;
      ELSE
        returnvalue := 0;
      END IF; 
    dbms_output.put_line('returnvalue: ' || returnvalue);
    END SelectCount;
    END MyPKG ;

    Hi,
    When you use an aggregate function, such as COUNT, without a GROUP BY clause, then the query is guaranteed to return exactly 1 row, regadless of whether there are any rows in the table or not.
    Perhaps you meant:
    create or replace
    PACKAGE BODY MyPKG AS
    PROCEDURE SelectCount
       returnvalue       OUT      INTEGER
    AS
      BEGIN
          select COUNT(*) from MyTable into returnvalue;
          dbms_output.put_line('returnvalue: ' || returnvalue);
      END SelectCount;
    END MyPKG ;
    that is, simply lose the IF block.

  • Cursor problem - intermittent selecting and moving cursor left and up

    Hi there. I have an intermittent problem. It doesn't happen all the time. It seems to happen when my mac has been on for say longer than half an hour. When I use either the trackpad or mighty mouse to select something, say a folder which has 10 files in it. If I click on the file at the bottom, it automatically selects the files above it and to the left. Its like someone is pressing the move left arrow and move up arrow on the keyboard. It also happens say if I wish to type in an url in safari, the cursor constantly moves left and all these problems make it useless to use. It doesn't happen all the time. I have checked the battery and it seems normal looking, and I have reinstalled osx but it still happens. Would the arrow keys on the keyboard be stuffed or trackpad?

    Hi there. This is already ticked, and I have tried it ticked and unticked, so that doesn't fix the problem, but thanks for trying. I actually left it with a mac repair man and he looked at it all weekend, but the problem didn't display for him, so thats frustrating! I need to try something else.

  • 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 :)

  • Dynamic column name with SELECT INTO

    I am trying to build a function that derives a pay amount from a set of business rules. There are about 40 columns that hold various pay amounts and their column names are variations of 4 indicators (day shift, vs night shift, etc.) that I have to dynamically look up, ie here is the ID number and a timecard, now figure out which of the 40 fields to look up to get the pay amount.
    I can determine from the timecard and employee ID which field to look at, but I'm getting hung up with the syntax needed to construct and execute the statement inside the PL/SQL block. I need to RETURN the pay I extract using the function, and I can create the correct SQL statement, but the EXECUTE IMMEDIATE won't accept the SELECT INTO syntax.
    Can someone please suggest a solution? Here is the function:
    create or replace FUNCTION FN_GET_PAYRATE(tc in NUMBER, e in NUMBER, pc in VARCHAR2)
    RETURN NUMBER
    IS
    e_id NUMBER;
    tc_id NUMBER;
    pl_cd VARCHAR2(7);
    shft VARCHAR2(2);
    lvl VARCHAR2(2);
    typ VARCHAR2(2);
    e_typ VARCHAR2(4);
    proj NUMBER;
    hrly VARCHAR2(4);
    payrt NUMBER;
    var_col VARCHAR2(10);
    sql_select VARCHAR2(200);
    sql_from VARCHAR2(200);
    sql_where VARCHAR2(200);
    sql_and1 VARCHAR2(200);
    sql_and2 VARCHAR2(200);
    sql_and3 VARCHAR2(200);
    sql_orderby VARCHAR2(200);
    var_sql VARCHAR2(2000);
    BEGIN
    e_id := e;
    tc_id := tc;
    pl_cd := pc;
    SELECT NVL(SHIFT,'D') INTO shft
    FROM TS_TIMECARD_MAIN
    WHERE TIMECARD_ID = tc_id;
    --DBMS_OUTPUT.PUT_LINE('SHIFT= ' || shft);
    SELECT NVL(PAY_LVL, 1), NVL(PAY_TYPE, 'B'), NVL(RTRIM(EMP_TYPE), 'LHD'), NVL(PROJECT, 001)
    INTO lvl, typ, e_typ, proj
    FROM TS_EMPLOYEES
    WHERE EMP_ID = e_id;
    --DBMS_OUTPUT.PUT_LINE('Level= ' || lvl);
    --DBMS_OUTPUT.PUT_LINE('PAY_TYPE= ' || typ);
    --DBMS_OUTPUT.PUT_LINE('EMP_TYPE= ' || e_typ);
    --DBMS_OUTPUT.PUT_LINE('PROJECT= ' || proj);
    IF e_typ <> 'LHD' THEN
    hrly := 'H';
    ELSE
    hrly := '';
    END IF;
    IF proj <> 001 THEN
    var_col := shft || lvl || typ || hrly;
    --DBMS_OUTPUT.PUT_LINE('RATE COLUMN= ' || var_col);
    sql_select := 'SELECT NVL(' || var_col || ', .01) INTO payrt';
    sql_from := ' FROM TS_PAYRATES';
    sql_where := ' WHERE PROJECT_ID = ' || proj;
    sql_and1 := ' AND ACTIVE = 1';
    sql_and2 := ' AND JOB_TYPE = ' || CHR(39) || e_typ || CHR(39);
    sql_and3 := ' AND PILE_ID = ' || CHR(39) || pl_cd || CHR(39);
    var_sql := sql_select || sql_from || sql_where || sql_and1 || sql_and2 || sql_and3 || sql_orderby;
    DBMS_OUTPUT.PUT_LINE('SQL: ' || var_sql);
    EXECUTE IMMEDIATE var_sql;
    DBMS_OUTPUT.PUT_LINE('RATE= ' || payrt);
    RETURN payrt;
    ELSE
    DBMS_OUTPUT.PUT_LINE('ERROR');
    RETURN 1;
    END IF;
    END;
    I have alternately tried this:
    SELECT NVL(var_col,.01) into payrt
    FROM TS_PAYRATES
    WHERE PROJECT_ID = proj AND ACTIVE = 1
    AND JOB_TYPE = CHR(39) || e_typ || CHR(39)
    AND PILE_ID = CHR(39) || pl_cd || CHR(39);
    as a substitute for the EXECUTE IMMEDIATE block, but I can't seem to use a dynamic substitution for the column name.
    Any help would be greatly appreciated.

    That's the most difficult part - the error messages seem to indicate a problem with the SQL statement in its execution context, because I can take the SQL string by itself and it executes perfectly.
    Here are three variations:
    SELECT INTO
    select fn_get_payrate(21555, 30162, 15) from dual
    ERROR at line 1:
    ORA-00905: missing keyword
    ORA-06512: at "PEOPLENETIF.FN_GET_PAYRATE", line 60
    SQL: SELECT NVL(N4P , .01) INTO payrt FROM TS_PAYRATES WHERE PROJECT_ID = 701 AND ACTIVE = 1 AND JOB_TYPE = 'LHD' AND PILE_ID = '15'
    Without SELECT INTO  (returns NULL)
    SQL> select fn_get_payrate(21555, 30162, 15) from dual;
    FN_GET_PAYRATE(21555,30162,15)
    SQL: SELECT NVL(N4P , .01) FROM TS_PAYRATES WHERE PROJECT_ID = 701 AND ACTIVE = 1 AND JOB_TYPE = 'LHD' AND PILE_ID = '15'
    RATE=
    EXECUTE IMMEDIATE USING
    SQL> select fn_get_payrate(21555, 30162, 15) from dual;
    select fn_get_payrate(21555, 30162, 15) from dual
    ERROR at line 1:
    ORA-01006: bind variable does not exist
    ORA-06512: at "PEOPLENETIF.FN_GET_PAYRATE", line 61
    SQL: SELECT NVL(N4P , .01) FROM TS_PAYRATES WHERE PROJECT_ID = 701 AND ACTIVE = 1 AND JOB_TYPE = 'LHD' AND PILE_ID = '15'

  • Simple join question - my query is returning unwanted rows ...

    My SQL select is returning more rows that I want it to return. The table that I'm joining on has multiple rows per CaseId, and I'm only interested in getting one...
    table1
    CaseId     column1     column2
    8     elmo          foz
    9     foo          bar
    10     fuz          baz
    11     fuy          bay
    table2
    CaseId     Seq     column8     column9
    8     1     choc          strawberry
    9     1     banana          orange
    9     2     do          re
    10     1     me          fa
    So a SQL select like:
    select t1.CaseId, t1.column1, t1.column2, t2.column8
    FROM table1 t1 LEFT OUTER JOIN table2 t2
    ON t1.CaseId = t2.CaseId
    returns data like:
    t1.CaseId     t1.column1     t1.column2     t2.column8
    8          elmo          foz          choc
    9          foo          bar          banana
    9          fuz          baz          do
    I want the SQL select to return only one row for each row that’s in table1; CaseId of 9 should have only one row in the SQL select results.
    The table2 has multiple rows, because of the Seq column. How can I formulate the SQL select to join on table2 using CaseId and the max Seq value?
    Thank you!

    Untested..
    with t1 AS
            (SELECT *
               FROM (SELECT table2.*,
                            ROW_NUMBER ()
                               OVER (PARTITION BY caseid ORDER BY seq DESC)
                               r
                       FROM table2)
              WHERE r = 1)
    SELECT t1.CaseId,
           t1.column1,
           t1.column2,
           t2.column8
      FROM table1 t1 LEFT OUTER JOIN t1 t2 ON t1.CaseId = t2.CaseId;OUTPUT:
    CASEID     COLUMN1     COLUMN2     COLUMN8
    8     elmo     foz     choc
    9     foo     bar     do
    10     fuz     baz     me
    11     fuy     bay     Cheers,
    Manik.

  • I'm having problems (1)selecting onscreen text, (2) having problems resizing menu boxes and selecting menues with the cursor. I'm not able to select menus and move them. I'm not sure how to correct this.

    I'm having problems (1) selecting onscreen text, (2) resizing menu boxes and selecting menues with the cursor. I'm not able to select menus and move them. I'm not sure how to correct this.

    1) This is because of software version 1.1. See this
    thread for some options as to how to go back to 1.0,
    which will correct the problem...
    http://discussions.apple.com/thread.jspa?threadID=3754
    59&tstart=0
    2) This tends to happen after videos. Give the iPod a
    minute or two to readjust. It should now be more
    accurate.
    3) This?
    iPod shows a folder icon with exclamation
    point
    4) Restore the iPod
    5) Try these...
    iPod Only Shows An Apple Logo and Will Not Start
    Up
    iPod Only Shows An Apple Logo
    I think 3,4, and 5 are related. Try the options I
    posted for each one.
    btabz
    I just noticed that one of the restore methods you posted was to put it into Disk Mode First rather than just use the resstore straight off, I Have tried that and seems to have solved the problem, If it has thank you. previously I have only tried just restoring it skipping this extra step. Hope my iPod stays healthy, if it doesnt its a warrenty job me thinks any way thanks again

  • MS-SQL - Oracle SELECT INTO conversion problem...

    Under MS-SQL (T-SQL) Select statement is defined as follows:
    SELECT select_list
    [INTO new_table_]
    ^^^^^^^^^^^^^^^^^^^^^
    FROM table_source
    [WHERE search_condition]
    [GROUP BY group_by_expression]
    [HAVING search_condition]
    [ORDER BY order_expression [ASC | DESC] ]
    Q:How under PL/SQL can one redirect sorted (ORDERed BY) results
    from SELECT query to another table.
    Slawek
    null

    I have asked the question because of the following reason:
    I have a large select query that returns rows from a table in
    different sort orders depending on user inputs, and I wonder if
    there is any way to return just the rows between two specified
    positions.
    I figured that I'm going to either create one temporary table
    with all the data (1000 records for example), sort the data in
    the prefered order and use the rownum method to obtain the row
    range (works fine under T-SQL). Other way is to try an inline
    view that return the rownumber. I can then restrict the numer of
    fields, e.g.
    select empid, rowNumber from emp,
    (select empid as id, rownum as rowNumber from emp) x
    where empid = id
    and rowNumber between 2 and 5
    The problem is that under Oracle the subquery is not allowed to
    have an ORDER BY clause (even if it had, rownum reflects row
    numbers before they were sorted) and there is no SELECT into
    TABLE_NAME.
    Michael Malicky (guest) wrote:
    : Slawek (guest) wrote:
    : : Under MS-SQL (T-SQL) Select statement is defined as follows:
    : : SELECT select_list
    : : [INTO new_table_]
    : : ^^^^^^^^^^^^^^^^^^^^^
    : : FROM table_source
    : : [WHERE search_condition]
    : : [GROUP BY group_by_expression]
    : : [HAVING search_condition]
    : : [ORDER BY order_expression [ASC | DESC] ]
    : : Q:How under PL/SQL can one redirect sorted (ORDERed BY)
    results
    : : from SELECT query to another table.
    : : Slawek
    : Order by is irrelevant when creating a new table out of a
    : query, as the rows are NOT stored in any order in a table.
    : The syntax for creating a new table out of an existing one
    : is:
    : CREATE TABLE new_table AS
    : SELECT select_list FROM old_table
    : WHERE ...
    : etc.
    : /mike
    null

  • SELECT INTO clause strange problem

    Hi all,
    I need some help with a very strange select into statement.Select into throws NO DATA exception even if table has data.
    I am trying to invoke procedure from BPEL.Inside the procedure,I am trying to get "name' from definitions table.But it always throws Data NOT Found exception.But table has relevant data and i am able to see the data by executing the same query outside the BPEL environment/flow(SQL PLUS).
    Also,I kept dummy test table for Debugging purpose and it inserted with temp value '103'.
    My procedure looks like below
    temp:='103';
    INSERT INTO test
    VALUES ('Test-1' ||dummy,sysdate);
    commit;
    SELECT name
    INTO p_name
    FROM definitions
    WHERE id =temp;
    Please help me in this regards
    Thanks in advance.

    Hi Frank,
    Thanks for quick response.
    My actual query is
    dummy:=assume getting_valid_value from BPEL(also same dummy inserting into temp value);
    SELECT organization_code
    INTO p_warehousename
    FROM org_organization_definitions
    WHERE .organization_code = dummy;
    What are the schemas involved? APPS
    (Who owns the table?
    Who own the procedure? APPS
    Is it defined with "AUTHID CURRENT_USER"? NO IDEA
    Who runs it when you get the error? Thru BPEL actually
    What runs the same query in SQL*Plus and sees a row?). v*alid value(ALF)*
    I checked with low level security query as it returns nothing.
    thanks

  • 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

  • SELECT * INTO Problem

    I need help, please. I'm trying this basic statement to create a backup copy of the hr.employees table.
    SELECT * INTO employees_Backup FROM employees
    Which I copied from examples on the internet (two sources, same syntax)
    When I run this in SQL Developer, I get the following:
    ORA-00905: missing keyword
    00905. 00000 - "missing keyword"
    *Cause:   
    *Action:
    Error at Line: 1 Column: 14

    Hi,
    Houffle wrote:
    ... Now, if I can just learn to format my code when I post.This site normally doesn't display multiple spaces in a row.
    Whenever you post formatted text (such as query results) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Amount of open cursor problem

    I am trying to display a tree-like data with a varchar2 field called ancestor indicating its family nodes, e.g. 1:2:5:16. A quick solution would be recurssion:
    procedure data_list(id in number default null) as
    cursor c1 is select * from table1 where ancestor is null;
    cursor c2 is select * from table2 where get_parent(ancestor) = id;
    -- get_parent(varchar2) is a function return parent id of current data.
    if (id is null) then
    -- display root nodes
    -- open c1 and print out data
    -- then recursively call itself to print out its children
    data_list(id);
    close c1;
    else
    -- open c2 and print out data
    -- then recursively call itself to print out its childen
    data_list(id);
    close c2;
    end if;
    end data_list;
    ======================
    As you notice, the problem is that if the tree is too high (or too deep) the amount of cursors being open simultanously might be huge, which will definitely degrade the performance of the server, especially under multiuser environment.
    Does someone here have better solution for this problem?
    Thanks.

    You probably want to start by looking into Oracle's hierarchal query support with the CONNECT BY clause and the SYS_CONNECT_BY_PATH function. Grabbing a quick example from the Oracle SQL Reference http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/functions121a.htm#1038139
    SELECT LPAD(' ', 2*level-1)||SYS_CONNECT_BY_PATH(last_name, '/') "Path"
       FROM employees
       START WITH last_name = 'Kochhar'
       CONNECT BY PRIOR employee_id = manager_id;
    Path
    /Kochhar
       /Kochhar/Greenberg
         /Kochhar/Greenberg/Faviet
         /Kochhar/Greenberg/Chen
         /Kochhar/Greenberg/Sciarra
         /Kochhar/Greenberg/Urman
         /Kochhar/Greenberg/Popp
       /Kochhar/Whalen
       /Kochhar/Mavris
       /Kochhar/Baer
       /Kochhar/Higgins
         /Kochhar/Higgins/GietzNote that hierarchal queries work very well when you have tree data. If you actually have a graph, it starts to get more complicated.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • A SELECT into a procedure

    Hello,Can I show the result of a SELECT .. FROM.. WHERE.. into a procedure?
    For example:
    CREATE OR REPLACE PROCEDURE nuova_ricerca (p_Stringa VARCHAR2)
    AS
    BEGIN
    SELECT *
    FROM ArchivioSoluzioni
    WHERE Problema LIKE ConvertiPerLike(p_Stringa);
    END;
    why I can use
    SELECT * INTO DUMMYArchivioSoluzione.Camp1, DUMMYArchivioSoluzione.Camp2..
    If the result of my SELECT is constructed by 2 rows?
    p.s
    ConvertiPerLike is a simple function.
    excuse for my bad english

    Do not copy the record Operatore in emprec...Why?Because
    SELECT * INTO emprec
    FROM Operatore;
    potentially returns MANY records (see my above post). If you want
    to get the result you have to restrict the selection with WHERE caluse
    which gaurantees you select ONE row, NOT MANY.
    If you want to select many rows you have to think of the collection
    and BULK COLLECT INTO statement:
    SQL> create or replace procedure foo
      2  is
      3   type t1 is table of emp%rowtype index by pls_integer;
      4   t t1;
      5  begin
      6   select * bulk collect into t from emp;
      7  end;
      8  /
    Procedure created.
    SQL> exec foo;
    PL/SQL procedure successfully completed.or to think of the cursor using as it was pointed out above:
    SQL>/* Just for illustration */
    SQL> create or replace procedure foo
      2  is
      3   erc emp%rowtype;
      4  begin
      5   for v in (select * from emp) loop
      6    erc := v;
      7   end loop;
      8  end;
      9  /
    Procedure created.
    SQL> exec foo;
    PL/SQL procedure successfully completed.Rgds.

Maybe you are looking for

  • Preview in finder?

    I am importing audio clips into Final Cut. like this- Right clicking on audio bin selecting >import. finding audio clip and then having to import before i can listen to the clip. is there a way i can preview clips before importing. it seems like this

  • [SOLVED]Emerald/compiz draws window decoration around conky...

    Hi! I've recently installed conky for the first time ever and wish to use it as a simple clock. I have edited the .conkyrc to achieve this, however when I start conky, compiz draws the emerald theme around my conky clock. Having looked around the web

  • Programmable infrared (IrDA) sender and receiver for iPhone

    Hello, I want to communicate with the iPhone and a device which only supports infrared for communication, so I'm searching for a programmable infrared IrDA sender and receiver for the iPhone. It should be possible to communicate with the recommended

  • How to Determine the Shortest Distance

    It's been a while since I last pestered the group, but I'm back with a new problem. This one is not so much one I can't solve, but one that I can't solve gracefully. At times, doctors will leave our organization and that doctor's patients must be han

  • A Meeting automatically created for a past event

    Hi, Please assist with the following issue: The meeting organizer sent out a meeting request for our whole company on 28th June the meeting was for the 4th of July, everyone attended the meeting.  11 days later a user that did not accept the meeting