views:

48

answers:

2

Hi All,

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

A: 

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
+4  A: 

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
+1. For when others then null
Guru
Thanks tony...Your suggestion works.Thans alot for quick reply!!!
+1 I would give +2 for the comment in the excepetion block :)
Juergen Hartelt