0

I am writing the below queries in oracle:

DBMS_OUTPUT.....'Ashish'

Select col1 into val1 from tab_1

DBMS_OUTPUT.....'Ubale'

when I run this procedure I get the output as "Ashish" only why? also what will be the value of v_val1 variable

Note: the table does not contain any records

2 Answers2

6

Since the table is empty, the "select into" statement will raise the NO_DATA_FOUND exception. That's why you don't get the second message. val1 will have the same value as before the select - i.e. null if you didn't previously assign a value.

The fact that you don't know you got the NO_DATA_FOUND exception suggests that you have made one of the biggest errors PL/SQL developers ever make:

EXCEPTION
    -- Never do this in real code!!!
   WHEN OTHERS THEN NULL;
END;
Tony Andrews
  • 129,880
  • 21
  • 220
  • 259
0

Did you get error? If the table doesn't have rows in it. You might get no_data_found exception.

By the way, where is your entire code?

Guru
  • 2,331
  • 6
  • 31
  • 48