Oracle 类regexp_表达式不使用变量

Oracle 类regexp_表达式不使用变量,oracle,Oracle,“错误”字段中没有记录。注释掉的代码不返回任何内容,但当使用变量时,它返回一条记录。我做错了什么 test varchar(5); test := '1'; select * from timedetail where empnum = '013061361' and tsdate = '1-nov-13' --and regexp_like(errors, '[1,0]') and regexp_like(errors, '[ || test || ]') 您没有变量:“[| |

“错误”字段中没有记录。注释掉的代码不返回任何内容,但当使用变量时,它返回一条记录。我做错了什么

test varchar(5);
test := '1';
select  * from timedetail 
where empnum = '013061361' and tsdate = '1-nov-13' 
--and  regexp_like(errors, '[1,0]')
and  regexp_like(errors, '[ || test || ]')

您没有变量:“[| | test | |]]”是字符串。
您需要这个“['| | test | |”]”

Oracle
regexp\u like
使用单引号分隔表达式。要使用变量,您需要将regex元字符从变量中分离出来,因此只需连接部分即可完成需求。使用
'i'
选项可以忽略区分大小写

试试这个:

   test varchar(5);
   test := '1';

 select  * from timedetail 
  where empnum = '013061361' 
    and tsdate = '1-nov-13' 
    and  regexp_like(errors, test,'i'); --matches any string containing 1
--and  regexp_like(errors,'^' ||  test,'i') --matches any string beginning 1
--and  regexp_like(errors, test || '$','i') --matches any string ending 1
--and  regexp_like(errors, '^' || test || '$','i') --matches any string exactly 1

当我尝试运行时,它说测试无效标识符,但这是由于您使用参数的方式。对于许多工具,在SQL中使用参数的语法是不同的。Oracle SQL开发人员:。SQL*Plus:我没有听懂。我使用的是OracleOracle是DBMS,它是一个引擎。问题是如何访问它?两个标准工具是SQL*Plus和Oracle SQL Developer。但也有TOAD、PL/sqldeveloper等。SQL中的参数不是标准的一部分,因此每个人都可以自由地以自己的方式实现它们。如果这是python、c#或其他语言代码的一部分,那么您将使用特定于驱动程序的绑定变量。