日期:2014-05-17 浏览次数:21034 次
表是scott中的emp表。。
create or replace package type_pack
is
type cur_type is ref cursor;
end;
--------
create or replace procedure sel_insert_tab_emp2(p_empno number, p_ename varchar2,
p_job varchar2, p_mgr number, p_hiredate varchar2,
p_sal number, p_comm number, p_deptno number,v_page_data out type_pack.cur_type)
as
l_sql_com varchar2(100);
begin
l_sql_com := 'select * from emp where';
if p_empno is not null then
l_sql_com := l_sql_com || 'empno := ' || p_empno ;
end if;
if p_ename is not null then
l_sql_com := l_sql_com || 'and ename := ' || p_ename;
end if;
if p_job is not null then
l_sql_com := l_sql_com || 'and job := ' || p_job;
end if;
if p_mgr is not null then
l_sql_com := l_sql_com + 'and mgr := ' || p_mgr ;
end if;
if p_hiredate is not null then
l_sql_com := l_sql_com || 'and hiredate := ' || to_date(p_hiredate,'yyyy-mm-dd');
end if;
if p_sal is not null then
l_sql_com := l_sql_com || 'and sal := ' || p_sal;
end if;
if p_comm is not null then
l_sql_com := l_sql_com || 'and comm := ' || p_comm;
end if;
if p_deptno is not null then
l_sql_com := l_sql_com || 'and deptno := ' || p_deptno;
end if;
open v_page_data for l_sql_com; --mark! 这报错。。
end;
----------------
--测试调用(注意,抓取游标中数据,类型的问题)
declare
v_page_data type_pack.cur_type;
v_data_row emp%rowtype;
begin
dbms_output.put_line('diaoyong');
pro_sel_tab_emp2(7788, null, null, null, null, null, null,null, v_page_data);
fetch v_page_data into v_data_row;
dbms_output.put_line('员工编号' || ' 员工姓名' ||' 部门名称');
while v_page_data%found loop
dbms_output.put_line(v_data_row.empno || ' ' || v_data_row.ename || ' ' ||v_data_row.deptno);
fetch v_page_data into v_data_row;
end loop;
close v_page_data;
end;
存储过程编译不出错。。
测试程序报错如下。
ORA-00933: SQL 命令未正确结束
ORA-06512: 在 "SDD.PRO_INSERT_TAB_EMP2", line 42
ORA-06512: 在 line 6
我这个存储过程逻辑还是有点问题的。不过我想先测试通过后再改的。。
求报错原因。