IF lv_Res = 1 THEN
NULL;
ELSE
RAISE java_broken;
END IF;
--PL\SQL wrapper for the java class ExecCmd which is stored in the database
FUNCTION fn_exec_cmd(p_shell VARCHAR2,p_cmd VARCHAR2,p_output IN OUT cmd_output) RETURN VARCHAR2
as
LANGUAGE JAVA NAME 'com.bat.utils.OSExecutor.executeCommand(java.lang.String,java.lang.String,oracle.sql.ARRAY[]) return java.lang.String';
FUNCTION fn_RunOsCmd(p_cmd IN VARCHAR2, tab_cmdoutput IN OUT osutil_cmd_output) RETURN VARCHAR2 IS
IF tab_output.COUNT >0 THEN
FOR x IN tab_output.first..tab_output.last LOOP
tab_cmdoutput(lv_output_count+x) := tab_output(x);
END LOOP;
lv_output_count := tab_cmdoutput.COUNT;
END IF;
RETURN lv_success;
I did not have this issue before. I created a collection as:
CREATE OR REPLACE
type CMD_OUTPUT as table of varchar2(255)
/
again, originally this worked. I then started getting
ORA-06531: Reference to uninitialized collection
the only way I could get round this was to initialse the collection
e.g.
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;
the procedure then has no error message but will not execute the command.
I know there are no issues with the java program so it has to be due to me putting
a) tab_output:= CMD_OUTPUT('A','B','C','X','Y','Z');
or
b) not setting up the correct privileges in the database