Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXISTS

Status
Not open for further replies.

arpan

Programmer
Oct 16, 2002
336
IN
I have framed the following procedure to find out whether the parameter that is being passed to the procedure exists in the ID column of a table or not:

CREATE OR REPLACE PROCEDURE ExistsOrNot(
iID INT)
IS
intID INT;
BEGIN
SELECT ID INTO intID FROM tblName WHERE ID=iID;
IF EXISTS(intID) THEN
DBMS_OUTPUT.PUT_LINE('ID EXISTS');
ELSE
DBMS_OUTPUT.PUT_LINE('ID DOES NOT EXIST');
END IF;
END;

but the above throws a compilation error saying Encountered the symbol "INTID" when expecting one of the following :
( select


Where am I going wrong? I know that NO_DATA_FOUND can be used in this case but I would like to know how do I make use of EXISTS to do the same.

Thanks,

Arpan
 
hi arpan,
EXISTS works out in the query along with Where clause. So try using it in the where clause. It will not work with exists i guess. As your query will bring only true or false when u use exists in the where clause.... u can then check, if true give a msg otherwise give another msg.

hope this works
Abhivyakti
 
No, you can not. EXISTS may be applied to subqueries or pl/sql table records. Where did you find this syntax? Regards, Dima
 
SELECT count(*) INTO something FROM tblName WHERE ID=iID;
and test on that. DaPi - no silver bullet
 
Hi Dima,

Actually what I have shown in my post (the IF condition) is allowed in Microsoft SQL Server......something like this:

IF EXISTS (SELECT ID FROM tblName WHERE ID=@id)
PRINT ('ID EXISTS')
ELSE
PRINT ('ID DOES NOT EXIST")
............

where @id is the parameter passed to the procedure.So that is the reason why I tried something similar in Oracle. I am more into SQL Server than Oracle. Anyway, thanks for your response. Thanks to Abhivyakti as well.

Regards,

Arpan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top