【发布时间】:2016-05-31 05:00:24
【问题描述】:
我有一张桌子
> create table employee(employeeid number(10), name varchar2(100),deptno
>
> number(10));
此表中有 1000 行。 当我尝试创建一个过程,该过程将在运行时搜索一个值并创建一个临时表并将所有结果插入该表中。 在过程中:tableName 是应用程序将传递的临时表的名称。 搜索字段是进行搜索的列名。 Searchvalue 将成为模式。
create or replace PROCEDURE quick_search (tableName IN varchar2,searchfield IN VARCHAR2,searchvalue IN varchar2) IS v_tableName varchar2(100); begin select count(tname) into v_tableName from tab where lower(tname) = tableName; if v_tableName = 1 then EXECUTE IMMEDIATE 'DROP TABLE '||tableName||''; case searchfield when 'name' then execute immediate 'create table '||create_table||' as Select Distinct employeeid FROM employee where regexp_like(NAME ,'||searchvalue||',''i'')'; when 'deptno' then execute immediate 'create table '||create_table||' as Select Distinct employeeid FROM employee where regexp_like(deptno ,'||searchvalue||',''i'')'; end case; end if; if v_tableName =0 then case searchfield when 'name' then execute immediate 'create table '||create_table||' as Select Distinct employeeid FROM employee where regexp_like(NAME ,'||searchvalue||',''i'')'; when 'deptno' then execute immediate 'create table '||create_table||' as Select Distinct employeeid FROM employee where regexp_like(deptno ,'||searchvalue||',''i'')'; end case; end if; end;
当我执行这个时:
exec exec quick_search ('temp1','name','barbara') ;
我的员工表中不存在名为 temp1 和 barbara 的 exixt 对象。
我收到错误 错误报告 - ORA-00904: "BARBARA": 无效标识符 ORA-06512:在“SCOTT.QUICK_SEARCH”,第 53 行 ORA-06512: 在第 1 行 00904. 00000 - “%s:无效标识符” *原因: *行动:
【问题讨论】:
标签: oracle plsql plsqldeveloper