Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"local collection types not allowed" error in PL/SQL ORA-06550

i am trying trying to get a query from oracle table called "sys.all_objects" into a string variable, so then i can give it to "dbms_obfuscation_toolkit.DESEncrypt" as input, after than encrypted string will go in to "utl_file" so i can write it into a txt file.

Here's the problem, when i try to query with this code;

DECLARE
TYPE name_array is array(50) OF varchar2(100);
var_input  name_array; 

BEGIN
SELECT owner
  INTO var_input
  FROM sys.all_objects;

  FOR i IN var_input.FIRST .. var_input.LAST
    LOOP
        dbms_output.put_line(var_input(i));
    END LOOP;
END;

and the error is;

ORA-06550: line 7, column 12:
PLS-00642: local collection types not allowed in SQL statements

any idea about geting through this issue ?

for the ones who want to see the full code ;

CREATE OR REPLACE DIRECTORY data AS 'd:\folder';
GRANT read, write ON DIRECTORY data TO PUBLIC;

DECLARE
var_input  varchar2(64) := 'Rndminpt';
var_key    varchar2(16) := 'Anahtar1'; 
var_enc    varchar2(1024);
var_dec    varchar2(1024);
var_file   utl_file.file_type;

BEGIN

-- (query part)

    dbms_obfuscation_toolkit.DESEncrypt(
        input_string     =>  var_input,
        key_string       =>  var_key,
        encrypted_string =>  var_enc);
    dbms_output.put_line('Encrypted...');

var_file := utl_file.fopen('DATA','textfile.txt','W');            
    utl_file.put_line(var_file,var_enc);
    utl_file.fclose(var_file);        
dbms_output.put_line('Writen in to text... ');      
END;
like image 578
Burak Atar Avatar asked Dec 10 '11 18:12

Burak Atar


1 Answers

This is just a clarification to A.B.Cade's answer. The cursor has nothing to do with the problem.

The root cause of

PLS-00642: local collection types not allowed in SQL statements

is sql into can be used only with a PL/SQL variable or record but not with a PL/SQL collection.

With PL/SQL collections one have to use select bulk collect into instead.

(Yes - I agree the error message could be more descriptive.)

See also:

  • SELECT INTO Statement

Examples

The following anonymous block compiles with PLS-00642 because select into can't be used with collections:

declare
  type dual_list_t is table of dual%rowtype;
  v_duals dual_list_t;
begin
  select *
    into v_duals
    from dual
  connect by level <= 2
  ;
end;
/

The following anonymous block compiles fine:

declare
  type dual_list_t is table of dual%rowtype;
  v_duals dual_list_t;
begin
  select *
    bulk collect into v_duals
    from dual
  connect by level <= 2
  ;
end;
/
like image 173
user272735 Avatar answered Sep 20 '22 21:09

user272735