Error with select statement
Hi All,
I am getting the error 'Comma without preceding colon (after SELECT ?).' with the following select statement. Can someone help me with the error.
select single actdate_from actdate_to
into ( lv_actdate_from, lv_actdate_to )
from zsdcoop
where kunnr = wa-kunnr and pfnum = wa-pfnum.
if ( lv_actdate_from NE wa-actdate_from ) or ( lv_actdate_to NE wa-actdate_to ).
wa-block = 'X'.
Endif.
Thanks,
Veni.
Typically, on statements like this, you want to use AND instead of OR. Google "truth tables" for a detailed explanation of why.
if ( lv_actdate_from NE wa-actdate_from ) or ( lv_actdate_to NE wa-actdate_to ).
wa-block = 'X'.
Should probably be:
if ( lv_actdate_from NE wa-actdate_from ) AND ( lv_actdate_to NE wa-actdate_to ).
wa-block = 'X'.
Similar Messages
-
Problem with Select Statements
Hi All,
I have a performance problem for my report because of the following statements.
How can i modify the select statements for improving the performance of the report.
DATA : shkzg1h LIKE bsad-shkzg,
shkzg1s LIKE bsad-shkzg,
shkzg2h LIKE bsad-shkzg,
shkzg2s LIKE bsad-shkzg,
shkzg1hu LIKE bsad-shkzg,
shkzg1su LIKE bsad-shkzg,
shkzg2hu LIKE bsad-shkzg,
shkzg2su LIKE bsad-shkzg,
kopbal1s LIKE bsad-dmbtr,
kopbal2s LIKE bsad-dmbtr,
kopbal1h LIKE bsad-dmbtr,
kopbal2h LIKE bsad-dmbtr,
kopbal1su LIKE bsad-dmbtr,
kopbal2su LIKE bsad-dmbtr,
kopbal1hu LIKE bsad-dmbtr,
kopbal2hu LIKE bsad-dmbtr.
*These statements are in LOOP.
SELECT shkzg SUM( dmbtr )
INTO (shkzg1s , kopbal1s)
FROM bsid
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'S'
AND umskz EQ ''
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg1su , kopbal1su)
FROM bsid
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'S'
AND umskz IN zspgl
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg1h , kopbal1h)
FROM bsid
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'H'
AND umskz EQ ''
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg1hu , kopbal1hu)
FROM bsid
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'H'
AND umskz IN zspgl
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg2s , kopbal2s)
FROM bsad
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'S'
AND umskz EQ ''
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg2su , kopbal2su)
FROM bsad
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'S'
AND umskz IN zspgl
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg2h , kopbal2h)
FROM bsad
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'H'
AND umskz EQ ''
GROUP BY shkzg.
ENDSELECT.
SELECT shkzg SUM( dmbtr )
INTO (shkzg2hu , kopbal2hu)
FROM bsad
WHERE bukrs = ibukrs
AND kunnr = ktab-kunnr
AND budat < idate-low
AND shkzg = 'H'
AND umskz IN zspgl
GROUP BY shkzg.
ENDSELECT.>
Siegfried Boes wrote:
> Please stop writing answers if you understrand nothing about database SELECTS!
> All above recommendations are pure nonsense!
>
> As always with such questions, you must do an analysis before you ask! The coding itself is perfectly o.k., a SELECT with an aggregate and a GROUP BY can not be changed into a SELECT SINGLE or whatever.
>
> But your SELECTS mustr be supported by indexes!
>
> Please run SQL Trace, and tell us the results:
>
> I see 8 statements, what is the duration and the number of records coming back for each statement?
> Maybe only one statement is slow.
>
> See
> SQL trace:
> /people/siegfried.boes/blog/2007/09/05/the-sql-trace-st05-150-quick-and-easy
>
>
> Siegfried
Nice point there Siegfried. Instead of giving constructive suggestion, people here give a very bad suggestion on using SELECT SINGLE combined with SUM and GROUP BY.
I hope the person already look at your reply before he try using select single and wondering why he has error.
Anyway, the most important thing is how many loop expected for those select statements?
If you have like thousands of loop, you can expect a poor performance.
So, you should also look at how many times the select statement is called and not only performance for each select statement when you're doing SQL trace.
Regards,
Abraham -
Runtime error at select statement in RFC_READ TABLE FM
Dear All,
I have copied the standard FM RFC_READ_TABLE to incorporate the customer needs. Below is the select query which I have written in this FM.
SELECT (po_search_text-column_text) INTO <wa> FROM ekko
INNER JOIN ekpo ON ekko~ebeln = ekpo~ebeln
INNER JOIN eket ON ekpo~ebeln = eket~ebeln AND ekpo~ebelp = eket~ebelp
INNER JOIN lfa1 ON ekko~lifnr = lfa1~lifnr
INNER JOIN lfm1 ON ekko~lifnr = lfm1~lifnr AND ekko~ekorg = lfm1~ekorg
INNER JOIN lfb1 ON ekko~lifnr = lfb1~lifnr AND ekko~bukrs = lfb1~bukrs
INNER JOIN t024 ON ekko~ekgrp = t024~ekgrp
INNER JOIN zatscsng_status ON eket~ebeln = zatscsng_status~po_number
AND eket~ebelp = zatscsng_status~po_line
AND eket~etenr = zatscsng_status~po_sched_line
INNER JOIN adrc ON zatscsng_status~delivery_addr = adrc~addrnumber
WHERE (po_search_text-cond_text)
ORDER BY (po_search_text-sort_text).
Here, posearch_text-column_text_ will have the fields to be selected at runtime and posearch_text-cond_text_ is the where condition. It is running fine in this case.
But when I try to select Item Category ( EKPO-PSTYP), if data is present for this category, it is returning the values but if data is not there for the particular item category in the where clause, it is giving a RUNTIME ERROR at the select statement.
Here is the 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 "ZATSCSNG_RFC_READ_TABLE" "(FUNCTION)", 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:
The current ABAP program has tried to execute an Open SQL statement
which contains a WHERE, ON or HAVING condition with a dynamic part.
The part of the WHERE, ON or HAVING condition specified at runtime in
a field or an internal table, contains the invalid value "<L_LINE>-PSTYP".
Edited by: Rob Burbank on Mar 17, 2010 5:09 PMNow that's what I call a join statement...
You probably have a bug in how you build po_search_text-cond_text, the content must be a syntactically correct where clause. It seems that in your example there is just "<L_LINE>-PSTYP" without a condition, so try omitting it altogether.
Debug the content of po_search_text-cond_text before it hits the select statement.
Thomas -
Error in select statement in CMOD
Hi Friends
I am enhancing a data source with some fields and in the CMOD i am writing the code.
My delcaration is as follows
begin of ty_dfkkzp,
SELW2 type dfkkzp-SELW2,
BLART type dfkkzp-BLART ,
BUDAT type dfkkzp-BUDAT ,
BLDAT type dfkkzp-BLDAT ,
TBETR type dfkkzp-TBETR ,
ZZRECEIPT type dfkkzp-ZZRECEIPT ,
ZZPAYCAT type dfkkzp-ZZPAYCAT ,
ZZPAYSRC type dfkkzp-ZZPAYSRC ,
ZZPAYTYPE type dfkkzp-ZZPAYTYPE ,
ZZTENDER type dfkkzp-ZZTENDER ,
end of ty_dfkkzp.
Following is my SELECT statement.
select
SELW2
BLART
BUDAT
BLDAT
TBETR
ZZRECEIPT
ZZPAYCAT
ZZPAYSRC
ZZPAYTYPE
ZZTENDER
into corresponding fields of table lt_dfkkzp
from dfkkzp
for all entries in it_data
where SELW2 = it_data-VTREF.
I am getting an error in the where clause. This is becuase VTERF ( Contract) is of type CHAR and length 20, where as SELW2 is of type CHAR but Length 35. I know the length and type should be the same. But this table DFKKZP strangely has SELW2(Contract) has length 35.
Can someone please suggest me how to handle this inorder for me to get this correct?.
Thanks in adv.
Regards
BNHi,
try this and let me know if it works.
Declare another internal table and work area like it_data1 type it_data as shown below.
Begin of it_data1_wa,
......... type........,
......... type .......,
SELW2 type dfkkzp-SELW2,
end if it_data_wa1.
data: it_data1 like standard table of it_data_wa.
data: it_data_wa type it_data
include all the fields inside the table.
loop at it_data into it_data_wa.
move corresponding lt_data_wa to it_data1_wa.
it_data1_wa-SELW2 = it_data_wa-VTREF.
append it_data1_wa to it_data1.
end loop.
now write the same select statement for all entries in it_data1 instead of it_data.
Regards,
Anusha -
Sql Error in Select statement when doing subquery
Hi,
I am trying to see what the error is in the subquery part of the select statement.
Subquery should be fetching the safety_stock_quantity based on the MAX(effectivity_date).
Any suggestions?
SELECT kbn.last_update_date,itm.segment1,itm.description,kbn.kanban_card_number,kbn.kanban_size,
(SELECT msc.safety_stock_quantity
FROM mtl_safety_stocks msc
WHERE msc.effectivity_date = (select MAX(msc2.effectivity_date)
from mtl_safety_stocks msc2
where msc2.inventory_item_id = itm.inventory_item_id
and msc2.organization_id = itm.organization_id)
AND msc.inventory_item_id = itm.inventory_item_id
AND msc.organization_id = itm.organization_id
FROM mtl_system_items_b itm
,mtl_onhand_quantities_detail moqd
,mtl_safety_stocks msc
,mtl_kanban_card_activity kbn
WHERE itm.inventory_item_id = kbn.inventory_item_id
AND itm.organization_id = kbn.organization_id
AND itm.inventory_item_id = moqd.inventory_item_id
AND itm.organization_id = moqd.organization_id
AND moqd.subinventory_code = kbn.source_subinventory
AND kbn.card_status = 1
AND kbn.supply_status = 5
AND msc.inventory_item_id = itm.inventory_item_id
AND msc.organization_id = itm.organization_id
GROUP BY
kbn.last_update_date,itm.segment1,itm.description,kbn.kanban_card_number,kbn.kanban_size;
Thanks
PravnHi, Pravn,
Remember the ABC's of GROUP BY:
When you use a GROUP BY clause and/or an aggregate fucntion, then every item in the SELECT clause must be:
(A) an <b>A</b>ggregate function,
(B) one of the "group <b>B</b>y" expressions,
(C) a <b>C</b>onstant, or
(D) something that <b>D</b>epends entirely on the above. (For example, if you "GROUP BY TRUNC(dt)", you can "SELECT TO_CHAR (TRUNC(dt), 'Mon-DD')").
There's a GROUP BY clause in your main query, so every item in the main SELECT clause must be one of the above. The last item, the unnamed scalar sub-query, is none of the above.
How can you fix this problem? That depends on your data, the results you want, and perhaps on your Oracle version. If you'd like help, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved. Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
Always say which version of Oracle you're using.
You may have noticed that this site normally doesn't display multiple spaces in a row.
Whenever you post formatted text (including, but limited to, actual code) on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing. -
Problem with SELECT statement. What is wrong with it?
Why is this query....
<cfquery datasource="manna_premier" name="kit_report">
SELECT Orders.ID,
SaleDate,
Orders.UserID,
Distributor,
DealerID,
Variable,
TerritoryManager,
US_Dealers.ID,
DealerName,
DealerAddress,
DealerCity,
DealerState,
DealerZIPCode,
(SELECT SUM(Quantity)
FROM ProductOrders PO
WHERE PO.OrderID = Orders.ID) as totalProducts,
FROM Orders, US_Dealers
WHERE US_Dealers.ID = DealerID AND SaleDate BETWEEN #CreateODBCDate(FORM.Start)# AND #CreateODBCDate(FORM.End)# AND Variable = '#Variable#'
</cfquery>
giving me this error message...
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
The error occurred in D:\Inetpub\mannapremier\kit_report2.cfm: line 20
18 : WHERE PO.OrderID = Orders.ID) as totalProducts,
19 : FROM Orders, US_Dealers
20 : WHERE US_Dealers.ID = DealerID AND SaleDate BETWEEN #CreateODBCDate(FORM.Start)# AND #CreateODBCDate(FORM.End)# AND Variable = '#Variable#'
21 : </cfquery>
22 :
SQLSTATE
42000
SQL
SELECT Orders.ID, SaleDate, Orders.UserID, Distributor, DealerID, Variable, TerritoryManager, US_Dealers.ID, DealerName, DealerAddress, DealerCity, DealerState, DealerZIPCode, (SELECT SUM(Quantity) FROM ProductOrders PO WHERE PO.OrderID = Orders.ID) as totalProducts, FROM Orders, US_Dealers WHERE US_Dealers.ID = DealerID AND SaleDate BETWEEN {d '2009-10-01'} AND {d '2009-10-31'} AND Variable = 'Chick Days pre-book'
VENDORERRORCODE
-3504
DATASOURCE
manna_premier
Resources:
I copied it from a different template where it works without error...
<cfquery name="qZVPData" datasource="manna_premier">
SELECT UserID,
TMName,
UserZone,
(SELECT COUNT(*)
FROM Sales_Calls
WHERE Sales_Calls.UserID = u.UserID) as totalCalls,
(SELECT COUNT(*)
FROM Orders
WHERE Orders.UserID = u.UserID) as totalOrders,
(SELECT SUM(Quantity)
FROM ProductOrders PO
WHERE PO.UserID = u.UserID AND PO.NewExisting = 1) as newItems,
(SELECT SUM(NewExisting)
FROM ProductOrders PO_
WHERE PO_.UserID = u.UserID) as totalNew,
SUM(totalOrders)/(totalCalls) AS closePerc
FROM Users u
WHERE UserZone = 'Central'
GROUP BY UserZone, UserID, TMName
</cfquery>
What is the problem?It's hard to say: what's your request timeout set to?
700-odd records is not much of a fetch for a decent DB, and I would not expect that to case the problem. But then you're using Access which doesn't fit the description of "decent DB" (or "fit for purpose" or "intended for purpose"), so I guess all bets are off one that one. If this query is slow when ONE request is asking for it, what is going to happen when it goes live and multiple requests are asking for it, along with all the other queries your site will want to run? Access is not designed for this. It will really struggle, and cause your site to run like a dog. One that died serveral weeks ago.
What else is on the template? I presume you're doing something with the query once you fetch it, so could it be that code that's running slowly? Have you taken any steps to isolate which part of the code is taking so long?
How does the query perform if you take the subquery out of the select line? Is there any other way of getting that data? What subquery will be running once for every row of the result set... not very nice.
Adam -
Performance Tuning 'Runtime Error' on Select statement
Hi Experts,
Good Day!
I would like to ask some help regarding a custom program that will encounter 'Runtime Error' on the below codes on how to perform performance tunning especially number 1.
1.
SELECT A~VBELN A~ERDAT A~AUART A~VKORG A~VTWEG A~SPART A~VDATU
A~KUNNR B~POSNR B~MATNR B~ARKTX B~ABGRU B~KWMENG B~VRKME
B~WERKS B~VSTEL B~ROUTE
FROM VBAK AS A INNER JOIN VBAP AS B ON A~VBELN EQ B~VBELN
INNER JOIN VBEP AS C ON A~VBELN EQ C~VBELN
AND B~POSNR EQ C~POSNR
INTO CORRESPONDING FIELDS OF TABLE I_DATA_TAB
WHERE A~VBELN IN S_VBELN
AND A~VKORG IN S_VKORG
AND A~AUART IN S_AUART
AND A~VTWEG IN S_VTWEG
AND A~SPART IN S_SPART
AND A~VDATU IN S_VDATU
AND A~KUNNR IN S_KUNNRD
AND B~MATNR IN S_MATNR
AND B~KWMENG IN S_KWMENG
AND B~VRKME IN S_VRKME
AND B~WERKS IN S_WERKS
AND C~EDATU IN S_VDATU.
2.
SELECT VBELN FROM LIKP INTO LIKP-VBELN
WHERE LFDAT IN S_VDATU
AND VKORG IN S_VKORG
AND LFART EQ 'YSTD'
AND KUNNR IN S_KUNNRP
AND KUNAG IN S_KUNNRD
SELECT VBELN POSNR LFIMG MATNR WERKS
FROM LIPS INTO (LIPS-VBELN, LIPS-POSNR, DISPLAY_TAB-DEL_QTY,
LIPS-MATNR, LIPS-WERKS)
WHERE VBELN EQ LIKP-VBELN
AND MATNR IN S_MATNR
AND VTWEG IN S_VTWEG
AND SPART IN S_SPART
AND WERKS IN S_WERKS.
ENDSELECT.
ENDSELECT.
4.
SELECT DELIVERY POSNR MATNR PODLFIMG FROM T9YPODI INTO
(T9YPODI-DELIVERY, T9YPODI-POSNR, T9YPODI-MATNR, T9YPODI-PODLFIMG)
WHERE MATNR IN S_MATNR
AND PODDATE IN S_VDATU.
Answer's will be a great help.
~Thank You,
Lourd
Edited by: Lourd06 on Oct 23, 2009 10:32 AM
Moderator message - Welcome to SCN.
Moderator message - Please see Please Read before Posting in the Performance and Tuning Forum before posting. You're in the driver's seat here. It's up to you to do some analysis before expecting that people can halp you. - post locked
And please use code tags.
Edited by: Rob Burbank on Oct 23, 2009 9:13 AMHi All,
We've checked the transaction ST22 it is TIME OUT. I really need your help on this the program will dump in number 1 Select statement. Can you help me perform a performance tunning.
In transaction ST22
Runtime Errors TIME_OUT
Date and Time 21.10.2009 08:51:33
Short text
Time limit exceeded.
What happened?
The program "ZV0PSR10" has exceeded the maximum permitted runtime without
interruption and has therefore been terminated.
What can you do?
Note down which actions and inputs caused the error.
To process the problem further, contact you SAP system
administrator.
Using Transaction ST22 for ABAP Dump Analysis, you can look
at and manage termination messages, and you can also
keep them for a long time.
Error analysis
After a specific time, the program is terminated to make the work area
available to other users who may be waiting.
This is to prevent a work area being blocked unnecessarily long by, for
example:
- Endless loops (DO, WHILE, ...),
- Database accesses with a large result set
- Database accesses without a suitable index (full table scan)
The maximum runtime of a program is limited by the system profile
parameter "rdisp/max_wprun_time". The current setting is 1200 seconds. If this
time limit is
exceeded, the system attempts to cancel any running SQL statement or
signals the ABAP processor to stop the running program. Then the system
waits another 60 seconds maximum. If the program is then still active,
the work process is restarted.
~Thank you
Lourd
Edited by: Lourd06 on Oct 23, 2009 11:22 AM
Edited by: Lourd06 on Oct 23, 2009 11:33 AM -
Syntax Error with EXPORT statement in ECC 6
Hi All,
I have one issue with EXPORT statement syntax.
I have declared data like below:
DATA: BEGIN OF mem_id,
mandt LIKE sy-mandt,
uname LIKE sy-uname,
modno LIKE sy-modno,
END OF mem_id.
export the memory id
EXPORT E_VBKOK XANZPK TEXTTAB XBOLNR TO MEMORY ID MEM_ID.
When I am checking the syntax error i am getting like "MEM_ID" must be a character-type field (data type C, N, D or T). by "INTERFACE". by "INTERFACE". "INTERFACE". by "INTERFACE". by "INTERFACE".
I know this statement would be like IMPORT ITAB TO JTAB FROM MEMORY ID 'table'. So I have written like below
EXPORT E_VBKOK XANZPK TEXTTAB XBOLNR TO MEMORY ID 'MEM_ID'. But still it is throwing an error.
Can you please let me know how can I resolve this?
Regards,
Jyothi CH.Hi Jyothi,
data: l_var type string.
concatenate '6' '8' into l_var separated by space.
export l_var to memory id 'BB'.
Here we have to declare the type(structure) for l_var not for BB
and in another program
data:l_var type string.
import l_var from memory id 'BB'.
write : l_var. -
Problem with Select statement.
DATA: wa_usr05 TYPE usr05.
The select statement always gives sy-subrc = 0
even if there is no entry with parid = 'ZRD'.
On successful it fills the structure wa_usr05 as
MANDT C 3 ACC
BNAME C 12 SCL
PARID C 20 X
PARVA C 18
but mandt is 310.
USR05 is a pool table and has mandt field.
SELECT SINGLE bname
parid
parva
FROM usr05
INTO wa_usr05
WHERE bname = sy-uname AND
parid = 'ZRD' AND
parva = 'x' OR parva = 'X'.
Let me know the reason and solution to the problem.SELECT SINGLE * FROM usr05
INTO wa_usr05
WHERE bname = sy-uname AND
parid = 'ZRD' AND
parva = <b>'X'</b> .
Use single * as u have defined the wa+usr05 as usr05.
Else.
DATA: i_usr05 TYPE STANDARD TABLE of usr05.
SELECT * FROM USR05
INTO TABLE usr05
WHERE bname = sy-uname AND
parid = 'ZRD' AND
parva = <b>'X'</b> .
Then loop at itab and write data.
Hope this solves ur query.
Reward points if this helps.
Message was edited by:
Judith Jessie Selvi -
Sequence error in select statement
Does anyone know why I get the following error when I run the code below. If so, how can it be fixed.
Thanks in advance,
John C
ORA-02287 sequence number not allowed here
INSERT INTO PROMO_STAGE.NAC_OFFER (CMPGN_KEY, OFFER_KEY, CREATIVE)
SELECT DISTINCT A.CREATIVE,
B.CMPGN_KEY,
PROMO_STAGE.SEQ_NAC_OFFER_KEY.NEXTVAL@DSTAGE
FROM PROMO_STAGE.CAMPAIGN@DSTAGE B,
ROCEONOF.NACQ0211_2_FINAL@OGD A
WHERE B.CMPGN_ID = 'NAC_'|| to_char(add_months(SYSDATE,-1),'YYYYMM');John
It is the DISTINCT which is causing the trouble. How about:
INSERT INTO PROMO_STAGE.NAC_OFFER (CMPGN_KEY, OFFER_KEY, CREATIVE)
SELECT COL1, COL2, PROMO_STAGE.SEQ_NAC_OFFER_KEY.NEXTVAL@DSTAGE
FROM
(SELECT DISTINCT A.CREATIVE COL1, B.CMPGN_KEY COL2
FROM PROMO_STAGE.CAMPAIGN@DSTAGE B,
ROCEONOF.NACQ0211_2_FINAL@OGD A
WHERE B.CMPGN_ID = 'NAC_'|| to_char(add_months(SYSDATE,-1),'YYYYMM'));
Incidentally, judging by the column names, it appears that the columns in your insert statement are not listed in the same order as in the select statement, which of course they should be. -
SQL insert with select statement having strange results
So I have the below sql (edited a bit). Now here's the problem.
I can run the select statement just fine, i get 48 rows back. When I run with the insert statement, a total of 9062 rows are inserted. What gives?
<SQL>
INSERT INTO mars_aes_data
(rpt_id, shpdt, blno, stt, shpr_nad, branch_tableS, csgn_nad,
csgnnm1, foreign_code, pnt_des, des, eccn_no, entity_no,
odtc_cert_ind, dep_date, equipment_no, haz_flag, schd_no,
schd_desc, rec_value, iso_ulti_dest, odtc_exempt, itn,
liscence_no, liscence_flag, liscence_code, mblno, mot,
cntry_load, pnt_load, origin_state, airline_prefix, qty1, qty2,
ref_val, related, routed_flag, scac, odtc_indicator, seal_no,
line_no, port_export, port_unlading, shipnum, shprnm1, veh_title,
total_value, odtc_cat_code, unit1, unit2)
SELECT 49, schemaP.tableS.shpdt, schemaP.tableS.blno,
schemaP.tableS.stt, schemaP.tableS.shpr_nad,
schemaP.tableM.branch_tableS, schemaP.tableS.csgn_nad,
schemaP.tableS.csgnnm1, schemaP.tableD.foreign_code,
schemaP.tableS.pnt_des, schemaP.tableS.des,
schemaP.tableD.eccn_no, schemaP.tableN.entity_no,
schemaP.tableD.odtc_cert_ind, schemaP.tableM.dep_date,
schemaP.tableM.equipment_no, schemaP.tableM.haz_flag,
schemaP.tableD.schd_no, schemaP.tableD.schd_desc,
schemaP.tableD.rec_value,
schemaP.tableM.iso_ulti_dest,
schemaP.tableD.odtc_exempt, schemaP.tableM.itn,
schemaP.tableD.liscence_no,
schemaP.tableM.liscence_flag,
schemaP.tableD.liscence_code, schemaP.tableS.mblno,
schemaP.tableM.mot, schemaP.tableS.cntry_load,
schemaP.tableS.pnt_load, schemaP.tableM.origin_state,
schemaP.tableM.airline_prefix, schemaP.tableD.qty1,
schemaP.tableD.qty2,
schemaC.func_getRefs@link (schemaP.tableS.ptt, 'ZYX'),
schemaP.tableM.related, schemaP.tableM.routed_flag,
schemaP.tableM.scac, schemaP.tableD.odtc_indicator,
schemaP.tableM.seal_no, schemaP.tableD.line_no,
schemaP.tableM.port_export,
schemaP.tableM.port_unlading, schemaP.tableS.shipnum,
schemaP.tableS.shprnm1, schemaP.tableV.veh_title,
schemaP.tableM.total_value,
schemaP.tableD.odtc_cat_code, schemaP.tableD.unit1,
schemaP.tableD.unit2
FROM schemaP.tableD@link,
schemaP.tableM@link,
schemaP.tableN@link,
schemaP.tableS@link,
schemaP.tableV@link
WHERE tableM.answer IN ('123', '456')
AND SUBSTR (tableS.area, 1, 1) IN ('A', 'S')
AND entity_no IN
('A',
'B',
'C',
'D',
'E',
AND TO_DATE (SUBSTR (tableM.time_stamp, 1, 8), 'YYYYMMDD')
BETWEEN '01-Mar-2009'
AND '31-Mar-2009'
AND tableN.shipment= tableD.shipment(+)
AND tableN.shipment= tableS.shipnum
AND tableN.shipment= tableM.shipment(+)
AND tableN.shipment= tableV.shipment(+)
<SQL>
Edited by: user11263048 on Jun 12, 2009 7:23 AM
Edited by: user11263048 on Jun 12, 2009 7:27 AMCan you change this:
BETWEEN '01-Mar-2009'
AND '31-Mar-2009'To this:
BETWEEN TO_DATE('01-Mar-2009', 'DD-MON-YYYY')
AND TO_DATE('31-Mar-2009','DD-MON-YYYY')That may make no difference but you should never rely on implicit conversions like that, they're always likely to cause you nasty surprises.
If you're still getting the discrepancy, instead of and INSERT-SELECT, can you try a CREATE TABLE AS SELECT... just to see if you get the same result. -
Runtime error for SELECT statement
Hi All,
I have written a SELECT statement as follows in my code.
select budat pernr aufnr vornr from AFRU
into corresponding fields of table it_vornr
for all entries in it_cats_tmp
where budat = it_cats_tmp-workdate
and pernr = it_cats_tmp-pernr
and aufnr = it_cats_tmp-rnplnr.
The table IT-CATS_TMP is having around 3000+ lines.
When control moves to this statement, the system is throwing Runtime error or its taking around 30 minutes time to execute.
If i query the same table (AFRU) in SE11 for the same set of conditions, the table displays relevent data immediately.
What might be the reason for this delay/Runtime Error?
Shall i need to change the syntax for better performance?
Your guidelines are highly appreciated......
Regards
PavanHi
1. Try to put WHERE conditions for KEY FIELDS.
Solution: Create a RANGE for the key fields & put that in SELECT Query.
DATA: gr_rueck TYPE RANGES OF afru-rueck.
SELECT .. WHERE rueck IN gr_rueck.
2. Avoid using CORRESPONDING FIELDS OF TABLE in SELECT.
Solution: Change internal table fields ORDER.
TYPES:
BEGIN OF TY_VORNR,
budat TYPE ..
pernr TYPE ..
aufnr TYPE ..
vornr TYPE ..
... " Other fields
END OF TY_VORNR.
SELECT .. INTO TABLE IT_VORNR ... -
Problem with select statement using Ranges
Hi Guys,
I have used Ranges and used a select statement for selecting those ranges but I am facing a problem.
RANGES: r_doctyp for EDIDC-DOCTYP.
r_doctyp-sign = 'I'.
r_doctyp-option = 'EQ'.
r_doctyp-low = 'DEBMAS'.
append r_doctyp.
r_doctyp-sign = 'I'.
r_doctyp-option = 'EQ'.
r_doctyp-low = 'MATMAS'.
append r_doctyp.
r_doctyp-sign = 'I'.
r_doctyp-option = 'EQ'.
r_doctyp-low = 'PRICAT'.
append r_doctyp.
r_doctyp-sign = 'I'.
r_doctyp-option = 'EQ'.
r_doctyp-low = 'ORDERS'.
append r_doctyp.
r_doctyp-sign = 'I'.
r_doctyp-option = 'EQ'.
r_doctyp-low = 'INVOIC'.
append r_doctyp.
Select DOCNUM " IDoc number
DOCTYP " IDoc Type
from EDIDC into table IT_ZEDIDC
where CREDAT EQ s_credat-low
and DOCTYP EQ r_doctyp " IDOC Types
and DIRECT EQ '1'.
Here my select statement is only taking INVOIC.
But my statement should take any document type.
Thanks,
Prasad.Hi...,
Your following select statement is correct.
Select DOCNUM " IDoc number
DOCTYP " IDoc Type
from EDIDC into table IT_ZEDIDC
where CREDAT IN s_credat
and DOCTYP IN r_doctyp " IDOC Types
and DIRECT EQ '1'.
Why you are not getting result..
1. structure of the IT_ZEDIDC is having two fields DOCNUM , DOCTYP with same data lengths. If not it should be...
2. Order in the database table is must be similer to the order you maintained in the select statement.
3. As you are hard coding the input ranges make sure about every letter.
4. take a look at other where condition fields too.
5. check the table of the ranges in debugging mode.
6. why can't you declare separate work area and table for ranges...?
like .... data: r_tab type range of <field>
data: wa_tab like line of r_tab.
7. Use clear work area statement after the append statment.
--Naveen Inuganti. -
Need help with select statement or query
Not familiar with what to call it, but here is what i need...
To give our analyst a better idea of warranty on some of our
equipment, i
would like to add to the page a column that displays if the
device is still
under warranty
I currently capture the date the equipment was returned from
repair, so what
could i use within my select statement or query to display a
warranty
expiration date or display on the page...
example :
Returned from repair 10/20/2006 warranty expires on
11/20/2006
each equipment has different warranties, so i need a formula
or something to
say... device #1 has 60 day warranty ( so 10/20/2006 + 60days
=
12/19/2006 )
I would imagine this to be a query
Table 1 would contain the equipment type and warranty time
Table 2 would contain the current status of the equipment
Query would take the back from repair date + warranty =
expiration dateSimple. Join the two tables and create a derived column for
the expiration date. The exact syntax is dependant on your DBMS, so
check the manual for whichever you are using and look at the date
functions. There will be a function that will allow you to add a
number of date units (day, month, year, etc) to a date
field. -
Excessive flashback log generates with select statement
Hi everyone;
We have some extractions taken from a "flashback on" database.
Extractions are just select statements but when they are run, database produces excessive flashback logs.
What may be the reason database produce flashback logs with just select statements?
(It's certain that there are no insert-update-delete operations)
Version: 10.2.0.4.3
Thanks...Do you do heavy update/delete before you select the statements ?
I am not very sure if delayed block cleanout also have the same effect on flashback logs but the output below is leading me to think that way
HR@ORACOS> select * from v$flashback_database_stat;
BEGIN_TIME END_TIME FLASHBACK_DATA DB_DATA REDO_DATA ESTIMATED_FLASHBACK_SIZE
20100527 15:32:53 20100527 15:50:16 875266048 1207132160 2038729728 0
20100527 14:32:50 20100527 15:32:53 248160256 127295488 450139648 1.3215E+10
20100527 13:32:48 20100527 14:32:50 10452992 15646720 4400640 1.5549E+10
20100527 12:32:43 20100527 13:32:48 745693184 948461568 1311620608 2.2789E+10
20100527 11:25:56 20100527 12:32:43 1262026752 1984741376 2358546432 2.7212E+10
HR@ORACOS> set autotrace traceonly statistics
HR@ORACOS> update base_table_np set y='INVALID';
commit;
4021808 rows updated.
Statistics
2512 recursive calls
8341430 db block gets
4069140 consistent gets
120569 physical reads
1908471980 redo size
848 bytes sent via SQL*Net to client
793 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
4021808 rows processed
HR@ORACOS> set autotrace off;
HR@ORACOS> select * from v$flashback_database_stat;
HR@ORACOS>
BEGIN_TIME END_TIME FLASHBACK_DATA DB_DATA REDO_DATA ESTIMATED_FLASHBACK_SIZE
20100527 15:32:53 20100527 16:00:36 1236664320 2021974016 4019910656 0
20100527 14:32:50 20100527 15:32:53 248160256 127295488 450139648 1.3215E+10
20100527 13:32:48 20100527 14:32:50 10452992 15646720 4400640 1.5549E+10
20100527 12:32:43 20100527 13:32:48 745693184 948461568 1311620608 2.2789E+10
20100527 11:25:56 20100527 12:32:43 1262026752 1984741376 2358546432 2.7212E+10
HR@ORACOS> set autotrace traceonly statistics
HR@ORACOS> select * from base_table_np;
4021808 rows selected.
Statistics
139 recursive calls
0 db block gets
53908 consistent gets
4404 physical reads
1652384 redo size ------->delayed block cleanout effect
175008833 bytes sent via SQL*Net to client
88996 bytes received via SQL*Net from client
8045 SQL*Net roundtrips to/from client
4 sorts (memory)
0 sorts (disk)
4021808 rows processed
HR@ORACOS> set autotrace off
HR@ORACOS> select * from v$flashback_database_stat; ----flashback data size increases
HR@ORACOS>
BEGIN_TIME END_TIME FLASHBACK_DATA DB_DATA REDO_DATA ESTIMATED_FLASHBACK_SIZE
20100527 15:32:53 20100527 16:01:11 1305264128 2054594560 4021728256 0
20100527 14:32:50 20100527 15:32:53 248160256 127295488 450139648 1.3215E+10
20100527 13:32:48 20100527 14:32:50 10452992 15646720 4400640 1.5549E+10
20100527 12:32:43 20100527 13:32:48 745693184 948461568 1311620608 2.2789E+10
20100527 11:25:56 20100527 12:32:43 1262026752 1984741376 2358546432 2.7212E+10Basically what I do is I update a 4 million table big redo generated with flashback logs
When I do select after the update I still see the redo generated because of delayed block cleanout but what I also see is the slight increase in flashback data size (check the first row of flashback_database_stat) which suits what you asking for. Select statement generates flashback log
Tested on 11.2.0.1 with single active session on the db
Coskan Gundogar
Blog: http://coskan.wordpress.com
Twitter: http://www.twitter.com/coskan
Linkedin: http://uk.linkedin.com/in/coskan
---------
Maybe you are looking for
-
Streaming from a Guest Account
Hello, I am wanting to have a friend watch a live stream from my mac connected with HDMI cable to my TV. I can get to safari, get to the web page, in this case ESPN2. However, live stream only gets as far as "loading." I never get it loaded. So, I at
-
History of changes in BPM Composer
Hi!!! Does any body knows if it is posible to see the history of changes done in a process in BPM Composer? The information that I want to see is which changes where done by a specific user? When? Like an audit trail of the changes done in a process.
-
My desktop photo disappears when I reboot iMac...replaced with default apple image. does anyone know a fix?
-
Capturing Parameters in WebDB aplication
***I am sorry to post the message in 8ilite forum as I couldn't find one for WebDB **** In my application on WebDB I have to populate the table with the data displayed on the screen. I am planning to capture the parameter passed to the report in "aft
-
Getting rid of unwanted background audio
Hey guys, so recently I recorded some interviews in not the ideal location. As such the audio I have has background noise ranging from a waterfall making noise to small chatter of other people. I have tried to clean up the audio and get rid of the ad