Using Like Operator in a decode function
Hi,
I am trying to find out if I can use the like operator in a decode function
like:
select decode(1234,like '%123%','123 is a match') from dual;
this reults in error ORA-00936: missing expression
is there any way to make this work?
thank you
SQL> ed
Wrote file afiedt.buf
1 WITH tbl AS (SELECT '201aaa' dt FROM DUAL UNION ALL
2 SELECT '123bbb' dt FROM DUAL UNION ALL
3 SELECT '567ccc' dt FROM DUAL UNION ALL
4 SELECT 'ab123ddd' dt FROM DUAL
5 )
6 SELECT dt,CASE WHEN dt like '%123%' THEN 'Match'
7 ELSE 'Not Matched'
8 END With_case
9 ,DECODE(REGEXP_SUBSTR(dt,'123'),NULL,'Not Match','Match') With_Regexp
10 ,DECODE(INSTR(dt,'123'),0,'Not Match','Match') With_Instr
11 ,DECODE(REPLACE(dt,'123'),dt,'Not Match','Match') With_Replace
12* FROM tbl
SQL> /
DT WITH_CASE WITH_REGE WITH_INST WITH_REPL
201aaa Not Matched Not Match Not Match Not Match
123bbb Match Match Match Match
567ccc Not Matched Not Match Not Match Not Match
ab123ddd Match Match Match MatchEdited by: Saubhik on Jul 26, 2010 5:24 AM
Edited by: Saubhik on Jul 26, 2010 5:40 AM
Edited by: Saubhik on Jul 26, 2010 5:40 AM
Similar Messages
-
Logical Operations in SQL decode function ?
Hi,
Is it possible to do Logical Operations in SQL decode function
like
'>'
'<'
'>='
'<='
'<>'
not in
in
not null
is null
eg...
select col1 ,order_by,decode ( col1 , > 10 , 0 , 1)
from tab;
select col1 ,order_by,decode ( col1 , <> 10 , 0 , 1)
from tab;
select col1 ,order_by,decode ( col1 , not in (10,11,12) , 0 , 1)
from tab;
select col1 ,order_by,decode ( col1 ,is null , 0 , 1)
from tab;
Regards,
infan
Edited by: user780731 on Apr 30, 2009 12:07 AM
Edited by: user780731 on Apr 30, 2009 12:07 AM
Edited by: user780731 on Apr 30, 2009 12:08 AM
Edited by: user780731 on Apr 30, 2009 12:08 AM
Edited by: user780731 on Apr 30, 2009 12:09 AMexample:
select col1 ,order_by,case when col1 > 10 then 0 else 1 end
from tab;
select col1 ,order_by,case when col1 <> 10 then 0 else 1 end
from tab;
select col1 ,order_by,case when col1 not in (10,11,12) then 0 else 1 end
from tab;As for testing for null, decode handles that by default anyway so you can have decode or case easily..
select col1 ,order_by,decode (col1, null , 0 , 1)
from tab;
select col1 ,order_by,case when col1 is null then 0 else 1 end
from tab; -
Problem in JDBC , when using LIKE operator. - VERY URGENT
Problem in JDBC , when using LIKE operator.
LINE 1 : String temp = "AA";
LINE 2 : String query = "select * from emp where EMPNAME like '*temp*' ";
LINE 3 : Staement st = con.createStaement();
LINE 4 : ResultSet rs = st.executeQuery(query);
'*' character is not getting evaluated. In MS ACCESS2000 only * is accepted instead of '%'. Moreover in MS ACCESS the like operator has to be used within double quotes as a String. whereas in other databases, it accepts single quotes as a String.
Ex:
In MS ACCESS
select * from emp where ename like "*aa*";
Other Databases
select * from emp where ename like '%aa%';
In my situation iam passing a Variable inside a like operator and '*' is used.
For the above Scenario, Please help me out.
If possible Kindly let me know the exact Syntax.
Please give me the answer as LINE1,LINE2,LINE3,LINE4,
I have verified in JDBC Spec also, it has been specified to use escape sequence.that too did not work.
Due to this, My project is in hold for about 4 days. I could not find a suitable solution.
Please help me out.I made a LIKE clause work with M$ Access, using PreparedStatement and the % wildcard:
escapeStr = "%";
String sql = "SELECT USERNAME, PASSWORD FROM USERS WHERE USERNAME LIKE ?";
PreparedStatement statement = connection.prepareStatement(sql);
statement.setString(1, ("user" + escapeStr));
ResultSet resultSet = statement.executeQuery();
while (resultSet.next())
System.out.println("username: " + resultSet.getObject("USERNAME") + " password: " + resultSet.getObject("PASSWORD")); -
How to use like operator in loop
Hi I am trying to use like operation in loop condition. the code is as follows:
loop at lt_mara into l_mara where l_mara like '%XXX'.
endloop
when i have the like operator like above its giving me an error that i cannot use like operator. Is there anyway that i can use like operation in loop at condition,
Thanks in advanceusing the ranges with CP option we can do that..
Populate the ranges mentioned below..
data: r_matnr type range of matnr,
w_matnr like line of r_matnr.
w_matnr-low = '%XXX'.
w_matnr-sign = 'I'.
w_matnr-option = 'CP'.
append w_matnr to r_matnr.
loop at lt_mara into l_mara where matnr in r_matnr.
endloop
Regards
Vijay Babu Dudla -
How to use LIKE operator in plsql
Hi
I wanted to select certain rows using like operator in plsql(Input should be given by the user). I have given my experiment here .I couldn't get any result.
As per sql syntax while using LIKE operator we should give search criteria within single quote.where as in plsql if we give within single quote its takes as string so no output is comming.what is solution ? How to use like operator in plsql?
sql syntax
SQL>SELECT customer_name FROM customer_header
WHERE customer_name LIKE 'B%' ; customer_name
Bala murali
Babu
Basker
plsql syntax
PROCEDURE pro_custheader_like ( v_cname IN varchar2
,answer OUT type_refcur_customer) IS
BEGIN
OPEN answer FOR
SELECT customer_name FROM customer_header
WHERE customer_name LIKE ( ' v_cname ' );
END pro_custheader_like;
execution command
sql>variable answer refcursor;
sql>set serveroutput on
sql>exec package_name.pro_custheader_like( 'R',:answer);
plsql successfully completed
sql>print :answer
no row selected
by
balamuralikrishnan.splsql syntax
PROCEDURE pro_custheader_like ( v_cname IN
varchar2
,answer OUT
type_refcur_customer) IS
N
OPEN answer FOR
SELECT customer_name FROM customer_header
WHERE customer_name LIKE ( v_cname );
END pro_custheader_like;
Try it without any quotes. And, let us know your feedback.
Regards.
Satyaki De.
Message was edited by:
Satyaki_De -
Using Like Operator For Parameter Fields
Hi All,
I have been figuring around this for few days, appreciated anyone know this could assit me
I have a report which having a mobile no parameter fields.
In my database, my mobile no was not a clean entry.
For eg, a standard mobile number from Malaysia was 60126143331.
1) 60 - indicate country code (MYS)
2) 12 - indicate mobile operator
3) 6143331 - indicate phone number
Usually, peoples will entry it as 6012-6143331 or 012-6143331 or 0126143331 or 60126143331. In my CR report, i have a static mobile no selection. Currently, my filter selection will be as below:
{pax.mobile_no} = {?p_mobileno}
any possible to change it to like? meaning to say, if user enter 012-6143331 it will know that this was 6012-6143331 and the records will be selected into the report.
Appreciated anyone know this could assits.
Thanks in advance.
Regards,
CKHi,
tq for ur prompt reply.
D value in my database r not fix, some mobile no could b 7 digits some could b up to 12 digits. But I jz want user to enter mobile no in 10 digits only. Example, mobile no in db wa 60126661233. However, user input in parameter selection could only 0126661233 without 6. In some situation if mobile no in db was 6012-6661233, user input willb only 0126661233 n this input will b match with data in db using like operator.
I m wondering can this b archieve in cr?
Tq
regards,
ck -
How to pass variable into lov sql query using like operator
hi.
i want to use a lov where i want to pass a variable using like operator.
my query is
select empno,name from table where empno like ':ed%';
my empno is A001 TO A199 AND B001 TO B199 so i want show either A% or B% empno
how can i do this ?
reagrdskindly press Shift+F1 at a time you face this error to see the exact Oracle error message.
and provide us with that detail
and its better if you start new topic for that error... because that will be new error,,,
-- Aamir Arif
Edited by: Aamiz on Apr 7, 2010 12:27 PM -
How tio use like operator in textitem to get the name
Oracle forms6i
Hai All
I have created an form to create an hierarchy list. I that I had an Text_item how can i use like operator to get the name to select. which trigger i need to use. when i select the name i need to get his employee code and other details
Thanks In Advance
Srikkanth.MA is the head of Dept 10 and three person are under A namelyHow will you know that B, C and D are under A is there any parent child relationship between Leader and Employee code? If yes, Then you can create the relationship between blocks no need to set where_clause programatically. So, relationship can be like...
leader_block.emp_code = emp_block.leader_code
AND leader_blokc.dep_code = emp_block.dep_codeSo, when you will query data in LEADER block it will show employees which are under LEADER which you queried in LEADER block.
Or if there is no relationship then how will you know that which employee under which leader?
b 002 10 1
c 003 10 1
d 004 10 1
When i enter the name of head corresponding other members in the department will need to display in the
Tabular format Or if you want to query the records only for department relation. Then as you said you create two blocks then create create the relationship using dep_code between those blocks.
like...
leader.dep_code = emp_block.dep_code-Ammad -
Get Result using LIKE operator
Hi All,
I am bit confused as to how to get this output using like operator :
select * from table1 where name like 'P&C%';
Here , since '&' is there , sql is prompting me to enter a value for C instead of giving output. I tried using escape but it is not working.
Can anybody tell me how to overcome this problem..?
Thanx.Alright,
Here you go. In 'SQL Editor' in PL/SQL Developer:
Pulled this off the PL/SQL Developer Manual:
Escape character
If you wish to use an ampersand in the SQL text that should not be interpreted as a substitution variable,
use a double ampersand instead. The following example will retrieve all employees from the ‘R&D’
department:
select * from emp
where emp.deptno in (select dept.deptno from dept
where dname = 'R&&D')
order by empno desc
If the text 'R&D' had been used instead, you would have been prompted for the D variable. -
How to use like operator in IFTHENELSE (BODS)
Hi All,
I want to find the value of ' % ASSOC%' in the name and replace it to 'Assoc.' using ifthenelse.
Can any one help me. Is there any similar fuction as LIKE operator. Can we give LIKE in ifthen else condition.
Thanks in advanceHi ,
if you have data ASSOC1,ASSOC2
and you want Output like Assoc.1,Assoc.2.
In this condition it is not possible with ifthenelse function
it will return output as Assoc.
Example Source:
If we use if then else condition. Then it will replace all the Data to Assoc.
Or else if you want to replace ASSOC to Assoc. Then you can use Search_Replace also
it will generate a XML script
The expected output as follows in the below screen. As per your requirement you can you any one of this.
Regards,
Akhileshkiran. -
How to use LIKE operator with PreparedStatement
Hi, I need to execute a query with the LIKE operator, but using a PreparedStatement. Can I do this, and if so what must my SQL look like with the wildcard characters '%' or '_'?
normal PS example: conn.prepareStatement("select * from mytable where name like ?");
If I try: conn.prepareStatement("select * from mytable where name like ?%");
I get: ORA-00911: invalid character
If I try: conn.prepareStatement("select * from mytable where name like '?%'");
I get: ORA-01006: bind variable does not exist
I must use a PreparedStatement, as my variable may contain illegal characters (like '), and using PreparedStatement.setString(1, var) will automatically escape it for me.
I could also use a normal Statement, but I need to escape my var ... is there a utility that will safely escape a String for an Oracle VARCHAR2??
Thanks in advance,
Stu MillerHmm, it seems you are right...
when my variable contains a '%' symbol, the PreparedStatement will NOT escape it, and thus it is treated like a wildcard. Therefore, I can just do
pstmt.setString(1, var+"%");
But, that may return more results than I'm asking for, as when 'var' contains a '%' symbol it is taken as a wildcard too.
I need each character in my variable to be taken literally, and only add a wildcard at the end. Basically, I need a STARTSWITH operator ;-)
It seems to me that escaping the sensitive characters in a String (which will differ depending on which operator is used), should be possible. I could write this, but I was hoping Oracle had already done it for me in some utility class. -
Problem in using like Operator
Hi, can any one help me in finding out if we can use a column name in the like operator...
for example i want to compare a column with another column in the same table...
column1 has a value as omer123
and cloumn2 has a value as omer
i just want to find out those records in which column2 contains in column1
column1 column2 column3
omer12 omer This is the one
12jack sda asds
1233 asd asd
12Aug212 dasd adsasd
i want to write a query which will return ' This is the one ' as its col2 is in col1
This is what i wrote but the problem is in the like operator
select t1.cloumn3
from table_name t1,table_name t2
where t1.id = t2.id
and t1.column1 like %t2.column2%
plz help..
thankzYour wildcard characters need to be quoted, thus:
SELECT t1.column3
FROM table_name t1,
table_name t2
WHERE t1.id = t2.id
AND t1.column1 LIKE '%'||t2.column2||'%' ; -
My table Name is
DESC FUNCTIONS
Func_Id VARCAHR2(15)
dESCRIPTION VARCAHR2(100)
fLAG VARCHAR2(1)
This table is haivng the following data
SA100
SB100
SA105
SB105
SC105
SA200
SB200
SA205
SB205
SA300
SB300
I want to implement the below update
Update functions set flag = 'Y' where func_id like 'S%100'
Update functions set flag = 'Y' where func_id like 'S%200'
Update functions set flag = 'Y' where func_id like 'S%300'
How can i implement the above 3 SQLs into a Single SQL statement?
How can i merge the above 3 SQls into a Single SQL?You could also use regexp_like:
with functions as
select 'SA100' func_id from dual union all
select 'SB100' func_id from dual union all
select 'SA105' func_id from dual union all
select 'SB105' func_id from dual union all
select 'SC105' func_id from dual union all
select 'SA200' func_id from dual union all
select 'SB200' func_id from dual union all
select 'SA205' func_id from dual union all
select 'SB205' func_id from dual union all
select 'SA300' func_id from dual union all
select 'SB300' func_id from dual
select * from functions where regexp_like(func_id,'^S.*[123]00$')
Update functions set flag = 'Y' where regexp_like(func_id,'^S.*[123]00$'); -
How to achive equivalent of contains in java using Like operator
Hi,
Could anyone please enlighten me on this issue.
I need to achieve through the query to reduce the unnecessary of loop through.
Lets say:
I have a table called BLACKLISTPASSWORD with column BPW.
example record in column (BPW)
Welcome
Welcome1
Welcome123
I want make a query like
SELECT BPW
FROM BLACKLISTPASSWORD
WHERE lower(BPW) LIKE 'welcome1234%'Expecting a result true if any sequence matches in above case expecting true bcz Welcome123 is there in DB.
Plz correct me in the query to achieve this.
Edited by: Deekay on Aug 2, 2012 12:40 AMDeekay wrote:
Hi,
Could anyone please enlighten me on this issue.
I need to achieve through the query to reduce the unnecessary of loop through.
Lets say:
I have a table called BLACKLISTPASSWORD with column BPW.
example record in column (BPW)
Welcome
Welcome1
Welcome123
I want make a query like
SELECT BPW
FROM BLACKLISTPASSWORD
WHERE lower(BPW) LIKE 'welcome1234%'Expecting a result true if any sequence matches in above case expecting true bcz Welcome123 is there in DB.
Plz correct me in the query to achieve this.
Edited by: Deekay on Aug 2, 2012 12:40 AMYou can use as
SELECT BPW
FROM BLACKLISTPASSWORD
WHERE lower(BPW) LIKE 'welcome%'This will return
Welcome
Welcome1
Welcome123
If you want Output as
>
Welcome1
Welcome123
>
i.e. Welcome followed by a/more digits; Below works on Oracle 10g or higher.
SELECT BPW
FROM BLACKLISTPASSWORD
WHERE regexp_like(BPW, 'welcome[[:digit]]+', 'i'); -
Using -like operator to select recipients for Dynamic Distribution Group
Dear Scriptor,
I got few thousand of data and would like to select recipient according to the CustomAttribute1.
Below is the sample data in my database.
Name: User1, CustomAttribute1: aa, bb, cc
Name: User2, CustomAttribute1: aa, bb
Name: User3, CustomAttribute1: bb, cc, dd
If I run the script as below,
New-DynamicDistributionGroup -name "myDyna.bb" -RecipientFilter {(CustomAttribute1 -like 'aa*')}
The return result is User1 and User2
When I run the script as below,
New-DynamicDistributionGroup -name "myDyna.bb" -RecipientFilter {(CustomAttribute1 -like 'bb*')}
No result returned
How can I overcome this issue?
Thanks.Below are my sample data in O365.
Type
Identity
UserPrincipalName
DisplayName
FirstName
LastName
CustomAttribute1
Mailbox
77771111
[email protected]
7777 #1
7777
#1
a1, a2, a3
Mailbox
77772222
[email protected]
7777 #2
7777
#2
a1, a2
Mailbox
77773333
[email protected]
7777 #3
7777
#3
d4, a1
Mailbox
77774444
[email protected]
7777 #4
7777
#4
a2, e5, f6
Mailbox
77775555
[email protected]
7777 #5
7777
#5
g7, h8, i9
Mailbox
77776666
[email protected]
7777 #6
7777
#6
g8, i9, a3
I would like to create a DynamicDistributionList where CustomAttibute1 contain "a2".
The expecting result are 77771111, 77772222 and 77774444.
How can I write the script?
I am using Windows Azure Active Directory Module for Windows Powershell. I run the $PSVersionTable.PSVersion and it returned me Major=4, Minor=0, Build=-1, and Revision=-1.
This works for you case:
New-DynamicDistributionGroup -name "myDyna.bb" -RecipientFilter {CustomAttribute1 -like '*a2*'}
Do not use parens "()".
¯\_(ツ)_/¯
Maybe you are looking for
-
Dears, I have a concurrent with bursting. Template type is Excel. Bursting Control File: <xapi:requestset xmlns:xapi="http://xmlns.oracle.com/oxp/xapi" type="bursting"> <xapi:request select="/XXRCVSHIPMENTSBURST/LIST_G_PO_NO"> <xapi:delivery> <xapi:e
-
How to implement Approval hierarchy for Sales Order in Order Management.
Hi, We need approval process for sale orders in Order Management module. Currently we are using credit HOLD option for orders at shipping level. The issue we are facing now is we can not cancel those orders who contains Service Line item in it while
-
Re:Linking between the two components.
Hi Friends, How to link a view in one component to the other component and the view in the second component should be read only..For example am having a submit button in first component when I click on the submit button the second component Approve b
-
Material Replication from Backend: DNL_CUST_PROD0 is stuck in SMQ2
Hi Experts, I am getting this error while running R3AS for DNL_CUST_PROD0 adapter and checking the SMQ2 is getting into SYSFAIL status. The detail error says "Incorrect parameter with CALL FUNCTION" for Function Module BAPI_CRM_SAVE Even, adapter DNL
-
Rejected pictures are gone.
Hello. I hope I will use the right terms because my english isn't that good. I upgraded from iPhoto to Aperture early 2012. I just imported my library and everything was fine. Some time ago I dumped my old iphoto library. Then I wanted to split my Ap