I want to be able to have a simple way to check if a query returns anything as an attempt to see if a record exists before I enter it.
So in MS-SQL I would do the following:
IF NOT EXISTS (SELECT * FROM MYTABLE WHERE MYCOLUMN = 'THISVALUE')
BEGIN
//Insert field
END
Easy.
This doesn't work in Oracle and the best alternative I have found is more verbose:
SELECT COUNT(*) INTO TEMPVAR
FROM MYTABLE
WHERE MYCOLUMN = ‘THISVALUE’
IF TEMPVAR = 0
BEGIN
//Insert field
END
So I want to put this into a function so I can do:
IF myPackage.Exists(SELECT * FROM MYTABLE WHERE MYCOLUMN = 'THISVALUE')
BEGIN
//Insert field
END
But here is where I am stuck. How do I execute a query within a case statement when the query has to be generic? I am using EXECUTE IMMEDIATE but no luck.
CASE
WHEN (EXECUTE IMMEDIATE queryString)
THEN 1
ELSE 0
END AS MYVAR
(and then returning that var).
myPackage.existsin your post that takes an input of aSELECT COUNT(*)query, but I realize that this may not be sufficient if it a requirement that the exists function acceptSELECT *type query strings instead. Can you work withSELECT COUNT(*)as an input or isSELECT *required? Thanks