Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ORA-06531: Reference to uninitialized collection

Posted on 2004-10-04
7
Medium Priority
?
1,887 Views
Last Modified: 2008-01-09
Hi,

I have a procedure that executes os commands
 1) pr_runOsCmd uses java in the internal oracle jvm to host out to the os.
It appends the windows start cmd into the cmd line.

I had it working, my db crashed and now I get an ORA-06531: Reference to uninitialized collection when I try to run it.

  FUNCTION fn_exec_cmd(p_shell VARCHAR2,p_cmd VARCHAR2,p_output IN OUT cmd_output) RETURN VARCHAR2 as
        LANGUAGE JAVA NAME 'com.utils.OSExecutor.executeCommand(java.lang.String,java.lang.String,oracle.sql.ARRAY[]) return java.lang.String';
      
-----------

cmd_output is declared in the same schema

CREATE OR REPLACE
type CMD_OUTPUT as table of varchar2(255)
/
I have granted synonyms, privileges to all the schemas but still cant get it working.

How do I initialize this collection?
0
Comment
Question by:joehodge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 13

Expert Comment

by:anand_2000v
ID: 12218552
Hello

Make sure the collection variable is initialized with a constructor which initializes the number of elements which are needed by the procedure.

Example:

create type event_times
as varray(6) of date;

create or replace procedure test as
et event_times;
begin
et := event_times(SYSDATE, NULL, NULL);
et(2) := to_date('13-JAN-95');
dbms_output.put_line('Count : '||et.COUNT);
dbms_output.put_line('Limit : '||et.LIMIT);
et.extend(1,1);
dbms_output.put_line('et(1) : '||et(1));
dbms_output.put_line('et(2) : '||et(2));
dbms_output.put_line('et(3) : '||et(3));
dbms_output.put_line('et(4) : '||et(4));
end;
0
 
LVL 13

Expert Comment

by:anand_2000v
ID: 12218583
with your type use
A:=fn_exec_cmd('ABC','XYZ',CMD_OUTPUT('A','B','C','X','Y','Z'))
0
 

Author Comment

by:joehodge
ID: 12218655
Hi,

------------------------------
FUNCTION fn_RunOsCmd(p_cmd IN VARCHAR2,    tab_cmdoutput IN OUT osutil_cmd_output) RETURN VARCHAR2
IS

tab_output cmd_output;
tab_errors cmd_output;                                    
lv_shell VARCHAR2(10);
lv_cmd VARCHAR2(255);
lv_success VARCHAR2(32767);
lv_output_count INTEGER :=0;

   BEGIN

   IF UPPER(substr(p_cmd,1,3)) ='RSH' THEN
           lv_shell := 'rsh';
        lv_cmd := substr(p_cmd,4,length(p_cmd)-3);
   ELSE
            lv_shell := 'cmd /c';
         lv_cmd := p_cmd;
   END IF;
   -- Execute command
   lv_success := fn_exec_cmd(lv_shell,lv_cmd,tab_output);

------------------------------------------
This is how the function works so I'm assuming that lv_success is the constructor?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:joehodge
ID: 12218689

lv_success :=fn_exec_cmd(lv_shell,lv_cmd,CMD_OUTPUT('A','B','C','X','Y','Z'))
results in
PLS-00363: expression 'CMD_OUTPUT' cannot be used as an assignment target

and

lv_success :=fn_exec_cmd(lv_shell,lv_cmd,tab_output('A','B','C','X','Y','Z'))
results in
PLS-00316: PL/SQL TABLEs must use a single index
0
 

Author Comment

by:joehodge
ID: 12218707
its nearing hometime so I've just doubled the points!
0
 
LVL 13

Accepted Solution

by:
anand_2000v earned 1000 total points
ID: 12218732
oh right it's an in out parameter...my mistake in not noting that...
you'll just have to add
tab_output:=CMD_OUTPUT('A','B','C','X','Y','Z');
before
lv_success := fn_exec_cmd(lv_shell,lv_cmd,tab_output);
it should work
0
 

Author Comment

by:joehodge
ID: 12218780
job done!

I've awarded you the points.

I didn't need that line of code before so can I initialize the collection outside of the function or do I have to leave it there?

thanks again
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question