2

The record has nothing in the errors field. The commented out code doesn't return anything but when the variable is used it returns a record. What am I doing wrong?

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 || ]')

2 Answers 2

0

you don't have a variable: '[ || test || ]' is a string. you need this one '[' || test || ']'

Sign up to request clarification or add additional context in comments.

10 Comments

It says Test invalid identifier when I try and run
But that is due to how you use your parameters. syntax to use parameters in SQL is different for many tools. Oracle SQL Developer: stackoverflow.com/questions/5653423/… . SQL*Plus: docs.oracle.com/cd/B19306_01/server.102/b14357/ch5.htm
I'm not following. I'm using Oracle
Oracle is DBMS, it is an engine. Question is how you access it? Two standard tools are SQL*Plus and Oracle SQL Developer. But there are also TOAD, PL/SQL Developer, and others. Parameters in SQL are not part of a standard so everyone free to implement them their own way.
And if this is part of the code in python, c# or another language, you will be using bind variables that are driver specific.
|
0

Oracle regexp_like uses single quotes to delimit the expression. To use a variable you'll need to isolate the regex metacharacters from the variable, so just concatenate the parts to complete the requirement. Use the 'i' option is to ignore case sensitivity.

Try this:

   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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.