Oracle : Procedure throws Invalid Datatype Error during execution ORA-00902: invalid datatype -


   create table t1 (emp_name varchar2 (40));      insert t1          values ('vinoth');      commit;      create table t2 (emp_name varchar2 (40));      create or replace package test_pkg_v            procedure p_main (p_status out varchar2);         type t1_type record (emp_name t1.emp_name%type);         type t1_tbl table of t1_type;     end test_pkg_v;     /      create or replace package body test_pkg_v            procedure p_main (p_status out varchar2)                  lv_t1_tbl   t1_tbl := t1_tbl ();            cursor t1_cur                        (select emp_name t1);         begin           open t1_cur;            loop              fetch t1_cur                 bulk collect lv_t1_tbl                 limit 10000;               insert t2 (emp_name)                 select emp_name table (lv_t1_tbl);               exit when t1_cur%notfound;           end loop;            commit;        exception           when others                        p_status := 'fail';              raise;        end p_main;     end test_pkg_v; / declare var varchar2(4000); begin test_pkg_v.p_main(var); end; 

while executing procedure throws ora-00902: invalid datatype. if comment out insert statement inside procedure, running fine. problem here , me resolution.

for able that, types have created outside of package. here corrected version. downside is, types beeing created, if alter table change type of column, might forget modify type.

create type t1_type object ( emp_name varchar2(40)); create type t1_tbl table of t1_type;  create or replace package test_pkg_v    procedure p_main (p_status out varchar2); end test_pkg_v; /  create or replace package body test_pkg_v    procedure p_main (p_status out varchar2)          lv_t1_tbl   t1_tbl;        cursor t1_cur                (select t1_type(emp_name) emp_name t1);     begin       open t1_cur;        loop          fetch t1_cur             bulk collect lv_t1_tbl             limit 10000;           insert t2 (emp_name)             select emp_name table (lv_t1_tbl);           exit when t1_cur%notfound;       end loop;        commit;    exception       when others                p_status := 'fail';          raise;    end p_main; end test_pkg_v; / 

if want types generic , adapt table, think have :

create or replace package test_pkg_v     type t1_type record (emp_name t1.emp_name%type);    type t1_tbl table of t1_type;     procedure p_main (p_status out varchar2);    function get_t1 return t1_tbl pipelined;  end test_pkg_v; /  create or replace package body test_pkg_v  cursor t1_cur (select emp_name t1);  function get_t1 return t1_tbl pipelined   lv_t1_tbl t1_tbl; begin   open t1_cur;   fetch t1_cur bulk collect lv_t1_tbl;   close t1_cur;   idx in 1..lv_t1_tbl.count loop     pipe row (lv_t1_tbl(idx));   end loop; end;  procedure p_main (p_status out varchar2) begin   insert t2 (emp_name) select emp_name table (get_t1);   commit; exception   when others     p_status := 'fail';     raise; end p_main; end test_pkg_v; / 

alternatively, iterating directly on cursor :

create or replace package test_pkg_v     type t1_type record (emp_name t1.emp_name%type);    type t1_tbl table of t1_type;    procedure p_main (p_status out varchar2);  end test_pkg_v; /  create or replace package body test_pkg_v  procedure p_main (p_status out varchar2)   cursor t1_cur (select emp_name t1); begin   current_row in t1_cur loop     insert t2 (emp_name) values (current_row.emp_name);   end loop;   commit; exception   when others     p_status := 'fail';     raise; end p_main;  end test_pkg_v; / 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -