Home » SQL & PL/SQL » SQL & PL/SQL » How to use if exist condition in oracle (11g)
icon5.gif  How to use if exist condition in oracle [message #568456] Thu, 11 October 2012 23:36 Go to next message
vikashkrburnwal@gmail.com
Messages: 61
Registered: October 2012
Location: Bangalore
Member
Hi all,

Hope doing well,

sir i am using one if exist condition in sql server that is like this.

if exists(select 1 from ShiftEmployee where Empid=@EmpID and Month=@month and year=@year)
begin
some value is passing here...
end

how to use the same in oracle?

thanks
Re: How to use if exist condition in oracle [message #568459 is a reply to message #568456] Fri, 12 October 2012 00:29 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

Just sample code...

declare 

v_counter nummber;
begin
select 1 into v_counter 
from ShiftEmployee where Empid=@EmpID and Month=@month and year=@year;

if v_counter>0 then 
some value is passing here...
end if;
end;
/
Re: How to use if exist condition in oracle [message #568460 is a reply to message #568459] Fri, 12 October 2012 00:58 Go to previous messageGo to next message
vikashkrburnwal@gmail.com
Messages: 61
Registered: October 2012
Location: Bangalore
Member
ok thank you sir i got it.

thanks alot Smile
Re: How to use if exist condition in oracle [message #568463 is a reply to message #568460] Fri, 12 October 2012 01:07 Go to previous messageGo to next message
Michel Cadot
Messages: 60018
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Do NOT use this, it is bad programming and wrong:
1/ between the SELECT and the IF the condition may have changed;
2/ the correct way to do it depends on what you put between "begin" and "end".

Regards
Michel

[Updated on: Fri, 12 October 2012 01:09]

Report message to a moderator

Re: How to use if exist condition in oracle [message #568507 is a reply to message #568459] Fri, 12 October 2012 09:48 Go to previous message
Solomon Yakobson
Messages: 2079
Registered: January 2010
Senior Member
muralikri wrote on Fri, 12 October 2012 01:29
Just sample code...


And wrong one. It will raise TOO_MANY_ROWS each time query yields multiple rows. You should add:

AND ROWNUM = 1

SY.
Previous Topic: After servererror on database
Next Topic: Question on insert statement
Goto Forum:
  


Current Time: Mon Dec 22 21:51:18 CST 2014

Total time taken to generate the page: 0.28386 seconds