Where clause in SELECT INTO statement
Hi,
I am using multiple conditions in where clause for my SELECT INTO statement as follows.
SELECT count(DTLA.LOCATION_ID)
INTO LOCATION_ID_count
FROM DOC2_MGR.DOC_TYPE_LOB_ASSOC DTLA
WHERE (DTLA.DOC_TYPE_ID = 'XYZ' AND DTLA.lob_code = 'ABC');
It considers only first condition and returns the result i.e. DTLA.DOC_TYPE_ID = 'XYZ' only.
Does select into statement suppose to consider only one condition in where clause???
Thanks in advance!
--Sandeep
I got it resolved. Here is list of things I noted
1. I was using variable names same as column names. It was mixing up temp variable names with column name on the table, which doesn't make sense as I was referring column names in table.column format
2. I had mixed few datatypes. Input param was suppose to be number where as I was passing it as Text
Thanks anyway!
--Sandeep
Similar Messages
-
WHERE clause in SELECT statement
hi experts..
i want to give 'OR' condition in the 'where' clause of 'SELECT' statement.
is it possible?
for examlpe..
IF EXIDV2 IS NOT INITIAL.
SELECT * FROM YSDT_SHIPLOAD
INTO TABLE IG_SHIPLOAD
WHERE EXIDV2 = EXIDV2 AND
VHILM = PC1 OR PC2 OR PC3.
ENDIF.
i want that VHILM should be one of those three.
how can i do this?
thanks..Hi ,
its possible,
Select * from ysdt_shipload int table ig_shipload where exidv2 = exidv2
AND vhilm = pc1
OR vhilm = pc2
OR vhilm = pc3.
OR
Select * from ysdt_shipload int table ig_shipload where exidv2 = exidv2
AND (vhilm = pc1 or vhilm = pc2 or vhilm = pc3).
Regards
Arani Bhaskar
Edited by: arani bhaskar on Mar 16, 2009 5:14 PM -
Regarding dynamically assigning the where clause to select query
hi,
Please send the code regarding how to dynamically assign the where clause to select query.
thanks in advanceSELECT <fileds>
INTO TABLE itab
FROM dbase
WHERE condition. -
How to modify a Procedure "select into" statement to use a cursor
The below code fails with exception too many rows. How do I modify the Procedure's Select Into statement to use a cursor?
CREATE OR REPLACE PROCEDURE Track_Asset(
business_date IN NUMBER DEFAULT NULL,
missing_table_name OUT VARCHAR2)
IS
ln_business_date NUMBER;
incorrectdateformat EXCEPTION;
BEGIN
IF business_date < 0
THEN
RAISE incorrectdateformat;
ELSE
DECLARE
ln_business_date NUMBER;
BEGIN
SELECT MAX(business_date)
INTO ln_business_date
FROM sproof ;
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line('NO MATCH FOUND');
WHEN OTHERS THEN
dbms_output.put_line('ORACLE ERROR :' || SQLERRM);
END;
DECLARE
missedfeedfnd EXCEPTION;
BEGIN
SELECT 'Missing Value : ' || table_name
INTO missing_table_name
FROM (
SELECT UPPER(table_name) table_name
FROM filespec
WHERE data_table_name IN ('TABLE1','TABLE2','TABLE3')
MINUS (
SELECT DISTINCT UPPER(first_table_name)
FROM dpca
WHERE business_date = ln_business_date
AND first_table_name IN ('TABLE1','TABLE2','TABLE3')
GROUP BY UPPER(first_table_name) UNION
SELECT UPPER(first_table_name)
FROM dpca
WHERE business_dt_num = TO_NUMBER( SUBSTR('201111', 1, 6) || '01' )
AND first_table_name = 'TABLE4'
GROUP BY UPPER(first_table_name) ));
IF missing_table_name IS NOT NULL THEN
dbms_output.put_line('Missing Value : '|| missing_table_name);
RAISE missedfeedfnd;
ELSE
NULL;
END IF;
EXCEPTION
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE (' SELECT INTO statement retrieved multiple rows');
WHEN missedfeedfnd THEN
raise_application_error ( - 20003, 'Missed Feed');
END;
END IF;
EXCEPTION
WHEN incorrectdatevalue
THEN
raise_application_error ( - 20001, 'Incorrect/Bad Date Entered');
END;ok try this - OUT param will be populated with comma separated list of table names:
PROCEDURE Track_Asset(
business_date IN NUMBER DEFAULT NULL,
missing_table_name OUT VARCHAR2)
cursor c_table_names is
select datatablename
from ( select upper(datatablename) datatablename
from filespec
where data_table_name in ('TABLE1','TABLE2','TABLE3' )
MINUS
( select upper(first_table_name)
from dpca
where business_dt_num = [-- this date is retrieved by getting the MAX(business_date) from sproof table]
and fus_data_table_name in ('TABLE1','TABLE2','TABLE3'
group by
upper(first_table_name)
UNION
select upper(first_table_name)
from dpca
where business_dt_num = to_number( substr('201111',1,6) || '01' )
and first_table_name = 'TABLE4'
group by
upper(first_table_name)
begin
for rec in c_table_names
loop
missing_table_name := missing_table_name || rec.datatablename ||',';
end loop;
missing_table_name := rtim(missing_table_name , ',');
end ;HTH
Edited by: user130038 on Dec 28, 2011 8:46 AM -
Can i include variable in select into statement?
Hi all,
Is it possible to include a variable name in the "select into" statement ? For ex:
"Select empname into variable_Name from employee" In this case variable_Name is the variable.Will this statement work by assigning empname to variable_Name if there is only one record in the employee table?please reply....c ya.Surely you have to? You can hardly SELECT INTO a constant. Perhaps I'm missing something,
-
Using SELECT INTO statement to transfer data from one DB to another?
Hello,
I need to move data from an SAP table to another downstream SQL server box without flat file in between. I have set up the DBCON interface, so that my ABAP code on SAP can connect to the remote SQL Server, then I can run INSERT command as Native SQL inside the ABAP.
However, INSERT has performance problem. The best performer as I can find is SELECT INTO statement. But then I am stuck at how to use SELECT INTO to query my local SAP table and send (via INTO) to remote database. I am not even sure whether I should use Open SQL or Native SQL.
Any suggestion? BTW, I understand the limitation of Native SQL, but we are OK to use it.
Thanks!It appears that this is some kind of migration project due to the scope of the data contained in the single file? If so whatever you do is like ly to be trow away once the migration of data is completed.
You have a couple of options:
1) Get the data extracted from HFM in multiple files instead of one bulk file, broken down by scanario,year & period
2) Take the single data dump file produced by FDM and manipulate it yourself to get the data in a more usuable format for processing through FDM.
Option 2 could be achieved via any ETL tool or a custom file parsing script. What may be more attractive to you and allow you to fully leverage your investment in FDM is that you could use the PULL adapter that ships as part of the FDM adapter suite to perform this transformation exercise. The PULL adapter takes a flat file input and allows you to use all the in built functionality of FDM to transform it and output a modified flat file (or series of flat files). You could use it to produce multioload files or a series of files broken down by scenario,year,period.
Whatever you do I would suggest that break the single data file down into smaller chunks as this will help with the iterative debugging process you will inevitably have to undetake whislt migrating the data to the new application. -
How build where clause in select statement in FM for Virtual provider
Hi
I looking for example of FM for Virtual provider where I find code how assign to select statement "where" clause value from query variable.
In following code how build t_r_custtype range and how assign value to it.
CODE********************************
TYPE-POOLS: abap.
initialize
CLEAR: e_t_data, e_t_msg.
this is specific to infoprovider VIRTPROV
CHECK i_infoprov = 'VIRTPROV'.
FIELD-SYMBOLS: <l_s_sbook> TYPE sbook,
<l_s_data> TYPE ANY.
DATA: l_t_component TYPE abap_compdescr_tab,
l_t_sbook TYPE TABLE OF sbook.
initialize
CLEAR e_t_data.
Data selection / only Business Customer
SELECT * FROM sbook
INTO CORRESPONDING FIELDS OF TABLE l_t_sbook
WHERE custtype in t_r_custtype.
ENDCODE********************************
Thanks a lot
AdamHello,
Would you like fill the ranges in Customer exit for BEx..?
If Yes. please refer the attachment for the whole code...
"Sample code in Customer Exit in BEx"
IF i_step = 2.
CASE i_vnam.
WHEN 'ZDAY_CX'.
LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZDAY_IN'.
CLEAR: l_s_range.
ZT_DT1 = loc_var_range-low.
ZT_DT2 = loc_var_range-HIGH.
CALL FUNCTION 'DATE_CREATE'
EXPORTING
ANZAHL_JAHRE = 0
ANZAHL_KALTAGE = 0
ANZAHL_MONATE = '-1'
ANZAHL_TAGE = 0
DATUM_EIN = ZT_DT1
DATUM_EIN_ULT = ' '
ULTIMO_SETZEN = ' '
IMPORTING
DATUM_AUS = ZFIDAY .
E_TT =
E_ULTKZ =
CALL FUNCTION 'DATE_CREATE'
EXPORTING
ANZAHL_JAHRE = 0
ANZAHL_KALTAGE = 0
ANZAHL_MONATE = '-1'
ANZAHL_TAGE = 0
DATUM_EIN = ZT_DT2
DATUM_EIN_ULT = ' '
ULTIMO_SETZEN = ' '
IMPORTING
DATUM_AUS = ZLSDAY.
E_TT =
E_ULTKZ =
l_s_range-low = ZFIDAY .
l_s_range-high = ZLSDAY .
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.
ENDLOOP.
*****************************************End*************************************
**To get the From date (For Text Variable) as per the user input date interval range**
WHEN 'ZR_S'.
LOOP AT i_t_var_range INTO loc_var_range WHERE vnam = 'ZDAY_IN'.
CLEAR: l_s_range.
ZT_DT1 = loc_var_range-low.
ZT_DT2 = loc_var_range-HIGH.
CALL FUNCTION 'DATE_CREATE'
EXPORTING
ANZAHL_JAHRE = 0
ANZAHL_KALTAGE = 0
ANZAHL_MONATE = 0
ANZAHL_TAGE = 0
DATUM_EIN = ZT_DT1
DATUM_EIN_ULT = ' '
ULTIMO_SETZEN = ' '
IMPORTING
DATUM_AUS = ZFIDAY .
E_TT =
E_ULTKZ =
l_s_range-low0(2) = ZFIDAY6(2).
l_s_range-low+2(1) = '.'.
l_s_range-low3(2) = ZFIDAY4(2).
l_s_range-low+5(1) ='.'.
l_s_range-low6(4) = ZFIDAY0(4).
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
APPEND l_s_range TO e_t_range.
ENDLOOP.
*****************************************End*************************************
Please let me know if any clarification required..
Rinku.. -
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 -
Dynamic WHERE clause in SELECT statement
Hi,
I need to extract (SELECT) all the products in different salesorganizations. Since a product can be available in more than 1 salesorg I have created several properties in the PRODUCT dimension - 1 for each salesorganization (naming: Sxxxx where xxxx is the salesorganization number).
Since I need to prefix the salesorganization property with an "S" I have created a property on the SALESORG dimension called SALESORG.
Therefore I need to create a dynamic WHERE clause in the SELECT statement. Currently my script is:
*SELECT(%SORG%, "[SALESORG]",SALESORG, [ID]=%SALESORG_SET%)
*SELECT(%PROD%, "[ID]",PRODUCT, [%SORG%]="X")
My first SELECT find the Sxxx (equal to the property I need in the PRODUCT dimension). My second SELECT uses the variable in the first SELCT statement to use the correct property for the WHERE clause.
Unfortunately the code is not validated - any suggestions?
/LarsHi Lars,
If you run it from a DM package without validating it, does it still work? I would bet it does.
If this is the case I would open a message with SAP (it would be an enhancement request). Until they fix the validation code, you would just have to live with the script not validating.
Cheers,
Ethan -
Dynamic where clause in select query
Hi
I'm trying for a dynamic query and in the dynamic where clause i'm checking a field for constant.....for instance if i wanna to use WERKS EQ '0478' how to declare it in dync where clause. i tried for the following:
SELECT (TAB_FIELD) INTO TABLE DITAB UP TO 10 ROWS FROM (TAB_NAME) WHERE (CONDI).
heree CONDI = 'werks eq 0287' . in this case the query fails as the werks shud be equal to '0287' and not just 0287. How to handle this? i tried for the following
CONDI = 'werks eq " '0287' " ' but no luck as it is not a valid stmt as i knew.hi prabhu,
this is how u select dynamically...
DATA: COND(72) TYPE C,
ITAB LIKE TABLE OF COND.
PARAMETERS: CITY1(10) TYPE C, CITY2(10) TYPE C.
DATA WA TYPE SPFLI-CITYFROM.
CONCATENATE 'CITYFROM = ''' CITY1 '''' INTO COND.
APPEND COND TO ITAB.
CONCATENATE 'OR CITYFROM = ''' CITY2 '''' INTO COND.
APPEND COND TO ITAB.
CONCATENATE 'OR CITYFROM = ''' 'BERLIN' '''' INTO COND.
APPEND COND TO ITAB.
LOOP AT ITAB INTO COND.
WRITE COND.
ENDLOOP.
SKIP.
SELECT CITYFROM
INTO WA
FROM SPFLI
WHERE (ITAB).
WRITE / WA.
ENDSELECT.
regards,
sohi -
Dynamic Where Clause in select using member attribute of class
Hello,
can anybody provide me some tips how to solve this problem:
SELECT (lv_sql_select) INTO CORRESPONDING FIELDS OF TABLE lt_cntrl2
FROM (lv_db_name)
FOR ALL ENTRIES IN mt_guids
WHERE (lv_sql_where).
works perfectly fine if I use a local table variable or a member of my class. But if I build my where clause using a member attribute of my class which comes from the interace- exactly the same type and data as before I get a dump.
SELECT (lv_sql_select) INTO CORRESPONDING FIELDS OF TABLE lt_xyz
FROM (lv_db_name)
FOR ALL ENTRIES IN if_abc~mt_guids
my where clause "guid = if_abc~mt_guids-guid.
Dump:
Error analysis
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SEMANTICS', was
not caught in
procedure "....GET_DATA" "(METHOD)", nor was it propagated
by a RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
Das laufende ABAP-Programm wollte eine Open SQL-Anweisung ausführen,
die eine dynamische Angabe enthält. Der Parser lieferte jedoch den
Fehler: "Wrong table name or table alias name table alias name
table alias name "....". table alias name
"...". table alias name "...". t"Hi Marco Freischlag,
As per my understanding , if we give for all entries we want to use internal table , For where conditions you want to pass variable , not internal table one filed,because it will not have header line...
so code like this...
SELECT (lv_sql_select) INTO CORRESPONDING FIELDS OF TABLE lt_xyz
FROM (lv_db_name)
FOR ALL ENTRIES IN if_abc~mt_guids
where guid = if_abc~mt_guids-guid. " Here pass some variable or work area in it and test.
Thanks,
Vijay SR -
Beginner: Getting syntax error on WHERE clause in SELECT
I'm very new to php and mySQL. Am using DW master/detail to generate to basic code I need. One thing I need to do is modify a select statement in the master to include a WHERE clause to limit the selection to a particular value in one field.
I'm getting a syntax error with the WHERE clause I'm adding to the map select statement.
This is the portion of the error message showing the error location:
'WHERE Group='Community' LIMIT 0, 10'
The php that generated the select is:
$query_maps = "SELECT * FROM tblmaps ORDER BY tblmaps.DispSeq";
$query_limit_maps = sprintf("%s WHERE Group='%s' LIMIT %d, %d", $query_maps, $selectGroup, $startRow_maps, $maxRows_maps);
This approach to creating the select statement is from the code generated for the master page. It adds the LIMIT clause. All I did was add the "WHERE Group='%s' and the $selectGroup variable which comes from earlier code. You can see that the $selectGroup variable is equal to the "Community: group.
I've scanned the web to see what syntax error I might be making but haven't found anything that explains it.
The full resolved select statement is:
SELECT * FROM tblmaps ORDER BY tblmaps.DispSeq WHERE Group='Community' LIMIT 0,10
What am I not seeing?
TomThanks. Make sense but changing that didn't help.
Here's the error message I'm getting:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Group='Community' ORDER BY tblmaps.DispSeq LIMIT 0, 10' at line 1
The full select (from a debugging ECHO I inserted) is:
SELECT * FROM tblmaps WHERE Group='Community' ORDER BY tblmaps.DispSeq LIMIT 0, 10
Note that when I take the WHERE clause out, there is no syntax error. -
Problems with WHERE CLAUSE in selects executed by BAPIs
Dear Experts,
I'm trying to make a SAP Java Connector. My problem is that, when they are called by Java, BAPI functions don't run in the same manner as in SAP testing mode .
I tested two BAPI functions called through my connector and I saw with the debbuger that BAPI functions don't execute the select and loop at with a WHERE clause when they are called by Java, therefore they throw errors. But in the SAP testing mode functions work just fine.
I'm new to SAP and I don't know why this happens. Would you like to explain to me how to fix this problem?
Thank you very much.
Kind regards,
Maricica979380 wrote:
Yeah,i m sorry.I m a forum newbie.All right,we ve been given an oracle account for the purpose of this project,an we have connect to the oracle database either via linux terminal with sqlplus,or via oracle client and plsql.So i have to create some tables,then fill these tables with tuples(we ve been given fixed .sql files to do that),and we re suggested to do that from the linux terminal.I did that successfully.Then we have to run some queries either in terminal or plsql.I chose plsql.I connect,i can see the tables that i have created but when i run(in both sql and terminal window) for example the query "select * from table_1",i take 0 rows as a result.I tested to run the query from terminal(with sqlplus) to see if the tables are really empty,but i recieve the results as i should.
I am sorry for my chaotic writing but i cant even explain the problem to myself better and i m not a native.
(im using oracle version 11.2.0.1, this is the first time i m using oracle databases and i m a rookie in databases in general)
Edited by: 979380 on 1 Ιαν 2013 10:33 πμ
[oracle@localhost ~]$ sqlplus user1/user1
SQL*Plus: Release 11.2.0.2.0 Production on Tue Jan 1 11:19:29 2013
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> create table table_1 (id number);
Table created.
SQL> select * from table_1;
no rows selected
SQL> insert into table_1 values(1);
1 row created.
SQL> select * from table_1;
ID
1
SQL> in order to SELECT any rows from any table, first you must INSERT data into the table!
is COPY & PASTE broken for you? -
How to create VO with multiple dynamic where clauses on select with UNION?
I am trying to implement the View Object for the UNION query that looks like this:
select a,b,c...
from t1,t2,...
where dynamic_where_clause1
union all
select a,b,c,...
from t11,t12, ...
where dynamic_where_clause2
There are up to 60 input parameters that are used to generate dynamic where clauses. They are actually created by calling PL SQL function.
So far, I was not able to assign both where clauses to the view object. Is there a workable solution for this problem, besides resorting to programmatic View Object?
I understand that recommended way with UNIONs is to wrap both queries into a parent select:
select * from (
select a,b,c...
from t1,t2,...
where ... -- table relationship joints
union all
select a,b,c,...
from t11,t12, ...
where ... -- table relationship joints
) QRSLT
where dynamic_where_clause
Unfortunately this approach doesn't work here, since individual selects are producing unmanageable amount of data and resulting query takes forever to complete.I afraid I would not have any real benefits from using VO if I replace the entire query with every request. Actually, the performance may suffer.
I solved the problem by creating a POJO Data Control and invoking the custom select query from java. Not sure if it is the best approach to the problem, but implementation time is limited and it works.
Actually, this is not the first time I see the need to implement VO with complicated SQL like select with unions and dynamic pieces. It would be nice to find a solution and not resort to workarounds.
Edited by: viksicom on Aug 2, 2012 8:48 AM -
Hello
I have entered the following statement into the SQL Command Processor in HTML Db:
select * into DEMO_CUSTOMERS_COPY from DEMO_CUSTOMERS
I get the following error:
ORA-00905: missing keyword
Can anyone tell me why I'm getting this error? I think the syntax of the statement looks ok to me but I may be wrong
Thanks,
SimonHi Simon,
No problem...glad to help.
Your original command (with a little modification) is the sort of thing you usually see in PL/SQL where you want to extract a column (or record) from a table, for example
SQL> set serveroutput on;
SQL> declare
v_value dual.dummy%TYPE;
begin
select
dummy
into
v_value
from dual;
dbms_output.put_line('The value is: ' || v_value);
end;
The value is: XNote that "select..into" requires only one row to be returned, so if multiple rows are returned then you'll get a TOO_MANY_ROWS exception.
Hope this helps.
Maybe you are looking for
-
How to submit a cuncurrent program from UNIX?
How to submit a concurrent program from UNIX.Plz reply immediatly
-
Error message when trying to open LR5
LR5 on my Win 7 64 bit PC crashed and I had to force it to close and reboot my PC. Now when I try to open Lightroom I get the error message "Lightroom catalog cannot be opened as it being being used by another application. Quit the other copy of Ligh
-
Well, my friend and I just received this 1st generation iPod Touch from a man at our church. He said we could sell it. However, it has some problems. For example, when I leave it alone, it cuts off completely, Then, I have to hold the home and power
-
How to fix ipad 2 when blue screen appears after dropping it sideways?
I dropped my ipad 2 from my kitchen table to the seat of the wooden chair at the table. The ipad landed on it's side and now the screen is dark blue and I cannot see anything on it. I can hear the camera take pictures though. I tried a reset and even
-
Duplicate "Home" calendars on iCloud, Mac, and iOS
I have 18 (and counting) "Home" calendars showing up in Calendar on my Macs (OS X 10.9.2), iOS (iOS 7.2), and on the iCloud.com site. http://support.apple.com/kb/TS3999 says If your calendars are duplicated on iCloud.com, contact iCloud Support. whic