Using like operator with attributes in select command
Hi,
I have a table with the attributes as DID, PNO,AGE, DEPARTMENT, DATEOFADM, CHARGES, ADDRESS, DOD
I want to display the records with the months in DOD and DATEOFADM same. How can I do so? I also want to do the same with the dates in the 2 attributes.
Thanks
Edited by: 1004111 on May 23, 2013 1:51 AM
Hi,
Please read SQL and PL/SQL FAQ
When you put some <b>code or output</b> please enclose it between two lines starting with {noformat}<b></b>{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
You should post create table and insert statement for your requirement.
You can check if 2 dates have the same month in either way:-- this is comparing year and month
SELECT *
FROM yourtable
WHERE TRUNC(dod,'MM')=TRUNC(dateofadm,'MM');
-- or in case you want to compare only months no matter the year
SELECT *
FROM yourtable
WHERE EXTRACT(MONTH FROM dod) = EXTRACT(MONTH FROM dateofadm);
Regards.
Al
Similar Messages
-
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. -
How to use LIKE Operator with my query requriment
HI all,
I have a requirement as follows
EMPID ENAME JOB SAL
10 RAJ KAMAL MANAGER 25000
20 KAMAL RAJ NAYAK CLERK 4000
30 NARENDAR GUPTA ANALYST 20000
40 ASHUTOSH GUPTA DEVELOPER 10000
50 ASHUTOSH NAYAR PROGRAMMER 15000
i am searching enames such that i need to get the whole name even if i search with just a single LETTER/WORD immaterial of the order they exist in the name for which i need to get the whole name.(INFACT WORD comparision)
ex:
1) select * from emp where ename like '%ka%'
i am getting:
10 RAJ KAMAL MANAGER 25000
20 KAMAL RAJ NAYAK CLERK 4000
This is not what i need i need just word camparision not letters comparision let me tell you...
select * from emp where ename like '%amal%'
Even for this query ill get the same output.. this is not my option to go..
I need just word comparision with starting letter and immaterial of the word position in the name
If it is possible to do with query please let me know..
Thanking you
Narendar VishwanathamFull example:
SQL> ed
Wrote file afiedt.buf
1 with e as (select 10 as empid, 'RAJ KAMAL' as ename, 'MANAGER' as job, 25000 as sal from dual union all
2 select 20, 'KAMAL RAJ NAYAK', 'CLERK', 4000 from dual union all
3 select 30, 'NARENDAR GUPTA', 'ANALYST', 20000 from dual union all
4 select 40, 'ASHUTOSH GUPTA', 'DEVELOPER', 10000 from dual union all
5 select 50, 'ASHUTOSH NAYAR', 'PROGRAMMER', 15000 from dual)
6 -- END OF TEST DATA
7 select *
8 from e
9* where regexp_like(ename,'(^| )KA( |$)')
SQL> /
no rows selected
SQL> ed
Wrote file afiedt.buf
1 with e as (select 10 as empid, 'RAJ KAMAL' as ename, 'MANAGER' as job, 25000 as sal from dual union all
2 select 20, 'KAMAL RAJ NAYAK', 'CLERK', 4000 from dual union all
3 select 30, 'NARENDAR GUPTA', 'ANALYST', 20000 from dual union all
4 select 40, 'ASHUTOSH GUPTA', 'DEVELOPER', 10000 from dual union all
5 select 50, 'ASHUTOSH NAYAR', 'PROGRAMMER', 15000 from dual)
6 -- END OF TEST DATA
7 select *
8 from e
9* where regexp_like(ename,'(^| )KAMAL( |$)')
SQL> /
EMPID ENAME JOB SAL
10 RAJ KAMAL MANAGER 25000
20 KAMAL RAJ NAYAK CLERK 4000
SQL> -
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 -
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 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 -
Error while using between operator with sql stmts in obiee 11g analytics
Hi All,
when I try to use between operator with two select queries in OBIEE 11g analytics, I'm getting the below error:
Error Codes: YQCO4T56:OPR4ONWY:U9IM8TAC:OI2DL65P
Location: saw.views.evc.activate, saw.httpserver.processrequest, saw.rpc.server.responder, saw.rpc.server, saw.rpc.server.handleConnection, saw.rpc.server.dispatch, saw.threadpool.socketrpcserver, saw.threads
Odbc driver returned an error (SQLExecDirectW).
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 27002] Near <select>: Syntax error [nQSError: 26012] . (HY000)
can anyone help me out in resolving this issue.Hi All,
Thank u all for ur replies, but I dint the exact solution for what I'm searching for.
If I use the condition as
"WHERE "Workforce Budget"."Used Budget Amount" BETWEEN MAX("Workforce Budget"."Total Eligible Salaries") AND MAX("Workforce Budget"."Published Worksheet Budget Amount"",
all the data will be grouped with the two columns which I'm considering in the condition.
my actual requirement with this query is to get the required date from a table to generate the report either as daily or weekly or monthly report. If I use repository variables, variables are not getting refreshed until I regenerate the server(which I should not do in my project). Hence I have created a table to hold weekly start and end dates and monthly start and end dates to pass the value to the actual report using between operator.
please could anyone help me on this, my release date is fast approaching. -
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 -
Hi, Having Problems using the LIKE Operator with the Clob Datatype. Does any one know if its possible.
Thanks
EmerIt's not possible.
try use DBMS_LOB.INSTR instead... -
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 we can use OR operator with string in java??
Gaurav1 wrote:
its logical OR operator;how can we use it with matcher classLike its been said already. The "logical OR" is used the same everywhere.
Why don't you post the code you're having problems with. (Only the relevant areas, please. And use code tags.) -
How to use glob search with the wildcard in command find?
How to use glob search with the wildcard in command find?
I want to find any file its names begin with "readme" string using command find. Why the following command cannot work?
$find /usr/share/doc -name readme*
However, the following commands can work?
$find /usr/share/doc -name readme\* or
$find /usr/share/doc -name readme'*'
I want to know: After using the “\” or ' ', why the wildcard do not become a character "*"?(still a metacharacter).
Another question:
I want to find any file its names begin with "readme*" string using the command find.What command should I use?I want to know: After using the “\” or ' ', why the
wildcard do not become a character "*"?(still a
metacharacter). The backslash is known as an escape character. It means 'use the character value of the next character, not the special meaning' It is used in a lot of places such as command line, global regular expression patterns, and editors such as vi.
In a typical shell, the splat (*) expands to all file names before passing the file names to the current command. So a \* sequence tells the shell to pass a *, not a list of file names, to the command.
Demo - OpenSuSE Linux 10.3
- I have a bunch of files. Let's list those that end in grid. Create one called *grid, and list again
pops@fuzzyVM:~/pops> ls
a b c startgrid stopgrid
pops@fuzzyVM:~> ls *grid
startgrid stopgrid
pops@fuzzyVM:~> ls \*grid
ls: cannot access *grid: No such file or directory
pops@fuzzyVM:~> touch '*grid'
pops@fuzzyVM:~/pops> ls
a b c *grid startgrid stopgrid
pops@fuzzyVM:~/pops> ls *grid
*grid startgrid stopgrid
pops@fuzzyVM:~/pops> ls \*grid
*grid
pops@fuzzyVM:~/pops>In the above, how would I remove the file *grid, and only that file?
Another question:
I want to find any file its names begin with
"readme*" string using the command find.What command
should I use?What were the results of the two versions you tried? And why? -
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 youSQL> 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
Maybe you are looking for
-
Almost there. Can't driver doesn't recognize variables in another class?
I know this has got to be an easy fix.. but i can't figure it out.so I'll put it all here... it's a program that serves as inventory. add items. sell items. etc... this driver will not compile while the item and inventory classes compile fine. // Pro
-
Linking to webpage with a target=blank
Does anyone know how to do this?
-
Viewing my data in my numbers worksheets
I'm not sure what switch altered my view of the data on my screen. All of my numbers files no longer show the data on the screen. Every single one of my files. NOt sure if one of my kids changed and option somewhere? HELP!
-
Transfer of music to Lumia 920.
Hi everyone . Got myself a brand new 920 last week , and it's mostly great . Mostly . I have a slowly growing collection of Music I've bought from the Nokia Music Store over the last 2 years . But I cannot transfer it to my new phone . 1) Ovi Suit
-
How to reduce sound gain in Captivate 6
Hi All, Have recorded my voice overs over weeks and using a mike and the end product has changed. The last recording session my voice sounds like it has more bass compared to my first recording. Any ideas how to fix this please? Also when limited