If exists in PL/sql

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paulos

    If exists in PL/sql

    Hi Guys

    I am a bit of a nocice at some aspects of PL/SQL and I have to write some
    code in a function that checks if a row in a given table exists...someth ing
    on the lines of :

    IF( exists(select 'x' from table) then
    do stuff
    else
    do other stuff

    end if;

    Is there a quick and efficient way of doing this?

    Thnx

    Paulos


  • hrishy

    #2
    Re: If exists in PL/sql

    Hi

    DECLARE
    l_count NUMBER;
    BEGIN
    select count(*)
    into l_count
    from all_tables
    where table_name = 'ur_table';

    if l_count 0 then
    do somthing;
    end if;
    END;

    another way would be very simply

    begin
    select 'X' from ur_table;
    do something
    exception
    write exception handling code
    end

    regards
    Hrishy




    "Paulos" <paulos-spamfree@skynet .bewrote in message news:<40c74c0c$ 0$9545$a0ced6e1 @news.skynet.be >...
    Hi Guys
    >
    I am a bit of a nocice at some aspects of PL/SQL and I have to write some
    code in a function that checks if a row in a given table exists...someth ing
    on the lines of :
    >
    IF( exists(select 'x' from table) then
    do stuff
    else
    do other stuff
    >
    end if;
    >
    Is there a quick and efficient way of doing this?
    >
    Thnx
    >
    Paulos

    Comment

    Working...