|
Re: How to re-initialize a pl/sql table [message #127269 is a reply to message #127268] |
Mon, 11 July 2005 00:17   |
deepa_balu
Messages: 74 Registered: March 2005
|
Member |
|
|
For every PL/SQL table you want to be able to empty, you declare a parallel, empty table of the same table type. When you are finished working with your table, simply assign the empty table to the actual table. This will unassign all the rows you have used. The following example demonstrates this technique:
DECLARE
TYPE company_names_tabtype IS TABLE OF company.name%TYPE
INDEX BY BINARY_INTEGER;
company_names_tab company_names_tabtype;
/* Here is the empty table declaration */
empty_company_names_tab company_names_tabtype;
BEGIN
... set values in company names table ...
/* The closest you can come to "dropping" a PL/SQL table */
company_names_tab := empty_company_names_tab;
END;
NOTE: PL/SQL Release 2.3 offers a DELETE operator so that you can delete all or some rows of a PL/SQL table.
|
|
|
|
|
|
Re: How to re-initialize a pl/sql table [message #127283 is a reply to message #127268] |
Mon, 11 July 2005 01:26   |
deepa_balu
Messages: 74 Registered: March 2005
|
Member |
|
|
See i guess reinitialising meaning setting the table values to NULL.
We can set a single row value to null as per the following.
you can follow the same inside a loop for all values of the table.
DECLARE
TYPE deepatab IS TABLE OF integer INDEX BY BINARY_INTEGER;
companytab deepatab;
BEGIN
companytab(1):=1;
dbms_output.put_line('Value is :' ||companytab(1));
companytab(1):=NULL;
dbms_output.put_line('Value is :'|| companytab(1));
END;
If u dont want a loop to re-initialise the plsql table, then u can follow the empty table assignment( the eg, i have given in my first post)
|
|
|
Re: How to re-initialize a pl/sql table [message #127310 is a reply to message #127283] |
Mon, 11 July 2005 03:39   |
d.dineshkumar
Messages: 211 Registered: April 2005 Location: Kolkatta
|
Senior Member |
|
|
THANKS BALU,
but i was looking for a method with which i can directly assign null to the plsql table variables.Ur first post is good ,but as i have 7 pl/sql table in my prg so i have to declare 7 more..variables that is the problem.And i don't want to loop through the element to nullify them
Thanks a lot.
Dinesh
|
|
|
Re: How to re-initialize a pl/sql table [message #127313 is a reply to message #127310] |
Mon, 11 July 2005 03:53   |
William Robertson
Messages: 1643 Registered: August 2003 Location: London, UK
|
Senior Member |
|
|
Can't you just use the DELETE method as mentioned above?
DECLARE
TYPE tt IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
t tt;
BEGIN
t(1) := 10;
t(2) := 20;
DBMS_OUTPUT.PUT_LINE('t contains ' || t.COUNT || ' elements');
t.DELETE;
DBMS_OUTPUT.PUT_LINE('t contains ' || t.COUNT || ' elements');
END;
/
|
|
|
|
|
|