1

I am new to PL-SQL. I do not understand why I am getting the error "PLS-00428: an INTO clause is expected in this SELECT statement"

What I'm trying to accomplish is to create a variable c_limit and load it's value. I then want to use that variable later to filter data.

Basically I am playing around in the demo db to see what I can/can't do with PL-SQL.

The code worked up to the point that I added "select * from demo_orders where CUSTOMER_ID = custID;"

declare 
c_limit NUMBER(9,2);
custID INT;

BEGIN
  custID := 6;

  -- Save the credit limit
  select credit_limit INTO c_limit
  from  demo_customers cust
  where customer_id = custID;

  select * from demo_orders where CUSTOMER_ID = custID;

  dbms_output.Put_line(c_limit);
END;
1
  • You have to select * from demo_orders where CUSTOMER_ID = custID; into something, as you did it in the first query. It looks like you don't need this query anyway, so just comment or delete it and this PL/SQL block will work. Commented Jan 18, 2016 at 16:08

2 Answers 2

1

If you are using a SQL SELECT statement within an anonymous block (in PL/SQL - between the BEGIN and the END keywords) you must select INTO something so that PL/SQL can utilize a variable to hold your result from the query. It is important to note here that if you are selecting multiple columns, (which you are by "SELECT *"), you must specify multiple variables or a record to insert the results of your query into.

for example:

SELECT 1 
INTO v_dummy 
FROM dual;

SELECT 1, 2 
INTO v_dummy, v_dummy2 
FROM dual;

It is also worth pointing out that if your SELECT * FROM.... will return multiple rows, PL/SQL will throw an error. You should only expect to retrieve 1 row of data from a SELECT INTO.

Sign up to request clarification or add additional context in comments.

Comments

0

Looks like the error is from the second select query.

select * from demo_orders where CUSTOMER_ID = custID;

PL-SQL won't allow a standalone sql select query for info.

http://pls-00428.ora-code.com/

You need to do some operation with the second select query

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.