I'm using a reporting program in which I give it the SQL statement and the values selected, become the variables. For example in this case I'm trying to determine whether a record already exists or not. If it doesn't, return RecordExists with a value of 0; otherwise 1.
This is much simpler (to me) using SQL Server, but I'm trying to figure out why the below will not work. The syntax error generated suggests I need an "INTO" clause with my SELECT RecordExists FROM Dual; line even though I'm not trying to assign a value at that point.
DECLARE
RecordExists NUMBER;
BEGIN
SELECT COUNT(*) INTO RecordExists FROM Times
WHERE Times.OrderNumber = '123456789' AND Times.StopSequence = '1';
IF (RecordExists >= 1)
THEN
SELECT 1 INTO RecordExists FROM dual;
SELECT RecordExists FROM dual;
ELSE
SELECT 0 INTO RecordExists FROM dual;
SELECT RecordExists FROM dual;
END IF;
END;
RecordExists? It has to be eitherreturned (if in a function), or declared as an OUT parameter (if a procedure).