Home » SQL & PL/SQL » SQL & PL/SQL » How to re-initialize a pl/sql table
icon5.gif  How to re-initialize a pl/sql table [message #127268] Sun, 10 July 2005 23:57 Go to next message
d.dineshkumar
Messages: 211
Registered: April 2005
Location: Kolkatta
Senior Member
Good morning gurus,
Pls give me a method to re-initialize a pl/sql table ,without looping through its elements of-course.

Thanks and regards
Dinesh
Re: How to re-initialize a pl/sql table [message #127269 is a reply to message #127268] Mon, 11 July 2005 00:17 Go to previous messageGo to next message
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 #127270 is a reply to message #127269] Mon, 11 July 2005 00:23 Go to previous messageGo to next message
d.dineshkumar
Messages: 211
Registered: April 2005
Location: Kolkatta
Senior Member
Thanks balu,
Can't i assign NULL directly to pl/sql table.So that all its elements will be null automatically.

Thanks and regards
Dinesh
Re: How to re-initialize a pl/sql table [message #127272 is a reply to message #127268] Mon, 11 July 2005 00:29 Go to previous messageGo to next message
deepa_balu
Messages: 74
Registered: March 2005
Member
i think we can set a single row only to null.
company_names_table (num_rows) := NULL;

All rows to null in one shot... i am not aware of that.

Re: How to re-initialize a pl/sql table [message #127281 is a reply to message #127272] Mon, 11 July 2005 01:18 Go to previous messageGo to next message
d.dineshkumar
Messages: 211
Registered: April 2005
Location: Kolkatta
Senior Member
Thanks again balu,
Can i have an example of what u r trying to explain.

Thanks
Dinesh
Re: How to re-initialize a pl/sql table [message #127283 is a reply to message #127268] Mon, 11 July 2005 01:26 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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;
/
Re: How to re-initialize a pl/sql table [message #127315 is a reply to message #127313] Mon, 11 July 2005 04:24 Go to previous messageGo to next message
d.dineshkumar
Messages: 211
Registered: April 2005
Location: Kolkatta
Senior Member
Thanks william,
But does delete release the memory occupied by the pl/sql table.

Thanks
dinesh
Re: How to re-initialize a pl/sql table [message #127319 is a reply to message #127315] Mon, 11 July 2005 04:59 Go to previous messageGo to next message
himang
Messages: 282
Registered: March 2005
Location: Bangalore
Senior Member

yes, it does.
Re: How to re-initialize a pl/sql table [message #127332 is a reply to message #127319] Mon, 11 July 2005 05:14 Go to previous message
d.dineshkumar
Messages: 211
Registered: April 2005
Location: Kolkatta
Senior Member
Great
Thanks To all.

With Regards
Dinesh
Previous Topic: Muliple row output require in single row (comma seperate)
Next Topic: sql external table
Goto Forum:
  


Current Time: Fri Apr 25 02:34:29 CDT 2025