Home » SQL & PL/SQL » SQL & PL/SQL » can we use 'Select' in IF statement
can we use 'Select' in IF statement [message #617006] Tue, 24 June 2014 02:54 Go to next message
vicktorz
Messages: 26
Registered: March 2013
Junior Member
Hi,,

Please clarify my doubt..

can we use select statment in IF clause(along with in operator)

that means,

If i in (select values from <table_name>) then
dbms_output.put_line('yes');
else
dbms_output.put_line('no');
end if;

If we can't use means, i wish to know the reason.. Pls clarify..
Re: can we use 'Select' in IF statement [message #617007 is a reply to message #617006] Tue, 24 June 2014 02:59 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
vicktorz wrote on Tue, 24 June 2014 13:24
If we can't use means, i wish to know the reason.. Pls clarify..


Because subquery is not allowed in this context.
Re: can we use 'Select' in IF statement [message #617018 is a reply to message #617006] Tue, 24 June 2014 03:52 Go to previous message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Michel Cadot wrote on Tue, 24 June 2014 10:50

So what you want to do is:
SQL> declare
  2    a varchar2(200) :='vs';
  3    b varchar2(200);
  4  begin
  5    SELECT name into b FROM vk_domain WHERE name = a and rownum = 1;
  6    dbms_output.put_line('yes');
  7  exception
  8    when no_data_found then dbms_output.put_line('no');
  9  end;
 10  /
yes

PL/SQL procedure successfully completed.



Previous Topic: Help Required in SQL Analytic Function.
Next Topic: date format as dd/mm/yyyy in the excel
Goto Forum:
  


Current Time: Thu Mar 28 12:39:50 CDT 2024