【问题标题】:regexp_like not accepting variable patternregexp_like 不接受变量模式
【发布时间】: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


    【解决方案1】:

    您将双引号放在不区分大小写的参数上,但也忘记将其放在模式参数上。您必须按如下方式修改程序的每个执行立即数:

    EXECUTE IMMEDIATE 'CREATE TABLE '||create_table||' AS SELECT DISTINCT employeeid FROM employee WHERE REGEXP_LIKE(name, ''' || searchvalue || ''',''i'')';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-12
      • 1970-01-01
      • 2019-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 2015-01-15
      相关资源
      最近更新 更多