I am getting the following error. Getting the error at SELECT CASE
statement.
PLS-00428: an INTO clause is expected in this SELECT statement
FOR REMS IN cur_names LOOP
SELECT CASE
WHEN EXISTS (SELECT 1
FROM SupplyTable
WHERE FirstName = REMS.Names)
THEN 'Y'
ELSE 'N'
END AS rec_exists
FROM dual;
IF rec_exists = 'Y' THEN
FName := REMS.Names;
ELSE
FName := 'Gen';
END IF;
END LOOP;
In PLSQL block, columns of select statements must be assigned to variables, which is not the case in SQL statements. The second BEGIN's SQL statement doesn't have INTO clause and that caused the error.
A SELECT statement was executed without INTO clause in a PL/SQL block. Add the INTO clause to the SELECT statement. ORA-06550: PLS-00428: an INTO clause is expected in this SELECT statement
In PL/SQL you can't run standard (SQL) SELECT statements. You can run SELECT statements that return values to PL/SQL variables (either scalar variables or collections, such as arrays of records, etc.) If you have a SELECT statement in a PL/SQL block, you must specify the variable (s) INTO which the values are to be returned.
SELECT - INTO Clause (Transact-SQL) SELECT...INTO creates a new table in the default filegroup and inserts the resulting rows from the query into it. To view the complete SELECT syntax, see SELECT (Transact-SQL).
you can´t have a random select inside your pl sql code. It must be in a loop, cursor, with an into clause. Just include an into clause here.
declare
v_value varchar2(1);
begin
...
FOR REMS IN cur_names LOOP
SELECT CASE
WHEN EXISTS (SELECT 1
FROM SupplyTable
WHERE FirstName = REMS.Names)
THEN 'Y'
ELSE 'N'
END AS rec_exists
INTO v_value
FROM dual;
IF v_value = 'Y' THEN
FName := REMS.Names;
ELSE
FName := 'Gen';
END IF;
END LOOP;
...
or a loop
FOR REMS IN cur_names LOOP
for i in
(
SELECT CASE
WHEN EXISTS (SELECT 1
FROM SupplyTable
WHERE FirstName = REMS.Names)
THEN 'Y'
ELSE 'N'
END AS rec_exists
FROM dual
)
loop
IF i.rec_exists = 'Y' THEN
FName := REMS.Names;
ELSE
FName := 'Gen';
END IF;
end loop;
END LOOP;
You need to store the output somewhere , like a variable. REC_EXISTS
is a column, so right after the select it no longer exists.
Try this:
declare rec_exists varchar2(1);;
FOR REMS IN cur_names LOOP
SELECT CASE
WHEN EXISTS (SELECT 1
FROM SupplyTable
WHERE FirstName = REMS.Names)
THEN 'Y'
ELSE 'N'
END into rec_exists
FROM dual;
IF rec_exists = 'Y' THEN
FName := REMS.Names;
ELSE
FName := 'Gen';
END IF;
END LOOP;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With