Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check a record IS NOT NULL in plsql

Tags:

I have a function which would return a record with type my_table%ROWTYPE, and in the caller, I could check if the returned record is null, but PL/SQL complains the if-statement that

PLS-00306: wrong number or types of arguments in call to 'IS NOT NULL'

Here is my code:

v_record my_table%ROWTYPE; v_row_id my_table.row_id%TYPE := 123456; begin     v_record := myfunction(v_row_id)     if (v_record is not null) then         -- do something     end if; end;  function myfunction(p_row_id in my_table.row_id%TYPE) return my_table%ROWTYPE is     v_record_out my_table%ROWTYPE := null; begin     select * into v_record_out from my_table     where row_id = p_row_id;     return v_record_out; end myfunction; 

Thanks.

like image 801
Sapience Avatar asked Aug 26 '11 16:08

Sapience


1 Answers

As far as I know, it's not possible. Checking the PRIMARY KEY or a NOT NULL column should be sufficient though.


You can check for v_record.row_id IS NULL.

Your function would throw a NO_DATA_FOUND exception though, when no record is found.

like image 181
Peter Lang Avatar answered Sep 29 '22 02:09

Peter Lang