nimish kulkarni
nimish kulkarni

Reputation: 3

ERROR IN ORACLE WHILE EXECUTING QUERY

I am trying to execute the below query and trying to get output in variable.

DECLARE LATESTID INT
SELECT LATESTID := ID FROM Cust_RectifiedDetails WHERE CustNo = UNIFIEDCUSTOMERNO
ORDER BY ID DESC

But while executing i am getting the below error :

ORA-24344: success with compilation error
PLS-00103: Encountered the symbol "LATESTID" when expecting one of the following:

   := . ( @ % ; not null range default character

Kindly please guide me Regards

Upvotes: 0

Views: 73

Answers (2)

Codeek
Codeek

Reputation: 1624

It's done using SELECT INTO try this :

BEGIN
   SELECT ID INTO LATESTID  FROM Cust_RectifiedDetails WHERE CustNo = UNIFIEDCUSTOMERNO
END;

Don't forget the BEGIN and END; clause and a semi-colon after your INT

Upvotes: 1

René Nyffenegger
René Nyffenegger

Reputation: 40489

After a DECLARE section you need a BEGIN.

Also, the semicolon after INT is missing.

You can't assign values in a select statement with a :=. Use select into instead.

Finally, an order by makes no sense when you select into. You might want to catch too_many_values. Alternatively, you might want to try max() or any of its derivatives.

declare
  latestid int;

begin

  select id into latestid
   from  cust_rectifieddetails
   where custno = unifiedcustomerno;

exception when to_many_values then
-- Do what you need to do.
   raise;

end;

Upvotes: 2

Related Questions