Home » SQL & PL/SQL » SQL & PL/SQL » How to initialized populated rowtype variable  () 1 Vote
How to initialized populated rowtype variable [message #157332] Wed, 01 February 2006 12:00 Go to next message
pzomof
Messages: 2
Registered: February 2006
Location: Chicago
Junior Member
Hi,

How would I initialize properly a variable declared as:

v1 table1%type;

And this is populated like:

v1.col1 := 'Col 1 value';
v1.col2 := 'Col 2 value';
v1.col3 := 'Col 3 value';
v1.col4 := 'Col 4 value';
...
vn.coln := 'Col n value';

Now I want to initialize v1 again.

Thanks,
-Paul
Re: How to initialized populated rowtype variable [message #157339 is a reply to message #157332] Wed, 01 February 2006 14:16 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Just assign NULL to it:

sql>declare
  2    v_emp emp%rowtype;
  3  begin
  4    v_emp.empno := 123;
  5    v_emp.ename := 'John';
  6    dbms_output.put_line( 'Name: ' || v_emp.ename );
  7    v_emp := null;
  8    dbms_output.put_line( 'Name: ' || v_emp.ename );
  9  end;
 10  /
Name: John
Name:

PL/SQL procedure successfully completed.
Re: How to initialized populated rowtype variable [message #157342 is a reply to message #157339] Wed, 01 February 2006 15:46 Go to previous messageGo to next message
pzomof
Messages: 2
Registered: February 2006
Location: Chicago
Junior Member
Thanks Todd Barry!
Re: How to initialized populated rowtype variable [message #157368 is a reply to message #157342] Thu, 02 February 2006 00:34 Go to previous message
Frank
Messages: 7901
Registered: March 2000
Senior Member
To re-initialize a table-type, you can use .delete:
SQL> declare
  2    type rec is record (id number
  3                       ,text varchar2(10)
  4                       );
  5    type tab is table of rec index by binary_integer;
  6    l_tab   tab;
  7  begin
  8    l_tab(1).id := 10;
  9    l_tab(1).text := 'Hello';
 10    l_tab(2).text := 'world';
 11    dbms_output.put_line(l_tab(2).text);
 12    l_tab.delete;
 13    dbms_output.put_line(l_tab(2).text);
 14  end;
 15  /
world
declare
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 13


hth
Previous Topic: identifying the long operation sql query
Next Topic: Deletion by CTAS
Goto Forum:
  


Current Time: Sun Apr 27 01:41:53 CDT 2025