Select statement: LIKE IN?
I have this SQL statement that I want to select as follows:
select * from customer where cust_desc like in (select partnumber from orders )
I hit an error doing this. How should I requery my sql statement?
Please note:
I retrieve 10 records when I did this query:
select partnumber from orders
Here is one sample case ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Elapsed: 00:00:00.03
satyaki>
satyaki>
satyaki>select *
2 from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO JOB1 DOB
7521 WARD SALESMAN 7698 22-FEB-81 226.88 500 30 SALESMAN
7654 MARTIN SALESMAN 7698 28-SEP-81 1815 1400 30 SALESMAN
7788 SCOTT ANALYST 7566 19-APR-87 598.95 20 ANALYST
7839 KING PRESIDENT 17-NOV-81 7260 10 PRESIDENT
7844 TURNER SALESMAN 7698 08-SEP-81 2178 0 30 SALESMAN
7876 ADAMS CLERK 7788 23-MAY-87 159.72 20 CLERK
7900 JAMES CLERK 7698 03-DEC-81 1379.4 30 CLERK
7902 FORD ANALYST 7566 03-DEC-81 5270.76 20 ANALYST
7934 MILLER CLERK 7782 23-JAN-82 1887.6 10 CLERK
7566 Smith Manager 7839 23-JAN-82 1848 0 10 Manager 23-JAN-89
7698 Glen Manager 7839 23-JAN-82 1848 0 10 Manager 23-JAN-89
11 rows selected.
Elapsed: 00:00:00.00
satyaki>
satyaki>
satyaki>
satyaki>select * from emp
2 where ename like in ( select ename from emp where sal < 400);
where ename like in ( select ename from emp where sal < 400)
ERROR at line 2:
ORA-00936: missing expression
Elapsed: 00:00:00.00
satyaki>
satyaki>ed
Wrote file afiedt.buf
1 select * from emp
2* where ename like ( select ename from emp where sal < 400)
satyaki>/
where ename like ( select ename from emp where sal < 400)
ERROR at line 2:
ORA-01427: single-row subquery returns more than one row
Elapsed: 00:00:00.00
satyaki>
satyaki>ed
Wrote file afiedt.buf
1 select * from emp
2* where ename in ( select ename from emp where sal < 400)
satyaki>/
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO JOB1 DOB
7521 WARD SALESMAN 7698 22-FEB-81 226.88 500 30 SALESMAN
7876 ADAMS CLERK 7788 23-MAY-87 159.72 20 CLERK
Elapsed: 00:00:00.00
satyaki>So, as you can see you cannot use two simultaneously or like in this way.
Regards.
Satyaki De.
Similar Messages
-
If I want to order by dateAdded to I have to include it in the select statement like
If I do this:
<cfquery name="chart" datasource="#datasource#">
select behaviourID,score, dateAdded2 = convert(varchar,
dateAdded , 101)
from staff_charts_data
where userID =
<cfqueryparam value="#arguments.userID#"
cfsqltype="cf_sql_integer"> AND
NOT score = 5
</cfquery>
If I want to order by dateAdded to I have to include it in
the select statement like so:
<cfquery name="chart" datasource="#datasource#">
select behaviourID,score, dateAdded2 = convert(varchar,
dateAdded , 101),dateAdded
from staff_charts_data
where userID =
<cfqueryparam value="#arguments.userID#"
cfsqltype="cf_sql_integer"> AND
NOT score = 5
</cfquery>you should be able to order by dateAdded without it being in
the select clause. The only time the order by field has to be in
the select clause is when your query has an aggregate and group by
clause, like this:
select field1, field2, max(field3) as youralias
from sometables
where whatever
group by field1, field2
order by ???
You can only order field1, field2, max(field3) or youralias.
You can't order by field4. -
How to use variables in an sql select statement.
Hi, I have seen examples using the update, but nothing using a select statement.
I have four variables I am getting from drop down menus in my JSP I set the user selected items to strings.
How would I create the select statement like this:
.String XName = request.getParameter("UserInputX");
rsInResult = stmtInResult.executeQuery("SELECT ColumxX FROM TableZ WHERE ColumnX = XName")Obviously it tries to read "XName" as a column and of course can't find it, how would I set it up to have it see the Value of XName and not the literal XName.read this:
rsInResult = stmtInResult.executeQuery("SELECT ColumxX FROM TableZ WHERE ColumnX = '"+XName+"')
{code}
better way is PreparedStatement:
{code}
// example code to change password to an user in the USERS table
String newPWD = "my password";
String user = "luxjava";
PreparedStatement prepStat;
String updatePWD = "UPDATE LOGISTIC.USERS "+
"SET logistic.users.password = ? "+
"WHERE logistic.users.username = ?";
prepStat = ql.conDb.prepareStatement(updatePWD);
prepStat.setString(1, newPwd);
prepStat.setString(2, user);
int zeroNotFound = prepStat.executeUpdate();
if (zeroNotFound==0)
ql.conDb.rollback();
prepStat.close();
else
ql.conDb.commit();
prepStat.close();
{code}
... use the SQLException to capture errors -
SELECT statement in FROM clause - syntax help
Hi,
I want to have a SELECT statement in the FROM clause. I get syntax error when doing this and since I am new to ABAP I need som help.
I want to do the following, (and if anyone has any SELECT statement from their own system which you know there is no syntax error in please post it here so I can analyze the syntax):
*I leave the INTO itab clause out, since I only want to demonstrate the functionality
I am trying to get.
<b>SELECT</b> tableOne~someField
<b>FROM</b> tab <b>AS</b> tableOne (<b>SELECT</b> someField
<b>FROM</b> tab
<b>WHERE</b> someFiled > 1) <b>AS</b> tableTwo
<b>WHERE</b> tableOnesomeField > tableTwosomeField
like I said, the problem is that the select statement in the parenthesis in the from clause seems to be incorrect because I get "wrong expression" when trying to compile. Is this because I cannot have a select statement in the from clause or is it because of a minor syntax error, such as I forgot a dot, or some other sign?
thanks and regards
Baransorry i am not enough familiar with sub queries but some error i can see which i will state here.
1> you have to use sub queries i.e. select in ( ) after where clause because here you are fulfilling a where clause by another select statement.
like this
SELECT * FROM SFLIGHT
INTO WA
WHERE SEATSOCC = ( SELECT MAX( SEATSOCC ) FROM SFLIGHT ).
2> you cannot specify field name without into clause either you have to use
select * or select f1 into tab-f1 like this...
but if you are using select * without into you have to define
tables : dbtab.
selec * from dbtab. like that.
regards
shiba dutta -
Ref cursor in select statement
I am not sure this is the right forum, but I got no reply from the OTN Sample.
How do I call a function from a select
statement ?
The function returns a ref cursor.
Here is the function definition:
FUNCTION get_priority_code_list
(p_language_id IN VARCHAR2)
RETURN RefCur
IS
rcur RefCur;
BEGIN
OPEN rcur FOR SELECT
priority_code "priority_code_menu",
priority_code_desc "priority_code_menu_desc"
FROM
prio_desc
WHERE
language_id = p_language_id;
RETURN rcur;
END;
I would like to wrap a SELECT statement
around the function and have the same result
as running the SELECT statement directly.
Of course it does not seem logical here to
use a function, but in fact I want the
function to do more than just a select....
I tried the syntax
SELECT package.function(param) FROM dual;
but that does not work...
or
SELECT * FROM package.function(param);
but that does not work either....
any idea ?
Tks.
nullI have a stored function that returns a ref cursor and I want to use it in select
I tried the following code
for example if the ref cursor returned rows of varchar2
I will define an object
CREATE TYPE myType as OBJECT( doc_type VARCHAR2(256));
created a type as a table of myType
create or replace type myTable as table of myType;
If I write a select statement like below
select * from TABLE(CAST(function_name() AS myTable))
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got CURSER
I get this error
Can anyone give any clue why this does throw an error or if there is a second way to do this, -
Moderator message: Please use meaningful subject in future
Hi,
I've a requirement that I need to get a record from EREV table for a Purchase Requisition no. based on Latest Version No. (REVNO. ) at a single shot.
I hav used the following code but i dint get desired values.
Select EDOKN
FGNAM
FGDAT
REVNO
from EREV into ls_erev
where edokn eq p_edokn and
revno eq (select Max(revno) from erev)).
Any body pl help me.
-Rajiv
Edited by: Vaddepati on Dec 3, 2008 11:01 AM
Edited by: Matt on Dec 3, 2008 10:03 AMHi veddapati,
Your sequence of using the fields in Select statement is wrong...thats why, you are not getting the required output..
You should select revno in the select statement before FGNAM as it is present in the table..
Please modify your select statement like this..... ::
Select EDOKN
REVNO
FGNAM
FGDAT
from EREV into ls_erev
where edokn eq p_edokn and
revno eq (select Max(revno) from erev)).
Hope it will solve your problem
Regards,,
Nikita
Edited by: Nikita Jain on Dec 3, 2008 2:29 PM -
Function output in a select statement
I have written a function(get_cols) which returns the following string (this string is created dynamically from the fuctions depending on the rows of the tables)
the output of the function is;
MAX (CASE WHEN field_code = 'test_pho' THEN VALUE END ) AS test_pho
,MAX (CASE WHEN field_code = 'ESN' THEN VALUE END ) AS ESN
,MAX (CASE WHEN field_code = 'IMSI' THEN VALUE END ) AS IMSI
,MAX (CASE WHEN field_code = 'PHONE_NO' THEN VALUE END ) AS PHONE_NO
What I need to do is to use this as it is in a another select statement like;
(1)
select
empno,
MAX (CASE WHEN field_code = 'test_pho' THEN VALUE END ) AS test_pho
,MAX (CASE WHEN field_code = 'ESN' THEN VALUE END ) AS ESN
,MAX (CASE WHEN field_code = 'IMSI' THEN VALUE END ) AS IMSI
,MAX (CASE WHEN field_code = 'PHONE_NO' THEN VALUE END ) AS PHONE_NO
from my_employee e, my_columns c
where e.emp_no = c.emp_no
and c.emp_no = '100003'
group by empno
function returns the correct output, but when i call the function in the select like below it get it as a whole string and doesn't give the correct output
(2)
select empno, get_cols('100003')
from my_employee e, my_columns c
where e.emp_no = c.emp_no
and c.emp_no = '100003'
how can i get the output of the function to the select as separate line as shown is above(1)
When I get the above output separately and give in the select as above (1) it gives the correct output I want ??
any help pleasejosleen wrote:
Hi BluShadow,
Your solution seem interesting. Can you explain how can this be used to produce the required output ? Do we need to maintain a separate my_columns table ?Not quite sure what you are asking?
As with any query, the output columns have to be defined at design time, you cannot have the number of columns dynamically generated based on the data. So, if you said you wanted to pivot data from rows to columns and the number of possible values in those rows could change, you cannot pivot those to columns unless you are expecting those values or have allowed for maximum number of values.
Basic example... Let say we have the following data:
SQL> select * from dept;
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTONAnd we want to pivot that data to put the departments as columns rather than rows. We can simply do something like:
SQL> ed
Wrote file afiedt.buf
1 select max(decode(deptno,10,dname)) as dname_10
2 ,max(decode(deptno,10,loc)) as loc_10
3 ,max(decode(deptno,20,dname)) as dname_20
4 ,max(decode(deptno,20,loc)) as loc_20
5 ,max(decode(deptno,30,dname)) as dname_30
6 ,max(decode(deptno,30,loc)) as loc_30
7 ,max(decode(deptno,40,dname)) as dname_40
8 ,max(decode(deptno,40,loc)) as loc_40
9* from dept
SQL> /
DNAME_10 LOC_10 DNAME_20 LOC_20 DNAME_30 LOC_30 DNAME_40 LOC_40
ACCOUNTING NEW YORK RESEARCH DALLAS SALES CHICAGO OPERATIONS BOSTON
SQL>However if a further department is added:
SQL> insert into dept values (50, 'IT SUPPORT', 'LONDON');
1 row created.
SQL> select max(decode(deptno,10,dname)) as dname_10
2 ,max(decode(deptno,10,loc)) as loc_10
3 ,max(decode(deptno,20,dname)) as dname_20
4 ,max(decode(deptno,20,loc)) as loc_20
5 ,max(decode(deptno,30,dname)) as dname_30
6 ,max(decode(deptno,30,loc)) as loc_30
7 ,max(decode(deptno,40,dname)) as dname_40
8 ,max(decode(deptno,40,loc)) as loc_40
9 from dept
10 /
DNAME_10 LOC_10 DNAME_20 LOC_20 DNAME_30 LOC_30 DNAME_40 LOC_40
ACCOUNTING NEW YORK RESEARCH DALLAS SALES CHICAGO OPERATIONS BOSTON
SQL>we obviously don't get to see the new data, unless we change our query to add this expected additional column(s) in...
SQL> ed
Wrote file afiedt.buf
1 select max(decode(deptno,10,dname)) as dname_10
2 ,max(decode(deptno,10,loc)) as loc_10
3 ,max(decode(deptno,20,dname)) as dname_20
4 ,max(decode(deptno,20,loc)) as loc_20
5 ,max(decode(deptno,30,dname)) as dname_30
6 ,max(decode(deptno,30,loc)) as loc_30
7 ,max(decode(deptno,40,dname)) as dname_40
8 ,max(decode(deptno,40,loc)) as loc_40
9 ,max(decode(deptno,50,dname)) as dname_50
10 ,max(decode(deptno,50,loc)) as loc_50
11* from dept
SQL> /
DNAME_10 LOC_10 DNAME_20 LOC_20 DNAME_30 LOC_30 DNAME_40 LOC_40 DNAME_50 LOC_50
ACCOUNTING NEW YORK RESEARCH DALLAS SALES CHICAGO OPERATIONS BOSTON IT SUPPORT LONDON
SQL>Now, rather than having a messy SQL statment with lots of max(decode... statements we can provide a pipelined function to return the same thing...
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE TYPE mydepts AS OBJECT
2 ( dname_10 VARCHAR2(14),
3 loc_10 VARCHAR2(13),
4 dname_20 VARCHAR2(14),
5 loc_20 VARCHAR2(13),
6 dname_30 VARCHAR2(14),
7 loc_30 VARCHAR2(13),
8 dname_40 VARCHAR2(14),
9 loc_40 VARCHAR2(13),
10 dname_50 VARCHAR2(14),
11 loc_50 VARCHAR2(13)
12* )
13 /
Type created.
SQL> ed
Wrote file afiedt.buf
1* CREATE OR REPLACE TYPE mydepttable AS TABLE OF mydepts
SQL> /
Type created.
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE FUNCTION alldepts RETURN mydepttable PIPELINED IS
2 v_obj mydepts := mydepts(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
3 CURSOR cur_depts IS
4 select deptno, dname, loc from dept;
5 BEGIN
6 FOR i IN cur_depts
7 LOOP
8 CASE i.deptno
9 WHEN 10 THEN v_obj.dname_10 := i.dname; v_obj.loc_10 := i.loc;
10 WHEN 20 THEN v_obj.dname_20 := i.dname; v_obj.loc_20 := i.loc;
11 WHEN 30 THEN v_obj.dname_30 := i.dname; v_obj.loc_30 := i.loc;
12 WHEN 40 THEN v_obj.dname_40 := i.dname; v_obj.loc_40 := i.loc;
13 WHEN 50 THEN v_obj.dname_50 := i.dname; v_obj.loc_50 := i.loc;
14 ELSE NULL;
15 END CASE;
16 END LOOP;
17 PIPE ROW (v_obj);
18 RETURN;
19* END;
SQL> /
Function created.
SQL> select *
2 from table(alldepts());
DNAME_10 LOC_10 DNAME_20 LOC_20 DNAME_30 LOC_30 DNAME_40 LOC_40 DNAME_50 LOC_50
ACCOUNTING NEW YORK RESEARCH DALLAS SALES CHICAGO OPERATIONS BOSTON IT SUPPORT LONDON
SQL>So, now there is a single function that acts like a table and does the functionality of pivoting the data. What the function actually does to generate the data is entirely up to you whether that is obtaining data from different tables or some PL/SQL code processing to perform some complex algorithmic type thing on the data from a passed in parameter etc. The point of the pipeline function is that it can return multiple columns of data and act as if it is a table that can be queried against, however it still remains that the output columns must be known at design time. This is actually a requirement of the SQL engine, as you cannot make a dynamic function that returns X number of columns based on data.
There is however a technique that can allow you to dynamically generate a number of columns based on data, but it involves getting a little more under the hood of Oracle and interfacing with the ODCI interface, actually using a pipelined funcion technique in conjunction with, in laymans terms, stepping in at the point the query is executing and telling oracle what columns this pipelined function is going to return, but at the same time as defining the returned columns.
An example of doing this is given by AScheffer on this thread: How to pipeline a function with a dynamic number of columns?
... but you really are getting into a complex world if you try and write your queries this way, just to try and make generic queries with dynamic columns.
In essence, the actual business need to actually return a dynamic number of columns is very slim as most applications, whether that is a user facing interface or report generator etc. will be expecting certain data columns to be returned to expected columns or fields within them. If you really want to dynamically pivot data with an unknown number of columns it is usually best to let things like reporting tools deal with this area as that is what they are best at, and don't try and do it within SQL. -
Inner join in select statement
hi,
i am using select statement like
SELECT ekkoebeln ekkobukrs ekkobstyp ekkobsart ekko~ernam
ekkolifnr ekkozterm ekkozbd1t ekkozbd2t ekko~zbd3t
ekkozbd1p ekkozbd2p ekkoekorg ekkoekgrp ekko~waers
ekkowkurs ekkokufix ekkobedat ekkokdate
Begin of Changes, RICEF : 293.
ekkozzhedg ekkozzheda ekkozzpba ekkozzpbubu lfa1~vbund
End of Changes, RICEF . 293.
lfa1land1 lfa1name1
ekpa~lifn2
INTO CORRESPONDING FIELDS OF TABLE iekko
FROM ekko
JOIN lfa1 ON lfa1lifnr = ekkolifnr
LEFT JOIN ekpa ON ekpaebeln = ekkoebeln AND
ekpa~ebelp = '00000' AND
ekpa~parvw = 'RS'
FOR ALL entries IN icooi
WHERE ekko~ebeln = icooi-refbn
AND ekko~zzhedg IN s_zzhedg
AND ekko~zzheda IN s_zzheda.
where in ekko table ,the fields zzhedg and zzheda are appended..but in the debugging mode i am unable to see this 2 field....in the output also....so how should i write my select query?Hi,
Is your select statement returning sy-subrc 0. In debugging mode may be your fields may not be visible in the screen since your internal table has many fields, you have to press >> forward button to check the fields.
Thanks & Regards,
Navneeth K. -
Using a varchar field to select statement
Hi all
I have a single row and single column table
T(command varchar2(4000))
and the row is
sno,name
And I have another table T1(sno number,name varchar)
Now can any body tell how can i use command column in table T to query T1 to get sno,name from T1
I am looking for a select statement like this
select (select command from T) from T1;
but it is printing out the data in T i mean sno, name
This is a copy of thread Selecting output of a select statement
but explained more clearly
Thanks,
ganesh.I don't know why your tables are designed like this but what I think you want to do is join T1 with the data in T.
select sno, name from T1
where sno in (select substr(command,0,instr(command,',')-1) from T)
and name in (select substr(command,instr(command,',')+1) from T);
substr returns a string up to a position
instr returns the position of a string
and the other post you refer to as about as confusing as your one. -
Behaviour of insert ... select statement
Hi,
If we use insert ... select statement like
insert into TableA
Select
from TableB;
and if TableB have 250000 rows then what will be the action for it..
will all 250000 rows fetched to database buffer and if index scans are performed on it and then all rows inserted into TableA
or
it will do it parallel
We are loading large data and facing performance problems for delaying index scans.
Just Curious :)
Rushang.it's not a secret. oracle will perform the select, using indexes if it decides to (depends on source table size, stats, optimizer mode, etc, etc). rows may be pulled back to memory be written to temp space (e.g., if you were returning many, many rows which needed to be grouped). the rows will then be inserted.
so, if you have an index on tableb.col1, then oracle may use the index. or it may do a FTS. either way, it will only select the needed rows to be inserted.
the insert does not prevent the select from working as it would normally. -
One select Statement - Number of hits displaying in ST05
Hi,
I am using single select statement on MARA table along with that using SELECT FOR ALL Entries,
However, I am getting number of hits for each records in ST05 like 2,3,8,2,2 etc.
I need to reduce number of hits by using single query only... please suggest..
Thanks,
SaiHi Siegfried,
just out of curiosity:
> You can get identicals on FAE for at least 3 reasons:
> + duplicates in the driver table, remove as written above
> + duplicate execution of the SELECT
> + fieldlist smaller than the primary key, which is not the case here
What exactly do you mean with the last point?
fieldlist in the select statement like this?
data it like table of t100.
select sprsl arbgb msgnr
from t100 into table it up to 500 rows.
select "sprsl" from t100 into table it
FOR ALL ENTRIES IN it
where sprsl = it-sprsl
and arbgb = it-arbgb
and msgnr = it-msgnr.
or field list in the where clause like this?
data it like table of t100.
select sprsl arbgb msgnr
from t100 into table it up to 50000 rows.
DELETE ADJACENT DUPLICATES FROM it COMPARING sprsl arbgb.
select sprsl from t100 into table it
FOR ALL ENTRIES IN it
where "sprsl" = it-sprsl
and "arbgb" = it-arbgb.
Or something else?
I'm asking because i've never heard or seen this before as a problem reg. identicals
for FAE. Only duplicates in driver tables or multiple executions of the FAE with the same
driver table contents (or parts of it).
If we have a smaller select field list we may read too many records which are thrown away in thd database interface
because of the distinct property of the FAE (distinct sprsl in the 2nd case) but we don't see identical selects in ST05.
How does a FAE that produces identical selects with unique driver table that is executed once look like?
So I'm a little bit confused what you meant here... .
Kind regards,
Hermann -
Concatination of string to select statement
hi all,
pl help me out.
i want to concatenate string to select statement like
create or replace procedure my_proc(p_sal number)
as
v_name varchar2(20);
ssql varchar2(4000);
begin
ssql := ' ';
select ssql || ' '|| select emp_name
into v_name
from employees
where sal =p_sal;
end;
but it is giving error .
pl correct it.
thanks
pavaniPavani,
Still not clear.
"Multiple conditions" sounds like you are trying to build predicates in the where clause, but in your example it looks like you are trying to build a select clause. Also your parameter is p_sal so the where clause "sal = p_sal" is fixed.
The real question is WHY you want to "write multipul conditions"? WHY you want to "store it in a string .and then concatenate the string to next condition so on"?
Regards,
Rob. -
Use of LIKE in where clause of select statement for multiple records
Hi Experts,
I have a account number field which is uploaded from a file. Now this account numbers uploaded does not match fully with sap table account numbers but it contains all of the numbers provided in the file mostly in the upright positions.
For example in file we have account number as 2ARS1 while in sap table the value is 002ARS1.
And i want to fetch data from sap table based on account number uploaded. So, i am trying to use LIKE with for all entries but its not working as mentioned below but LIKE is not working with FOR ALL ENTRIES.
data : begin of t_dda occurs 0,
dda(19) type c,
end of t_dda.
data : begin of t_bukrs occurs 0,
bukrs type t012k-bukrs,
end of t_bukrs.
data : dda type t012k-bankn,
w_dda type t012k-bankn.
CONCATENATE '%'
'2ARS1'
INTO W_DDA.
MOVE W_DDA TO T_DDA-DDA.
APPEND T_DDA.
CLEAR T_DDA.
free t_bukrs.
SELECT BUKRS
FROM T012K
into TABLE t_bukrs
for all entries in t_dda
WHERE BANKN like t_dda-dda.
Can anybody suggest what should i use to get the data for multiple account numbers using one select statement only instead on using SELECT UP TO 1 ROWS in LOOP....ENDLOOP ?
Thanks in advance,
AkashHi,
yes, For All entries won't work for LIKE with '% '.
I think the other alternative is go for Native SQL by writing sub-query
sample code is here:
data: begin of i_mara occurs 0,
matnr like mara-matnr,
matkl like mara-matkl,
end of i_mara.
exec sql.
select matnr, matkl from mara where matnr in (select matnr from marc) and matnr like '%ma' into :i_mara
endexec.
loop at i_mara.
write:/ i_mara-matnr, i_mara-matkl.
endloop.
hope u got it.
regards
Mahesh
Edited by: Mahesh Reddy on Jan 21, 2009 2:32 PM -
A trouble with "LIKE" in a select statement
Hi!
I'm having trouble with "LIKE" in a select statement...
With Access I can make the following and everything works well:
SELECT name, birthday
FROM client
WHERE birthday LIKE '*/02/*';
but if try to do it in my application (it uses Access), it doesn't work - I just can't understand that!!!
In my application the "month" is always the currently month taken from the "System". Look what I'm doing...
String query1 = "SELECT name, birthday " +
"FROM client " +
"WHERE birthday " +
"LIKE '*/" +
pMonth +
"/*' " +
"ORDER BY birthday ASC ";
ResultSet rs = statement1.executeQuery(consulta1);
boolean moreRecords = rs.next();
The variable "moreRecords" is always "false", the query returns nothing although the table "client" has records that attend the query.
Please, anyone can help me?! It's a little bit urgent.
Thanks,
Katia.Hi Katia,
I'll bet the problem lies with the characters you're using to escape the LIKE clause. You're using the ones that Access likes to see, but that's not necessarily what's built into the JDBC-ODBC driver class.
You can find out what the correct escape wildcard characters are from the java.sql.DatabaseMetaData.getSearchStringEscape() method. It'll tell you what to use in the LIKE clause.
I'm not 100% sure about your code. It doesn't use query1 anywhere. I'd do this:
String query = "SELECT name, birthday FROM client WHERE birthday LIKE ? ORDER BY birthday ASC";
PreparedStatement statement = connection.createStatement(query);
String escape = connection.getMetaData().getSearchStringEscape();
String test = escape + '/' + pMonth + '/' + escape;
statement.setString(1, test);
ResultSet rs = statement.executeQuery();
while (rs.hasNext())
// load your data into a data structure to pass back.
rs.close();
statement.close();Let me know if that works. - MOD -
Hi All,
My requirement is not to select the entries for the T024 table where the eknam is either starts with 'NOT VALID' or blank.
For that, I have written the select statement using NOT LIKE,
Will this negation in the select statement cause extra execution tiem?
If so, can you give some hint for alternative statement.
SELECT EKGRP EKNAM FROM T024 INTO TABLE IT_T024
IT_PURC WHERE EKGRP = S_EKGRP AND EKNAM NOT LIKE 'NOT VALID%' AND EKNAM NOT LIKE ' '.
Thanks,
Kal ChandHello,
For the first condition: not starting with 'NOT VALID' , I don't know other way apart from yours: EKNAM NOT LIKE 'NOT VALID%'.
For the second one, not starting with blank: EKNAM NOT LIKE ' '. Does it work? I think it compares if EKNAM is different from blank which can be done using: EKNAM NE ' '.
I hope it will help you.
Maybe you are looking for
-
What are the main uses for a Macbook Pro, and also for a Macbook Air?
I'm curious of whether I should buy a Macbook Pro, or Macbook Air. Before I make my decision I would like to know what are the main purpaces for each Macbook.
-
My EBS is too slow on windows 7
My ebs is too slow when i use it on windows 7 but on older version on windows is working fine. Could somebody know what is the issue or how can we solve it? Thanks
-
Xml to idoc for iincoming invoices
I am quite a newbie. I am interested how to convert xml to idoc without XI (now PI). Probably there is an ABAP possibility(exmple). Is there another way? I have in mind incoming invoices.
-
Installing ip service license on 3560x
Hello i wanted to upgrade my WS-C3560X-24P switch from IP Base to IP Services. I have done this several times in the past with other 3560X-48 Port Switches. This time, everything seemed fine, but my license level doesn't change from ip base to ip ser
-
Possible scenarios with XI, SAP AutoId, RFID combination.
Hi All, Could you please provide the answers to the below questions 1. What all possible scenarios we can do with SAP AutoId using RFID datas? 2. I would like to do scenarios with and without SAP Netweaver XI for the above case. Please provide some s