Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Cast+Select from pl/sql table question( BULK Operations in SQL)

Cast+Select from pl/sql table question( BULK Operations in SQL)

From: MONAGHAN, Mike <Monagham_at_oup.co.uk>
Date: Fri, 26 Jan 2001 13:56:56 -0000
Message-Id: <10753.127576@fatcity.com>


Andor asked about selecting on PL/SQL tables. You have to use TABLE as well as CAST. The 8.1.6 manual (PL/SQL user's guide, chapter 4) is quite good on this topic. Here's some demonstrated PL/SQL that works for me (on 8.1.6.3 on Solaris2.6). Note that the array types (varchar20_table_type and int_table_type, both owned by user asuer) must already exist, and execute permission granted appropriately.

create or replace type int_table_type as table of number(8)
/

grant execute on int_table_type to public
/

create or replace type varchar20_table_type as table of varchar2(20)
/

grant execute on varchar20_table_type to public
/

declare

	array1		auser.int_table_type := auser.int_table_type();
	array2		auser.int_table_type := auser.int_table_type();
	array3		auser.varchar20_table_type :=
auser.varchar20_table_type();
	array_count	number;
begin
	array1.extend(5);
	array1(1):=1;
	array1(2):=2;
	array1(3):=3;
	array1(4):=6;
	array1(5):=7;
	
	dbms_output.put_line('array1 ========================');
	for i in array1.FIRST .. array1.LAST
	loop
		dbms_output.put_line('array1('||i||'): ' ||
to_char(array1(i)) );
	end loop;
	
	select count(*) into array_count
	from table(cast(array1 as auser.int_table_type)) as dummy_table;
	dbms_output.put_line('COUNT1: ' || array_count);
			
	array2.extend(4);
	array2(1):=1;
	array2(2):=2;
	array2(3):=4;	
	array2(4):=5;
	
	dbms_output.put_line('array2 ========================');
	for i in array2.FIRST .. array2.LAST
	loop
		dbms_output.put_line('array2('||i||'): ' ||
to_char(array2(i)) );
	end loop;
		
	select count(*) into array_count
	from table(cast(array2 as auser.int_table_type)) as dummy_table;
	dbms_output.put_line('COUNT2: ' || array_count);

	/* */
	select status bulk collect into array3
	from article a
	where a.subject_id in 
		(select *
		from table(cast(array1 as auser.int_table_type)) as
dummy_table1
		)
	order by 1;
		
	dbms_output.put_line('array3 ========================');
	for i in array3.FIRST .. array3.LAST
	loop
		dbms_output.put_line('array3('||i||'): ' || array3(i) );
	end loop;
	
	select count(*) into array_count
	from table(cast(array3 as auser.varchar20_table_type)) as
dummy_table;
	dbms_output.put_line('COUNT3: ' || array_count);
	dbms_output.put_line('COUNT3: ' || array3.COUNT);
Received on Fri Jan 26 2001 - 07:56:56 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US