No data found in SELECT INTO

Hi all

I try to choose in a variable in a loop of cursor but I get NO DATA FOUND when
Select does not return a value.
I want to set the variable to 0 when the selection fails.

I tried to add an exception, but I get the following:

ORA-00900: invalid SQL statement


Here is the code I am trying to run (the exception is commented):

Line: -.
PROCEDURE MyProc IS
v_op NUMBER;
BEGIN

FOR cursor1 IN (select * from myTable)
LOOP
Operation of SELECTION IN v_op from operationsTable where id = cursor1.ID;


-EXCEPTION *.
-WHEN NO_DATA_FOUND THEN
-v_op: = 0;

-END; *

END LOOP;
MyProc END;
Line: -.

Does anyone know how to set a variable when the selection fails and NO DATA FOUND?
Thank you
dyahav

You need to hold your exception by BEGIN and END

BEGIN

select into...

EXCEPTION WHEN NO_DATA_FOUND
do_something
END;

Tags: Database

Similar Questions

  • No data found in the select statement error

    Hi all

    Find my sample table and data structure:
    SQL> desc states;
     Name                                                  Null?    Type
     ----------------------------------------------------- -------- ------------------------------------
     SNO                                                            NUMBER
     SNAME                                                          VARCHAR2(10)
    
    SQL> select*from states;
    
           SNO SNAME
    ---------- ----------
             1 kerala
             2 Tamil nadu
             3 AP
             4 MP
             5 jammu
    Now, I create a block like:
    declare
    v_state varchar2(20):=' AP';
    v_no number;
    begin
    select sno into v_no from states where sname=v_state;
    dbms_output.put_line(v_no);
    end;
    /
    After excecuting this block no data found error takes place.
    Coz in where defective condition. "AP"="AP."

    What oracle function I should use to eliminate this error.

    I tried something like
    where trunc(sname)=trunc(v_state);
    But it defective. Please help me

    / * Don't know what is your exact question, but: * /.

    use the TOPPING instead of TRUNC

    Published by: hoek on November 26, 2011 10:00

  • SELECT statement: no data found

    I have the following select statement:
    DECALRE
    
     l_customerID INTEGER :=0;
    
    BEGIN
    
     SELECT DISTINCT customer_id into l_customerID FROM customer where status = 'd';
    
    If  l_customerID = 0 then
    DBMS_OUTPUT.PUT_LINE('Not deactivated')
    else
    DBMS_OUTPUT.PUT_LINE('deactivated')
    end if;
    END
    /
    However, I got this error when he tried to enter this if statement when l_customerID = 0

    ORA-01403: no data found
    How to do in the stated case when l_customerID = 0 or should I change my select statement or what?

    Hi try this

         l_customerID INTEGER :=0;
    
    BEGIN
    
         select
              nvl((SELECT DISTINCT customer_id into l_customerID FROM customer where status = 'd'),'-1')
         from
              dual
    
    If  l_customerID = 0 then
         DBMS_OUTPUT.PUT_LINE('Not deactivated')
    else
         DBMS_OUTPUT.PUT_LINE('deactivated')
    end if;
    END
    / 
    

    It only works if the inner query will return a single line... If a return that one line will return the exception of other lines.

    Concerning
    Singh

  • Can I Insert fixed string in table select table data found?

    Hi all
    I have a table
    Create table student (student_name varchar2(10), student_id number(10),day varchar2(10),hours_studied number(10));
     
    insert into student values ('RON',12,'SUN',4);
    insert into student values ('RON',12,'MON',5);
    insert into student values ('RON',12,'TUE',6);
    insert into student values ('ZAP',13,'SUN',3);
    insert into student values ('ZAP',13,'MON',9);
    insert into student values ('ZAP',13,'TUE',10);
    insert into student values ('DEW',14,'SUN',4);
    insert into student values ('DEW',14,'MON',6);
    insert into student values ('DEW',14,'TUE',8);
    insert into student values ('PIKE',15,'SUN',2);
    insert into student values ('PIKE',15,'MON',1);
    insert into student values ('PIKE',15,'TUE',4);
    insert into student values ('TON',16,'SUN',30);
    insert into student values ('TON',16,'MON',2);
    insert into student values ('TON',16,'TUE',24);
    I have one more same table as before, but with an extra column
    Create table student1 (student_name varchar2(10), student_id number(10),day varchar2(10),hours_studied number(10)) month varchar2(10);
    Now, I want to insert data into the table 'student1' using the 'student', which includes the data.
    Insert into student1 values select * from student
    The above insert statement throws me an error "Not enough values" something like that...


    There is no primary key on the table. I last column of the table, "Student" 1 is standard, that is to say.., MAY for all lines.
    Can I write the query like this?
    Insert into student1 values select student_name,student_id,day,hours_studied,'MAY' from student;
    If this is not the case, how can I write the insert statement?

    Please let me know if it's confusing...

    Yes, it works, but need a correction of bit:

    Insertion in Student 1 select student_name, student_id, day, hours_studied, 'USA' of student

    you do not have the keyword "VALUES" in the "insert... Select...' statement."

  • No data found during execution of selection within a function

    Hello
    I have a select statement based on the USER_ROLE_PRIVS view for a specific granted_role and the user, if I run the statement in SQL/Plus I get the required result, however if I put the same selection in a function and run the function by the same user I get ora-00100 no data found. I run given to the public on the service. Is there a scholarship that I missed

    Any help would be great
    Tina

    If the execution of another schema, add a statement such as authid current_user

    create function f_authid_cu return number
      authid current_user
    as begin
      return 0;
    end f_authid_cu;
    /
    
  • The execution of the trigger, 01403 error. 00000 - "no data found".

    Hi guys, Pl/Sql

    When we try to run after initiation, as 01403 error. 00000 - "no data found".

    Trigger is

    CREATE OR REPLACE TRIGGER SYNC_OUGR_USER_ADDRESS

    AFTER INSERT ON OUGR_USER_ADDRESS FOR EACH LINE

    DECLARE

    P_CD_ADDR_TYPE OUGR_USER_ADDRESS. TYPE % CD_ADDR_TYPE;

    P_AD_CITY OUGR_USER_ADDRESS. TYPE % AD_CITY;

    CITY OF P_NM_NAME. TYPE % NM_NAME;

    P_FL_OVERSEAS OUGR_USER_ADDRESS. TYPE % FL_OVERSEAS;

    P_AD_COUNTRY OUGR_USER_ADDRESS. TYPE % AD_COUNTRY;

    P_TEMP_CITY VARCHAR2 (10);

    P_CD_CODE REF_COUNTRY_CODE. TYPE % CD_CODE;

    BEGIN

    P_CD_ADDR_TYPE: =: NEW. CD_ADDR_TYPE;

    P_FL_OVERSEAS: =: NEW. FL_OVERSEAS;

    P_AD_CITY: =: NEW. AD_CITY;

    P_AD_COUNTRY: =: NEW. AD_COUNTRY;

    SELECT LENGTH (TRIM (TRANSLATE (P_AD_CITY, ' + -. 0123456789', ' '))) IN THE DOUBLE P_TEMP_CITY; -to check if the value is numeric

    SELECT NM_NAME IN THE P_NM_NAME OF THE CITY WHERE ID_TOWN = P_AD_CITY;

    SELECT CD_CODE INTO P_CD_CODE FROM REF_COUNTRY_CODE WHERE CD_CODE = P_AD_COUNTRY;

    IF P_CD_ADDR_TYPE ('ma', 'PA') THEN

    IF P_TEMP_CITY IS NULL THEN

    P_AD_CITY: = P_NM_NAME;

    ON THE OTHER

    P_AD_CITY: = P_AD_CITY;

    END IF;

    ON THE OTHER

    P_AD_CITY: = P_NM_NAME;

    END IF;

    IF P_FL_OVERSEAS = "Y" THEN

    P_AD_COUNTRY: = P_CD_CODE;

    ON THE OTHER

    P_AD_COUNTRY: = P_AD_COUNTRY;

    END IF;

    INSERT INTO OUGR_USER_ADDRESS@TO_GVRS

    (ID_ADDRESS,

    CD_ADDR_TYPE,

    AD_UNIT,

    AD_NUM,

    AD_STR1,

    AD_STR2,

    AD_CITY,

    AD_COUNTY,

    AD_ST,

    AD_COUNTRY,

    AD_ZIP5,

    AD_ZIP4,

    FL_AD_RURAL,

    FL_OVERSEAS,

    TM_STAMP

    )

    VALUES (: NEW.ID_ADDRESS,)

    : NEW. CD_ADDR_TYPE,

    : NEW. AD_UNIT,

    : NEW. AD_NUM,

    : NEW. AD_STR1,

    : NEW. AD_STR2,

    P_AD_CITY,

    : NEW. AD_COUNTY,

    : NEW. AD_ST,

    P_AD_COUNTRY,

    : NEW. AD_ZIP5,

    : NEW. AD_ZIP4,

    : NEW. FL_AD_RURAL,

    : NEW. FL_OVERSEAS,

    : NEW. TM_STAMP

    );

    END SYNC_OUGR_USER_ADDRESS;

    /

    Greatly appreciate your help in this regard.

    Thanks in advance.

    Kind regards

    REDA

    Hi, Raj,

    Instead of

    SELECT LENGTH (TRIM (TRANSLATE (P_AD_CITY, ' + -. 0123456789', ' '))) IN THE DOUBLE P_TEMP_CITY; -to check if the value is numeric

    SELECT NM_NAME IN THE P_NM_NAME OF THE CITY WHERE ID_TOWN = P_AD_CITY;

    SELECT CD_CODE INTO P_CD_CODE FROM REF_COUNTRY_CODE WHERE CD_CODE = P_AD_COUNTRY;

    You can say:

    P_TEMP_CITY: = LENGTH (TRIM (TRANSLATE (P_AD_CITY, ' + -. 0123456789', ' ')));

    SELECT MIN (NM_NAME)

    IN P_NM_NAME

    OF THE CITY

    WHERE ID_TOWN = P_AD_CITY;

    SELECT MIN (CD_CODE)

    IN P_CD_CODE

    OF REF_COUNTRY_CODE

    WHERE CD_CODE = P_AD_COUNTRY;

    You don't need the double table much in PL/SQL.

    When you use an aggregate function (MIN, as above) without a clause GROUP BY, the result set is guaranteed to have exactly 1 row.  This also avoids the error (ORA-01422) TOO_MANY_ROWS, which is probably impossible in this example.

  • DAC 11.1.1.6.4 fails with the error cannot get columns: ORA-01403: no data found

    Hello

    We strive to run a full charge in DAC, but it is a failure.

    The S_ASSET table is empty and therefore, we get the error

    Could not get column: ORA-01403: no data found

    We were not facing this error in DAC 10 g but after upgrade to DCA 11 g, this task has no place if the array is empty. How remove this restriction and DAC will work perfectly even if the tables are empty to full charge?

    CAD DETAILS

    Console Administration Oracle BI DW

    CAD build a 11.1.1.6.4.20121119.2022 Build date: November 19, 2012

    Management Console to install, configure, and administer the Warehouse Analytics of Oracle Business

    Schema version - 47, Index version - 36, repository version - 6, data version Seed - 16

    INFORMATICA - VERSION9.0.1 HF2


    Here's the log of IMG_BUILD - S_ASSET when this task was running in DAC 10 g. The task facing any problem when S_ASSET table was empty.

    [code]

    2013-12-23 15:34:29.644 CHANGE CAPTURE: IMG_BUILD - internal S_ASSET began.

    the number of days of prunes: 4

    After change data capture: 2013-12-19 12:23:19.332 in full Mode.

    2013-12-23 15:34:29.69 - execution:

    TRUNCATE TABLE S_ETL_I_IMG_6

    2013-12-23 15:34:29.89 - executed successfully.

    2013-12-23 15:34:29.9 - execution:

    TRUNCATE TABLE S_ETL_R_IMG_6

    2013-12-23 15:34:30.145 - executed successfully.

    2013-12-23 15:34:30.16 - execution:

    TRUNCATE TABLE S_ETL_D_IMG_6

    2013-12-23 15:34:30.198 - executed successfully.

    2013-12-23 15:34:30.236 - execution:

    INSERT / * + APPEND * / INTO S_ETL_R_IMG_6

    (ROW_ID, MODIFICATION_NUM, LAST_UPD)

    SELECT

    ROW_ID

    MODIFICATION_NUM

    LAST_UPD

    Of

    S_ASSET

    WHERE

    LAST_UPD > TO_DATE ('2013-12-19 12:23:19 ',' ' YYYY-MM-DD HH24:MI:SS)

    2013-12-23 15:34:30.968 - executed successfully.

    2013 12-23 15:34:30.989 - execution of deleting duplicates rowid.

    2013-12-23 15:34:31.01 - successfully deleting duplicates rowid.

    2013-12-23 15:34:31.27 - execution:

    DROP VIEW V_ASSET

    2013-12-23 15:34:31.566 - executed successfully.

    2013-12-23 15:34:31.569 - execution:

    CREATE VIEW V_ASSET AS

    SELECT

    *

    Of

    S_ASSET

    2013-12-23 15:34:31.743 - executed successfully.

    2013-12-23 15:34:31.78 - execution:

    SELECT COUNT (*) IN S_ASSET

    The County is: 0

    Executed successfully: CHANGE CAPTURE: IMG_BUILD - internal S_ASSET

    (Number of attempts: 1).

    Executed orders:

    IMG_BUILD - internal

    2013-12-23 15:34:31.851 CHANGE CAPTURE: IMG_BUILD - internal S_ASSET has finished running with the completed state.

    The same task, IMG_BUILD - S_ASSET fails when it is running in DAC 11 g, because the table is empty. Here is the log for the failure of the task to 11g.

    [code]

    2013-12-27 21:21:47.497 acquisition of resources

    2013-12-27 21:22:20.33 acquired resources

    2013-12-27 21:22:20.787 CHANGE CAPTURE: IMG_BUILD - internal S_ASSET began.

    the number of days of plum: 5760

    After change data capture: 2013-12-23 21:19:19.233 in full Mode.

    21:22:21.211 2013-12-27 - execution:

    TRUNCATE TABLE S_ETL_I_IMG_6

    2013-12-27 21:22:22.384 - executed successfully.

    21:22:22.389 2013-12-27 - execution:

    TRUNCATE TABLE S_ETL_R_IMG_6

    2013-12-27 21:22:22.532 - executed successfully.

    21:22:22.534 2013-12-27 - execution:

    TRUNCATE TABLE S_ETL_D_IMG_6

    2013-12-27 21:22:22.546 - executed successfully.

    21:22:22.55 2013-12-27 - execution:

    INSERT / * + APPEND * / INTO S_ETL_R_IMG_6

    (ROW_ID, MODIFICATION_NUM, LAST_UPD)

    SELECT

    ROW_ID

    MODIFICATION_NUM

    LAST_UPD

    Of

    S_ASSET

    WHERE

    LAST_UPD > TO_DATE ('2013-12-23 21:19:19 ',' ' YYYY-MM-DD HH24:MI:SS)

    2013-12-27 21:22:22.614 - executed successfully.

    2013 12-27 21:22:22.616 - execution of deleting duplicates rowid.

    2013-12-27 21:22:24.72 - successfully deleting duplicates rowid.

    Could not get column: ORA-01403: no data found

    FAULT INFO: Error executing: CHANGE CAPTURE: IMG_BUILD - internal S_ASSET

    MESSAGE: com. Siebel.Analytics.etl.Execution.exceptions.ChangeCaptureTaskFailedException: Change Capture failed.

    EXCEPTION CLASS: java.lang.RuntimeException

    com.siebel.analytics.etl.etltask.GenericTaskImpl.doExecuteWithRetries(GenericTaskImpl.java:536)

    com.siebel.analytics.etl.etltask.GenericTaskImpl.execute(GenericTaskImpl.java:372)

    com.siebel.analytics.etl.etltask.GenericTaskImpl.execute(GenericTaskImpl.java:253)

    com.siebel.analytics.etl.etltask.GenericTaskImpl.run(GenericTaskImpl.java:655)

    com.siebel.analytics.etl.taskmanager.XCallable.call(XCallable.java:63)

    java.util.concurrent.FutureTask$ Sync.innerRun (FutureTask.java:303)

    java.util.concurrent.FutureTask.run(FutureTask.java:138)

    java.util.concurrent.Executors$ RunnableAdapter.call (Executors.java:441)

    java.util.concurrent.FutureTask$ Sync.innerRun (FutureTask.java:303)

    java.util.concurrent.FutureTask.run(FutureTask.java:138)

    java.util.concurrent.ThreadPoolExecutor$ Worker.runTask (ThreadPoolExecutor.java:886)

    java.util.concurrent.ThreadPoolExecutor$ Worker.run (ThreadPoolExecutor.java:908)

    java.lang.Thread.run(Thread.java:619)

    : CAUSE:

    MESSAGE: change Capture failed.

    EXCEPTION CLASS: com.siebel.analytics.etl.execution.exceptions.ChangeCaptureTaskFailedException

    com.siebel.analytics.etl.etltask.ChangeCaptureTask.executeChangeCapture(ChangeCaptureTask.java:93)

    com.siebel.analytics.etl.etltask.ChangeCaptureTask.doExecute(ChangeCaptureTask.java:46)

    com.siebel.analytics.etl.etltask.GenericTaskImpl.doExecuteWithRetries(GenericTaskImpl.java:477)

    com.siebel.analytics.etl.etltask.GenericTaskImpl.execute(GenericTaskImpl.java:372)

    com.siebel.analytics.etl.etltask.GenericTaskImpl.execute(GenericTaskImpl.java:253)

    com.siebel.analytics.etl.etltask.GenericTaskImpl.run(GenericTaskImpl.java:655)

    com.siebel.analytics.etl.taskmanager.XCallable.call(XCallable.java:63)

    java.util.concurrent.FutureTask$ Sync.innerRun (FutureTask.java:303)

    java.util.concurrent.FutureTask.run(FutureTask.java:138)

    java.util.concurrent.Executors$ RunnableAdapter.call (Executors.java:441)

    java.util.concurrent.FutureTask$ Sync.innerRun (FutureTask.java:303)

    java.util.concurrent.FutureTask.run(FutureTask.java:138)

    java.util.concurrent.ThreadPoolExecutor$ Worker.runTask (ThreadPoolExecutor.java:886)

    java.util.concurrent.ThreadPoolExecutor$ Worker.run (ThreadPoolExecutor.java:908)

    java.lang.Thread.run(Thread.java:619)

    (Number of attempts: 1).

    IMG_BUILD - internal

    2013-12-27 21:22:31.526 CHANGE CAPTURE: IMG_BUILD - internal S_ASSET has finished running with the Failed state.

    [[code


    The CREATE VIEW privilege was missing from the CAD database user, therefore, was not to create the step. I have granted CREATE VIEW and all is well.

  • ORA-01403: no data found

    Hello

    The following procedure works fine when the select statement returns a line.
    However, it creates "ORA-01403: no data found" error when no data is returned for select.

    When I put the following exception after select it, It doest go inside the if block. (It stops after selection). Do not know why.
    exception
    when NO_DATA_FOUND then null;
    How can I set an exception for this?
    CREATE OR REPLACE PROCEDURE kill_blocking
    IS
    l_sid number(10); 
    l_serial number(10);
    l_wait number(10);
    l_username varchar2(20);
    sqlStmt VARCHAR2(1000);
    BEGIN
    
    SELECT s1.sid,s1.serial#,s2.seconds_in_wait,s2.username
    into l_sid,l_serial,l_wait,l_username
    FROM v$lock l1, v$session s1, v$lock l2,v$session s2,v$sql sqlt1, v$sql sqlt2
    WHERE s1.sid =l1.sid
    AND s2.sid =l2.sid AND sqlt1.sql_id= s2.sql_id AND sqlt2.sql_id= s1.prev_sql_id AND l1.BLOCK =1
    AND l2.request > 0 AND l1.id1 = l2.id1 AND l2.id2 = l2.id2;
    
    if l_username='APP' and l_wait > 100
    then 
    sqlStmt := 'ALTER SYSTEM KILL SESSION ''' || TO_CHAR(l_sid) ||',' || TO_CHAR(l_serial) ||'''' ;
    dbms_output.put_line( sqlStmt );
    
    EXECUTE IMMEDIATE sqlStmt;
    
    
    END IF;
    END;
    / 

    Check this box

    SQL> CREATE OR REPLACE PROCEDURE kill_blocking IS
      2     l_sid        NUMBER (10);
      3     l_serial     NUMBER (10);
      4     l_wait       NUMBER (10);
      5     l_username   VARCHAR2 (20);
      6     sqlstmt      VARCHAR2 (1000);
      7  BEGIN
      8     SELECT s1.SID, s1.serial#, s2.seconds_in_wait, s2.username
      9       INTO l_sid, l_serial, l_wait, l_username
     10       FROM v$lock l1,
     11            v$session s1,
     12            v$lock l2,
     13            v$session s2,
     14            v$sql sqlt1,
     15            v$sql sqlt2
     16      WHERE s1.SID = l1.SID
     17        AND s2.SID = l2.SID
     18        AND sqlt1.sql_id = s2.sql_id
     19        AND sqlt2.sql_id = s1.prev_sql_id
     20        AND l1.BLOCK = 1
     21        AND l2.request > 0
     22        AND l1.id1 = l2.id1
     23        AND l2.id2 = l2.id2;
     24
     25     IF l_username = 'APP' AND l_wait > 100
     26     THEN
     27        sqlstmt :=
     28              'ALTER SYSTEM KILL SESSION '''
     29           || TO_CHAR (l_sid)
     30           || ','
     31           || TO_CHAR (l_serial)
     32           || '''';
     33        DBMS_OUTPUT.put_line (sqlstmt);
     34
     35        EXECUTE IMMEDIATE sqlstmt;
     36     END IF;
     37  EXCEPTION
     38     WHEN NO_DATA_FOUND
     39     THEN
     40
     41        DBMS_OUTPUT.put_line ('No Data Found');
     42  END;
     43  /
    No Data Found
    
    PL/SQL procedure successfully completed.
    
  • No data found Trigger error (before or after)

    Dear all,

    We have the trigger in the database, whenever we try to insert the record in WIP_OPERATIONS, NO DATA FOUND exception was thrown, when debugging we, we have found no problem. The first select statement is getting has not, even if there is the value entered for: NEW.wip_entity_id and when we execute the query separately in the database with the: NEW. WIP_ENTITY_ID, its getting the value. What could be the reason? We cannot use statement SELECT AFTER or BEFORE INSERT trigger? No idea why its NO_DATA_FOUND Exception throw?

    CREATE OR REPLACE TRIGGER sdm_brasil_wj_ops_iface_trg
    BEFORE YOU INSERT OR REMOVE
    ON WIP_OPERATIONS
    SEO
    AGAIN LIKE NEW
    OLD OLD
    FOR EACH LINE
    DECLARE
    ln_status NUMBER (10): = 0;
    ln_item_id Number (20);
    --
    lc_txn_type VARCHAR2 (1);
    v_interface_flag VARCHAR2 (1);
    v_err_msg VARCHAR2 (2000): = NULL;
    v_error VARCHAR2 (2000): = NULL;
    --
    lb_insert_iface BOOLEAN: = FALSE;
    --
    lr_discrete_job_ops wip_operations % ROWTYPE: = NULL;
    --
    BEGIN

    lr_discrete_job_ops.wip_entity_id: =: NEW.wip_entity_id;

    BEGIN

    INSERT INTO APPS. The VALUES of XX_TEMP (': NEW.wip_entity_id ' |: NEW.wip_entity_id);

    SELECT status_type
    IN ln_status
    OF wip_discrete_jobs
    WHERE wip_entity_id =: NEW.wip_entity_id;


    INSERT INTO APPS. The XX_TEMP VALUES ('ln_status' | ln_status);

    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    ln_status: = 0;
    v_error: = ' ERR001: NO DATA FOUND - primary item for WJ ID Id: ' | To_char (lr_discrete_job_ops.wip_entity_id): ' = > ' | SUBSTR (SQLERRM, 1, 500);
    dbg_pk.appmsg (1, vn | v_error);
    WHEN TOO_MANY_ROWS THEN
    ln_status: = 1;
    v_error: = ' ERR001: TOO Manu Rows: primary item for WJ ID Id: ' | To_char (lr_discrete_job_ops.wip_entity_id): ' = > ' | SUBSTR (SQLERRM, 1, 500);
    dbg_pk.appmsg (1, vn | v_error);
    WHILE OTHERS THEN
    ln_status: = 2;
    v_error: = ' ERR001: other - of the primary item for WJ ID Id: ' | To_char (lr_discrete_job_ops.wip_entity_id): ' = > ' | SUBSTR (SQLERRM, 1, 500);
    dbg_pk.appmsg (1, vn | v_error);
    END;

    932450 wrote:
    Hi Blushadow,

    Thanks for the reply, even I thought that the select statement is get executed before recording is committed to the database.

    How we can know, determine if the data enters the wip_discrete_jobs table?

    He didn't necessarily need to be committed, but it must have been inserted in the same session.
    The NO_DATA_FOUND error would seem to indicate that the trigger on the table wip_operations is put to fire until the data is inserted at wip_discrete_jobs. We have all your code, we are unable to identify the exact location of the error.

  • No data found exception

    Hello

    I wrote code like this... But I'm not get when no data found exceptional... Please advise... !!!
    create or replace procedure dis_emp(v_empno in number) as 
    
       cursor kk is select * from empl where empno=v_empno;
    
       a kk%rowtype;
    
    
    begin
            open kk;
          
         loop
    
             fetch kk into a;
             exit when kk%notfound;
         dbms_output.put_line(a.empno||'  '||a.ename||'  '||a.job);
         
    end loop;
    close kk;
            
    
    exception
    when no_data_found then
       dbms_output.put_line('Sorry...wrong empid');
    
    
     when others then
       dbms_output.put_line('sorry..');
          
    end;
    concerning
    SA

    Hello

    The no_data_found exception is thrown when you use select it without cursor... under construction.

    And that's exactly what you use when you perform simple extractions. There's nothing "smart" on the declaration of a cursor, instead.

    create or replace procedure dis_emp(v_empno in number) as
         a empl%rowtype;
    begin
         select * into a
         from empl
         where empno=v_empno;
    
         dbms_output.put_line(a.empno||'  '||a.ename||'  '||a.job);
    exception
    when no_data_found then
        dbms_output.put_line('Sorry...wrong empid');
    end procedure dis_emp;
    /
    

    Also note, don't get any exception when you are not really going to deal with.

    Concerning
    Peter

  • Download of CSV using Browse point (don't get no data found error)

    Hello

    I use procedure below to download CSV in my table.

    CSV is to have null values in some places ex: 1,.
    2,0.999
    3,
    4,0.696

    below the procedure works fine when I am downloading as CSV: 1.0
    2,0.999
    3.0
    4,0.696.

    My table is seen as two columns, and I get no data found error when downloading a CSV of null values.

    I went through import data in Excel to the database table but no use...

    Please help me on this.

    Procedure
    ===========
    DECLARE
    v_blob_data       BLOB;
    v_blob_len        NUMBER;
    v_position        NUMBER;
    v_raw_chunk       RAW(10000);
    v_char   CHAR(1);
    c_chunk_len  number := 1;
    v_line  VARCHAR2 (32767) := NULL;
    v_data_array  wwv_flow_global.vc_arr2;
    
    BEGIN
    
    -- Read data from wwv_flow_files
    select blob_content into v_blob_data  from wwv_flow_files
     where UPDATED_BY = (select max(UPDATED_BY) from wwv_flow_files where UPDATED_BY = :APP_USER)
    AND id = (select max(id) from wwv_flow_files where updated_by = :APP_USER);
    
    v_blob_len := dbms_lob.getlength(v_blob_data);
    v_position := 1;
     
    -- Read and convert binary to char
    WHILE ( v_position <= v_blob_len ) LOOP
     v_raw_chunk := dbms_lob.substr(v_blob_data,c_chunk_len,v_position);
     v_char :=  chr(hex_to_decimal(rawtohex(v_raw_chunk)));
     v_line := v_line || v_char;
     v_position := v_position + c_chunk_len;
    -- When a whole line is retrieved
     IF v_char = CHR(10) THEN
    -- Convert comma to : to use wwv_flow_utilities
      v_line := substr(v_line, 1, length(v_line)-2);
       v_line := REPLACE (v_line, ',', ':');
    -- Convert each column separated by : into array of data
       v_data_array := wwv_flow_utilities.STRING_to_table (v_line);
    -- Insert data into target table
       EXECUTE IMMEDIATE 'insert into table_name@Schema1 (col1,col2)
        values (:1,:2)'
        USING
          v_data_array(1),
          v_data_array(2);
          
          -- Clear out
       v_line := NULL;
      END IF;
     END LOOP;
    
    END;
    concerning
    Chauvet

    Published by: Chaumont on 26 September 2012 10:52

    Published by: Chaumont Sep 26, 2012 22:25

    Published by: Chaumont on 27 September 2012 01:58

    Chambers,

    You can use wwv_flow_utilities.array_element to avoid any no_data_found. The function does not raise any errors. For example, for the line which only have a value of table when you wait 2, it can be useful.

    EXECUTE IMMEDIATE 'insert into table_name@Schema1 (col1,col2)
        values (:1,:2)'
        USING
          wwv_flow_utilities.array_element(v_data_array,1),
          wwv_flow_utilities.array_element(v_data_array,2);
    

    Kind regards
    Christina

  • Help simple loop for no data found

    I am new to PL/SQL and will have problems trying to manage people entering in a good REC BANNER_ID. In the beginning of the game
      for rec in c1 loop
          select SPRIDEN_pidm into pidm 
            from SPRIDEN
           where SPRIDEN_ID = rec.BANNER_ID and SPRIDEN_CHANGE_IND is null; 
    I get no data found when an identification number is entered that does not exist in the spriden table. I want to be able to have the people who did not go in a good REC BANNER_ID in skipped records County which is towards the end. I tried a lot of things, but I do not seem to get anywhere. I'm sure it's pretty simple. I think I need to add some kind of "* IF."
    statement to the article mentioned above. Here is the whole part of the code
    --set serveroutput on format wraped;
    set serveroutput on;
    set verify off;
    spool /u03/banjobs/LOCAL/student/scholar_insert.txt
    Declare
       term_code  varchar2(6) := '&&TERM';
       cursor c1 is select * from ttubantemp.SXTSCHOLAR;
       Pidm  Number;
       so   varchar2(2);
       icnt  number := 0;
       cnt   number := 0;
       insert_cnt number := 0;
       update_cnt number := 0;
       exist_cnt  number := 0;
       skip_cnt   number := 0;
    BEGIN
       dbms_output.enable (buffer_size => null);
       for rec in c1 loop
          select SPRIDEN_pidm into pidm 
            from SPRIDEN
           where SPRIDEN_ID = rec.BANNER_ID and SPRIDEN_CHANGE_IND is null;
           Select Count(*) Into Cnt
             From SPRCMNT
             Where Sprcmnt_Pidm = Pidm
             And Sprcmnt_Cmtt_Code = 'SO';
     --        and SPRCMNT_TEXT not like term_code;
          If Cnt > 0 Then
             Select Sprcmnt_Cmtt_Code Into So
               From Sprcmnt
              Where Sprcmnt_Pidm = Pidm
              and  SPRCMNT_CMTT_CODE = 'SO';
          Else
             so := null;
          end if;
    --
          dbms_output.put_line('BANNER_ID = '||rec.BANNER_ID||
                               ' - PIDM = '||Pidm||
                               ' - Term = '||Term_Code||
                               ' - cnt = '||Cnt);
                          
            If Pidm Is Not Null
            then
             Select Count(*) Into Cnt 
               From Spriden
              Where Spriden_Pidm = Pidm
              And So Is Null;
             if cnt > 0 then
                dbms_output.put_line('   INSERTING');
               INSERT INTO sprcmnt(
                  SPRCMNT_PIDM,
                  SPRCMNT_CMTT_CODE,
                  SPRCMNT_TEXT,
                  SPRCMNT_TEXT_NAR,
                  SPRCMNT_CONFIDENTIAL_IND,
                  SPRCMNT_DATE,
                  SPRCMNT_ORIG_CODE,
                  SPRCMNT_ACTIVITY_DATE,
                  SPRCMNT_CTYP_CODE,
                  SPRCMNT_CONTACT_DATE,
                  SPRCMNT_USER_ID,
                  SPRCMNT_CONTACT_FROM_TIME,
                  SPRCMNT_CONTACT_TO_TIME)
           VALUES (pidm,
                  'SO',
                  term_code,
                  NULL,
                  'N',
                  Sysdate,
                  'SCHL',
                  SYSDATE,
                  NULL,
                  Null,
                  'NEXTGEN',
                  NULL,
                  NULL);
                insert_cnt := insert_cnt + 1;
             else
              select count(*) into cnt 
               from sprcmnt
              Where Sprcmnt_Pidm = Pidm
               And So Is Not Null
               And Sprcmnt_Text Like '&&%TERM%';
                if cnt > 0 then
                   dbms_output.put_line('   UPDATING');
                   update sprcmnt
                      set SPRCMNT_TEXT = SPRCMNT_TEXT||' '||term_code
                    where SPRCMNT_PIDM = pidm
                      and  SPRCMNT_CMTT_CODE = 'SO';
                    update sprcmnt
                      set SPRCMNT_ACTIVITY_DATE = sysdate
                    where SPRCMNT_PIDM = pidm
                      and  SPRCMNT_CMTT_CODE = 'SO';
                     Update Sprcmnt
                      set SPRCMNT_USER_ID = 'NEXTGEN'
                    where SPRCMNT_PIDM = pidm
                      and SPRCMNT_CMTT_CODE = 'SO';
                    update_cnt := update_cnt + 1;
                 else
                    dbms_output.put_line('   RECORD EXISTS');
                    exist_cnt := exist_cnt + 1;
                 end if;
             end if;
             icnt := icnt + 1;
          else
              dbms_output.put_line('SKIPPED BANNER_ID = '||rec.BANNER_ID);
              skip_cnt := skip_cnt + 1;
          end if;
       end loop;
       commit;
       dbms_output.put_line('Total Records    = '||icnt);
       dbms_output.put_line('Records Inserted = '||insert_cnt);
       dbms_output.put_line('Records Updated  = '||update_cnt);
       dbms_output.put_line('Records Existed  = '||exist_cnt);
       dbms_output.put_line('Records Skipped  = '||skip_cnt);
    END;
    /
    spool off;
    /
    EXIT
    Here are the results I get with 1 id good and a bad id

    Error report:
    ORA-01403: no data found
    ORA-06512: at line 15 level
    01403 00000 - "no data found".
    * Cause:
    * Action:
    BANNER_ID = T00001227 - PIDM = 1450 - term = 201280 - cnt = 0
    INSERTION OF

    Engage

    Here are the results with only a good idea

    anonymous block filled
    BANNER_ID = T00001227 - PIDM = 1450 - term = 201280 - cnt = 0
    INSERTION OF
    Total records = 1
    Inserted records = 1
    Put records = 0
    Folders existed = 0
    Ignored records = 0

    Engage

    Edited by: Withnoe 6 July 2012 14:27

    Put another block of start-end inside the loop (around your select statement) and includes an exception handler.
    Pseudocode here:

    for rec in c1 loop
      BEGIN
          select SPRIDEN_pidm into pidm
            from SPRIDEN
           where SPRIDEN_ID = rec.BANNER_ID and SPRIDEN_CHANGE_IND is null;
      EXCEPTION WHEN NO_DATA_FOUND THEN
        dbms_output.put_line('SKIPPED BANNER_ID = '||rec.BANNER_ID);
        skip_cnt := skip_cnt + 1;
      END;
    .
    .
    .
    end loop;
    

    In addition, if you count the records to see if he has at least 1 card that meets the condition, why count ALL records? You can count and put "rownum = 1" or "" rownum < 2"="" so="" it="" stops="" when="" it="" gets="" to="" one="" row.="" another="" way="" i="" like="" to="" do="" it="" is="" "select="" count(*)="" from="" dual="" where=""> ".

    But often there is no need to count at all. People will sometimes do a count to see if there is to be done and if so, then run. In many cases, it is best to try just to get the job done without counting any first.

  • why its shows no data found?

    why its shows no data found?

    I have SEQ column in my table.

    DECLARE
    V_ENAME varchar2 (20);
    V_SEQ varchar2 (20);
    L_E_SEQ varchar2 (20);
    L_ENAME varchar2 (20);

    Start
    SELECT ENAME, SEQ IN V_ENAME, V_SEQ FROM VEN_EMP WHERE EMPNO = 7369;
    IF V_SEQ = 1 THEN
    L_ENAME: = V_ENAME;
    ON THE OTHER
    L_E_SEQ: = V_SEQ-1;
    SELECT ENAME IN V_ENAME FROM EMP WHERE SEQ = L_E_SEQ;
    dbms_output_line (v_ename);
    END IF;
    END;

    Published by: ayman on March 19, 2012 23:34
      1  DECLARE
      2  v_ename varchar2(20);
      3  v_sql varchar2(20);
      4  L_E_SEQ varchar2(20);
      5  V_SEQ NUMBER(20);
      6  L_ENAME VARCHAR2(20);
      7  begin
      8  SELECT ENAME,SEQ INTO V_ENAME,V_SEQ
      9   FROM
     10  (select 'FOR' ENAME,1 SEQ,100 EMPNO from dual union all
     11  select 'FOR' ENAME,2,7369 from dual
     12  ) WHERE EMPNO=7369;
     13  IF V_SEQ=1 THEN
     14  L_ENAME:=V_ENAME;
     15  ELSE
     16  L_E_SEQ:=V_SEQ-1;
     17  SELECT ENAME INTO V_ENAME
     18  FROM
     19  (select 'FOR' ENAME,1 SEQ,100 EMPNO from dual union all
     20  select 'FOR' ENAME,2,7369 from dual
     21  ) WHERE SEQ=L_E_SEQ;
     22  dbms_output.put_line(v_ename);
     23  END IF;
     24  END;
     25  /
    
    FOR
    
    PL/SQL procedure successfully completed.
    

    What is the problem?

  • How to modify a statement "select into" how to use a cursor

    The following code fails with an exception too many lines. How can I modify statement Select Into the procedure 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 filled with the table names comma-separated list:

    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

    Published by: user130038 on December 28, 2011 08:46

  • SELECT INTO VARIABLE base

    I'm trying to make a

    SELECT EMP_TOTAL FROM EMPLOYEES WHERE ADD_DATE = SYSDATE

    In the statement above "WHERE ADD_DATE = SYSDATE' this condition eliminates several values since in my table there is only a 1 value for each sysdate

    And this unique value, I want to choose in a variable coz

    If it is not equal to zero

    I want to run a bunch of SQL
    ON THE OTHER

    SOME other SQL.

    The problem I face is when selecting in the variable.


    I get error when I try

    DECLARE a number
    SELECT EMP_TOTAL FROM EMPLOYEES WHERE ADD_DATE = SYSDATE;
    IF a! = 0 THEN

    -------SQL----------

    ON THE OTHER

    --------SQL-------


    I also tried

    DECLARE a NUMBER: SELECTION EMP_TOTAL OF EMPLOYEES WHERE ADD_DATE = SYSDATE

    Help, please.

    Newbie in PLSQL

    I get error when I try

    Let me guess, the error is right no data found? He should know that sysdate (in fact, all dates in Oracle) always has a component "time" to the second, so it is unlikely that you would have a file meets the criteria. Depending on whether you actually store times in your area of add_date that you must do something more like:

    If there is no time in your area

    DECLARE
       a number;
    BEGIN
       SELECT emp_total INTO a
       FROM employees
       WHERE add_date = TRUNC(sysdate) ;
       IF a != 0 THEN
          -------SQL----------
       ELSE
          --------SQL-------
       END IF;
    END;
    

    If you are actually storing time:

    DECLARE
       a number;
    BEGIN
       SELECT emp_total INTO a
       FROM employees
       WHERE add_date >= TRUNC(sysdate) and
             add_date < TRUNC(sysdate + 1);
       IF a != 0 THEN
          -------SQL----------
       ELSE
          --------SQL-------
       END IF;
    END;
    

    John

Maybe you are looking for