On Aug 17, 8:16 am, orgilhp <orgi...@gmail.com> wrote:
> hi all,
> I'm using code below in order to know whether LAST_NUMBER of
> MySequence1 is "1" or not.
> ---------------------------------------------------------------------------­---------------------------------------------------------------
> set serveroutput on;
> declare v_temp number(1,0);
> begin
>   SELECT 1 INTO v_temp FROM dual
>   WHERE EXISTS
>     ( SELECT last_number FROM all_sequences
>       WHERE LOWER(sequence_name)=LOWER('MySequence1') AND
> last_number=1);
>     dbms_output.put_line(v_temp);
> end;
> ---------------------------------------------------------------------------­-------------------------------------------------------------
> but when the Last_Number <> "1" then the "NO DATA FOUND" error is
> thrown.
>
> I think that if last_number<>1 then EXISTS() function just returns
> "false".
> I don't see any reason to get error.
>
> Please suggest me!
> ... Orgil

It is the select statement generating the error, not the EXISTS
condition.  The select returns no data because it finds nothing that
matches your conditions (NO_DATA_FOUND).  This is where you, as the
programmer, code an exception and handle the NO_DATA_FOUND condition:

declare v_temp number(1,0);
begin
  SELECT 1 INTO v_temp FROM dual
  WHERE EXISTS
    ( SELECT last_number FROM all_sequences
      WHERE LOWER(sequence_name)=LOWER('MySequence1') AND
last_number=1);
    dbms_output.put_line(v_temp);
exception
     when NO_DATA_FOUND then
          dbms_output.put_line('Last number of MySequence1 is greater
than 1');
end;

and you solve your 'problem'.



David Fitzjarrell

-- 
You received this message because you are subscribed to the Google
Groups "Oracle PL/SQL" group.
To post to this group, send email to Oracle-PLSQL@googlegroups.com
To unsubscribe from this group, send email to
oracle-plsql-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/Oracle-PLSQL?hl=en

Reply via email to