0

In a recent interview I was asked to write a simple PL/SQL code to throw NO_DATA_FOUND exception without actually raising it from the code. I am wondering what could be a simple pl/sql snippet to do so. Probably using dual?

asked Jun 4, 2016 at 19:03

3 Answers 3

1

Many ways, but as you suggested, you can use DUAL:

CREATE PROCEDURE NODATAFOUND
AS
 nowt VARCHAR(10);
BEGIN
 SELECT * INTO nowt FROM DUAL WHERE 1=0;
END;
/

It'll produce a ORA-01403: no data found when executed.

answered Jun 4, 2016 at 21:08
0
0

I would use an existing table from project structure with an impossible where clause. For example a negative number on PK when PK i defined as positive, etc.

Strange question in an interview....I never got that kind.

answered Jun 4, 2016 at 19:20
1
  • The idea behind the question was to use simplistic code without assuming any tables or raising this exception I think. But yes this would obviously work. Commented Jun 4, 2016 at 21:18
0

How about

raise no_data_found;

answered Jun 6, 2016 at 20:01
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.