Problem with select....where IN statement
Hi,
i have the following select-statement in my z-abap:
DATA: s_kostl TYPE RANGE OF cosp-objnr,
DATA: s_kstar TYPE RANGE OF kstar,
SELECT (lv_feldname) INTO lv_betrag
FROM coss WHERE lednr = '00' AND
objnr IN s_kostl AND
gjahr = gjahr AND
kstar IN s_kstar AND
wrttp = '04' AND
versn = '000'.
now i get a dump, because s_kostl and/or s_kstar contains about 11.000 entries (DBIF_RSQL_INVALID_RSQL).
how can avoid this ? or how i have to 'rewrite' my SQL statment that the ranges-tabs s_kostl AND s_kstar can be processed
correctly ?
br, Martin
Hello.
I guess that the problem is not the limit or ranges, it is on the select statement. check it
It should be select single
yours:
{code}
SELECT (lv_feldname) INTO lv_betrag
FROM coss WHERE lednr = '00' AND
objnr IN s_kostl AND
gjahr = gjahr AND
kstar IN s_kstar AND
wrttp = '04' AND
versn = '000'.
{code}
correct:
{code}
SELECT SINGLE (lv_feldname) INTO lv_betrag
FROM coss WHERE lednr = '00' AND
objnr IN s_kostl AND
gjahr = gjahr AND
kstar IN s_kstar AND
wrttp = '04' AND
versn = '000'.
{code}
Try doing that change. Also, check frist without using LV_feldname, use the name of the field that u want to select, once u get the correct result change it back.
Regards
Miguel
Similar Messages
-
I'm having a problem with a SELECT clause...
the variables...
<cfset MyString=#getProducts.matches_with#>
<cfset myArrayList = ListToArray(MyString)>
the query...
SELECT *
FROM pricelist
WHERE supplier_code IN ('#myArrayList[1]#' , '#myArrayList[2]#')
The problem is, the select clause is only ever retrieving one row, despite their being several matches
The clause works fine when I change the WHERE line to
WHERE supplier_code IN ('E1775' , 'R1771')
What am I doing wrong here ?Just wanted to say thanks all for the advice - I'm back on track now.
As you know I had a field 'matches_with' in the merchandise table which contains a comma separated list, which I now accept is bad design.
I wrote the following code to take each field and put it into a new table called matches_with, which contains two fields
product_code , matches_with_product_code. All done.
<cfloop query="getData">
<!--- create an array based on the csv list of items in matches_with field --->
<cfset myArray = ListToArray(#getData.matches_with#)>
<!--- skip if no items in array --->
<cfif #ArrayLen(myArray)# gt 0>
<!--- loop through item in the array --->
<cfloop from="1" to="#ArrayLen(myArray)#" index="i">
<cfquery name="insert" datasource="foo">
<!--- insert each array item into SQL table --->
INSERT INTO 00_matches_with (product_code, matches_with_product_code)
VALUES ('#getData.product_code#' , '#myArray[i]#')
</cfquery>
</cfloop>
</cfif>
</cfloop> -
Problem with "SELECT...FOR UPDATE OF..." and "POST command" combination
Problem in committing transactions in Multiple Forms (Oracle Forms) with POST built-in command:
Consider that the following statements are written in WHEN-WINDOW-CLOSED trigger of a called form.
Statements in called form (Form name: FORM_CHILD):
go_block('display_block') ;
do_key('execute_query') ;
-- Data from table_b will be populated in this block, based on the value of COLUMN_1 obtained
-- from TABLE_A.
-- Example: If the value of COLUMN_1 is 10, then all the matching records from TABLE_B, which
-- are inserted with value 10 in TABLE_B.COLUMN_1 will be fetched and shown here.
if user_choice = 'YES' then
commit ;
else
rollback ;
end if ;
Statements in calling forms:
There are two calling forms having following statements and it is going to call the above said called form.
CALLING FORM 1
Statements in KEY-COMMIT trigger:
post;
call_form(form_child, no_activate) ;
Statements in ON-INSERT trigger:
select column_1
from table_a
for update of column_1
where column_2 = 'X' ;
update table_a
set column_1 = column_1 + 1
where column_2 = 'X' ;
insert into table_b ...;
insert into table_b ...; Statements in KEY-COMMIT trigger:
post;
call_form(form_child, no_activate) ;
CALLING FORM 2:
Statements in ON-INSERT trigger:
select column_1
from table_a
for update of column_1
where column_2 = 'X' ;
update table_a
set column_1 = column_1 + 1
where column_2 = 'X' ;
insert into table_b ...;
insert into table_b ...;
insert into table_b ...;
Our understanding:
Assume that both the forms are running from two different machines/instances, issuing commit at the same time. In this case, forms will start executing the statements written in ON-INSERT trigger, the moment POST command is executed. Though the commit is issued at the same time, according to oracle, only one of the request will be taken for processing first. Assume that calling form 1 is getting processed first.
So, it fetches the value available in COLUMN_1 of TABLE_A and locks the row from further select, update, etc. as SELECT...FOR UPDATE command is used (note that NOWAIT is not given, hence the lock will be released only when COMMIT or ROLLBACK happens) and proceed executing further INSERT statements. Because of the lock provided by the SELECT...FOR UPDATE command, the statements in calling form 2 will wait for the resource.
After executing the INSERT statements, the FORM_CHILD is called. The rows inserted in to TABLE_A will be queried and shown. The database changes will be committed when user closes the window (as COMMIT is issued in its WHEN-WINDOW-CLOSED trigger). Then the SELECT...FOR UPDATE lock will be released and calling form 2's statements will be executed.
Actual happenings or Mis-behavior:
Calling form 2 starts executing INSERT statements instead of waiting for SELECT...FOR UPDATE lock. Also, the value selected from TABLE_A.COLUMN_1 is same in both the calling forms, which is wrong.
The rows inserted into TABLE_B are having similar COLUMN_1 values in calling form 2 and they are fetched and shown in the called form FORM_CHILD.
Note that in calling form 2 also POST only is issued, but the changes posted there are accessible in calling form 1 also, which is wrong.
Kindly suggest us as to how to fix above problem. It will be much use, if you can send us the information regarding the behavior of Oracle Forms POST built-in also.
Our mail ID: [email protected]
Thanks a lot in advance.You have several problems:
1. On-Insert will ONLY run if you have created a new record in a base-table block. If you haven't done that, then the POST command will not cause it to run.
2. Select for update without a "no wait" will lock records for the first form, but when the second form tries this, it will hit the ORA-00054 exception, and will NOT wait. The only way you could make it wait is to issue an UPDATE sql command, which is not such a good way to go.
All POST does is issues SQL insert or update commands for any changes the user has made to records in a form's base-table blocks, without following with a Commit command.
Also understand that Commit is the same as Commit_Form, and Rollback is the same as Clear_Form. You should read up on these in the Forms help topics. -
Problem with: select 'c' as X from dual
Problem with 'select 'c' as X from dual'
I get 2 different results when I execute the above with SQLPlus (or java) depending on the instance I am connected to. For one instance the result is a single character and for the other the character is padded with blanks to 32 chars in the SQLPlus window (and java). Does anyone know what database setting causes this to happen? Is it a version issue ?
Test #1: Oracle 9.2.0.6 - SQLPlus result is padded with blanks
SQL*Plus: Release 9.2.0.1.0 - Production on Mon Dec 10 09:27:58 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
With the Partitioning option
JServer Release 9.2.0.6.0 - Production
SQL> select 'c' as X from dual;
X
c
SQL>
Test #2 Oracle 9.2.0.1 SQLPlus result is a single character.
SQL*Plus: Release 9.2.0.1.0 - Production on Mon Dec 10 09:29:27 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
SQL> select 'c' as X from dual;
X
c
SQL>Using 9.2.0.6 On AIX 5.2 I get the single byte result:
UT1 > select 'c' as X from dual;
X
c
If the databases are on different Oracle Homes you may want to check the sqlplus global logon files for any set commands.
If you executed the two sql statements from different OS directories you may also want to check your sqlpath for sqlplus .logon files.
Try issueing clear columns and repeating the statement. Are the results the same?
HTH -- Mark D Powell -- -
Problem with selecting text in Adobe Reader XI
Hi all, I am encountering a problem with Adobe Reader XI and it is very strange I could not find an alike issue on the internet so I guess I have to submit a question with it.
So here it is, I am using Adobe Reader XI Version 11.0.2, operating system: Windows 7. I do not know it starts from when but it has the problem with selecting text - to be copied in pdf documents. I ensure that the documents are not scanned documents but word-based documents (or whatever you call it, sorry I cannot think of a proper name for it).
Normally, you will select the text/paragraph you want to copy and the text/paragraph will be highlighted, but the problem in this case that I cannot select the text/paragraph, the blinking pointer (| <-- blinking pointer) will just stays at the same location so I cannot select/highlight anything to be copied. It happens oftenly, not all the time but 90%.
This is very annoying as my work involves very much with copying text from pdf documents, I have to close the pdf file and then open it again so I can select the text but then after the first copying or second (if I am lucky), the problem happens again. For a few text I have to type it myself, for a paragraph I have to close all opening pdf documents and open again so I could select the paragraph to copy. I ran out of my patience for this, it causes trouble and extra time for me just to copying those texts from pdf documents. Does this problem happen to anyone and do you have a solution for this? I would much appreciate if you could help me out, thank you!Yeah, I totally agree, this is very strange. I have always been using Adobe Reader but this problem only occurred ~three months ago. It must be that some software newly installed I think. But I have no idea.
About your additional question, after selecting the texts and Ctrl + C, the texts are copied and nothing strange happens. It's just that right after I managed to copy the texts, it takes me a while to be able to select the texts again. For your information, I just tested to select the texts and then pressed Ctrl, the problem happened. And then I tried pressing C and then others letters, it all led to the problem.
I guess I have to stick with left-clicked + Copy until I/someone figure the source of this problem. Thanks a lot for your help! -
Problems with "Select Distinct" Statement
Hi... I've a little problem with my SQL Statement...
I've a Table in a DataBase with Solds of the Month... the fields are: vta_fecha, vta_prod, vta_total, vta_mesa.
I've to Select only the distincts fields of vta_prod... selected by vta_fecha and vta_mesa...
My code is like this: try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conec = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/POOL/Data/BaseDat.MDB");
state = conec.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);try{
rec = state.executeQuery("Select DISTINCT vta_prod, vta_fecha, vta_mesa from Ventas where vta_fecha = #" + Fecha_q + "# And vta_mesa = 0");
rec.first();
int x = 0;
while (rec.isAfterLast()==false){
x++;
rec.next();
rec.first();
if (x > 0){
Productos = new String[x];
Total_Vta = new int[x];
Cant_Prod = new int[x];
x = 0;
while (rec.isAfterLast() == false){
Productos[x] = rec.getString("vta_prod");
rec.next();
x++;
else{
Productos = new String[0];
Total_Vta = new int[0];
Cant_Prod = new int[0];
}catch(Exception e){JOptionPane.showMessageDialog(null,e.getMessage());}Now, in the Table I have only 3 diferents vta_prod, but this Statement returns 9 Rows... and I don't know why...
Please help me...
Regards...I don�t have a complete picture because I don�t know what values you are passing in the select and I don�t know your column types but this is what I think is happening from what you have shared.
You may have misunderstood what the DISTINCT keyword does.
The DISTINCT keyword applies to the full set of columns in the select (not just the first column). So in your case it would be equivalent to:
SELECT vta_prod, vta_fecha, vta_mesa
FROM Ventas
WHERE ...
GROUP BY by vta_prod, vta_fecha, vta_mesa
So, it doesn't matter that you only have 3 distinct vta_prod values if you have multiple values being returned in the other columns. The vta_mesa column can only a return a single value as �0�. That leaves the vta_fecha column which is probably a date/time column and is probably the column that is returning the three other distinct values (one date with three distinct times).
(3 vta_prod) x (3 vta_fecha) x (1 vta_mesa) or 3x3x1 = 9 rows
So find a way to strip the time from vta_fecha in your select statement and your SQL should return the results you expect. I�m not an Access expect but I think I remember you can use something like the �Convert� or �DatePart� functions to make that happen (check your documentation to be sure)..
A couple of asides;
1) You should use a PreparedStatement and rarely if ever use Statement.
2) You should start Java variable names with lower case. -
Problems with select statement
Hi,
For some reason I cannot find the solution for the following problem.
I have an internal table.
Now I like to make an select over a database table, while only rows should be selected, where the key field occurs in the internal table and in case of identical key field only the row with the lowest value in another column is selcted.
Example:
- internal table:
col1 col2 col3
1 A AA
2 B AA
3 A AC
-database table:
col1 col2 col3
1 001 CD
1 002 CF
1 003 CG
2 001 CD
2 002 CF
2 003 CG
3 002 CF
3 003 CG
4 001 CD
4 002 CF
4 003 CG
- the selected database entries should be
1 001 CD
2 001 CD
3 002 CF
explication:
- entries with 4 in the first column do not occur in the internal table, so they do not appear in the selection
- in case of more than one entry in the database table only the one with the lowest value in column two will be selected
If you have any idea how this could be solved, I would really appreciate you help.
regards
TorstenHi,
1) u have to select based on internal table 1
2) u have to filter the internal table 2 for minimum value.
select col1 col2 col3
from <any table>
into table <Internal_table_final>
for all entries in <Internal_table_1>
where col1 = Internal_table_1-col1.
sort Internal_table_final by col1 col2.
loop at Internal_table_final.
at new col1.
continue.
endat.
delete Internal_table_final.
endloop.
<b>try this</b>
Regards
<b>Mark Helpful Answers</b>
Message was edited by: Manoj Gupta -
Problem with the control break statement - AT END OF
data : IT_DATA TYPE STANDARD TABLE OF /BIC/OH0SPA_OHD WITH KEY /B28/S_D1DVOX5 ,
FIELD-SYMBOLS : <ls_data> TYPE any,
SELECT * FROM (c_open_hub) INTO TABLE IT_DATA .
*IF sy-subrc = 0.
*ENDIF.
Create the GUID for header
CALL FUNCTION 'GUID_CREATE'
IMPORTING
EV_GUID_32 = LV_GUID.
TRY.
CALL METHOD CL_GDT_CONVERSION=>GUID_OUTBOUND
EXPORTING
IM_GUID_C = LV_GUID
IMPORTING
EX_VALUE = LV_UUID.
CATCH CX_GDT_CONVERSION INTO go_exc .
gv_text = go_exc->get_text( ).
Application log for errors
IF gv_text IS NOT INITIAL.
PERFORM add_msg_to_log CHANGING lt_return.
CALL FUNCTION '/SPA/APPL_LOG'
EXPORTING
LV_OBJECT = '/SPA/APPL'
LV_SUBOBJECT = '/SPA/ESOA'
IT_RETURN = lt_return.
ENDIF.
ENDTRY.
OUTPUT-TRADE_PROMOTION_CRMBULK_CREATE-MESSAGE_HEADER-ID-CONTENT = LV_GUID.
OUTPUT-TRADE_PROMOTION_CRMBULK_CREATE-MESSAGE_HEADER-UUID-CONTENT = LV_UUID.
SELECT * FROM DD03T INTO TABLE lt_dd03t WHERE TABNAME = c_open_hub AND DDLANGUAGE = 'E' AND AS4LOCAL = 'A'.
*IF sy-subrc = 0.
*ENDIF.
Sort the delta table
SORT it_data.
populate the output structure
LOOP AT IT_DATA ASSIGNING <ls_data>.
READ TABLE lt_dd03t INTO ls_dd03t with KEY DDTEXT = c_keyfigures.
ASSIGN COMPONENT ls_dd03t-FIELDNAME OF STRUCTURE <ls_data> to <l_keyfigures>.
READ TABLE lt_dd03t INTO ls_dd03t with KEY DDTEXT = c_signdata.
ASSIGN COMPONENT ls_dd03t-FIELDNAME OF STRUCTURE <ls_data> to <l_signdata>.
READ TABLE lt_dd03t INTO ls_dd03t with KEY DDTEXT = c_bbtype.
ASSIGN COMPONENT ls_dd03t-FIELDNAME OF STRUCTURE <ls_data> to <l_bbtype>.
READ TABLE lt_dd03t INTO ls_dd03t with KEY DDTEXT = c_customer.
ASSIGN COMPONENT ls_dd03t-FIELDNAME OF STRUCTURE <ls_data> to <l_customer>.
READ TABLE lt_dd03t INTO ls_dd03t with KEY DDTEXT = c_product.
ASSIGN COMPONENT ls_dd03t-FIELDNAME OF STRUCTURE <ls_data> to <l_product>.
READ TABLE lt_dd03t INTO ls_dd03t with KEY DDTEXT = c_territory.
ASSIGN COMPONENT ls_dd03t-FIELDNAME OF STRUCTURE <ls_data> to <l_territory>.
READ TABLE lt_dd03t INTO ls_dd03t with KEY DDTEXT = c_time.
ASSIGN COMPONENT ls_dd03t-FIELDNAME OF STRUCTURE <ls_data> to <l_time>.
CASE <l_keyfigures>.
WHEN c_sd.
PERFORM DATE_CALC USING <l_signdata> CHANGING LV_DATE.
ls_period_term-start_date = lv_date.
WHEN c_ed.
PERFORM DATE_CALC USING <l_signdata> CHANGING LV_DATE.
ls_period_term-end_date = lv_date.
WHEN c_uplift.
LS_PRODUCT_KF-ID-CONTENT = c_uplift_qyts.
LS_PRODUCT_KF-VALUE = <l_signdata>.
LS_PRODUCT_KF-YEAR = lv_week(4).
LS_PRODUCT_KF-CALENDAR_PERIOD_ORDINAL_NUMBER = lv_week+4.
APPEND LS_PRODUCT_KF TO LT_PRODUCT_KF.
WHEN OTHERS.
PERFORM DATE_CALC USING <l_signdata> CHANGING LV_DATE.
ls_period_term-start_date = lv_date.
Get week
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING
DATE = LS_PERIOD_TERM-START_DATE
IMPORTING
WEEK = LV_WEEK.
append Keyfigure
LS_PRODUCT_KF-ID-CONTENT = <l_keyfigures> .
LS_PRODUCT_KF-VALUE = <l_signdata>.
LS_PRODUCT_KF-YEAR = lv_week(4).
LS_PRODUCT_KF-CALENDAR_PERIOD_ORDINAL_NUMBER = lv_week+4.
APPEND LS_PRODUCT_KF TO LT_PRODUCT_KF.
append tradespend
SELECT SINGLE * FROM /SPA/SPEND_MAP INTO CORRESPONDING FIELDS OF LV_/SPA/SPEND_MAP
WHERE KEY_FIGURE = <l_keyfigures>.
IF sy-subrc = 0.
LS_TRADE_SPEND-TYPE_CODE-CONTENT = LV_/SPA/SPEND_MAP-SPEND_TYPE.
LS_TRADE_SPEND-CATEGORY_CODE-CONTENT = LV_/SPA/SPEND_MAP-SPEND_CATEGORY.
LS_TRADE_SPEND-METHOD_CODE-CONTENT = LV_/SPA/SPEND_MAP-SPEND_METHOD.
APPEND LS_TRADE_SPEND TO LT_TRADE_SPEND.
else.
lv_flg = 'X'.
ENDIF.
ENDCASE.
AT END OF /B28/S_D1DVOX5. "
SELECT SINGLE * FROM /SPA/SO_TER_MAP INTO LS_/SPA/SO_TER_MAP WHERE TERRITORY = <l_territory>.
IF sy-subrc = 0 AND lv_flg IS INITIAL.
Create the GUID for TP's
CALL FUNCTION 'GUID_CREATE'
IMPORTING
EV_GUID_32 = LV_GUID_MESSAGE.
TRY.
CALL METHOD CL_GDT_CONVERSION=>GUID_OUTBOUND
EXPORTING
IM_GUID_C = LV_GUID_MESSAGE
IMPORTING
EX_VALUE = LV_UUID_MESSAGE.
CATCH CX_GDT_CONVERSION .
ENDTRY.
populate the product
LS_PRODUCT-ID-CONTENT = <l_product>.
LS_CUSTOMER-ID-CONTENT = '300022'.
LS_CUSTOMER-ROLE_CODE = '00000105'.
LS_PRODUCT-KEY_FIGURE = LT_PRODUCT_KF.
APPEND LS_PRODUCT TO LT_PRODUCT.
APPEND LS_CUSTOMER TO LT_CUSTOMER.
APPEND LS_DESCRIPTION TO LT_DESCRIPTION.
APPEND LS_PERIOD_TERM TO LT_PERIOD_TERM.
LS_TRADE_PROMOTION-TRADE_PROMOTION-SALES_AREA-ORGANISATIONAL_CENTRE_ID = LS_/SPA/SO_TER_MAP-SALES__ORG.
LS_TRADE_PROMOTION-TRADE_PROMOTION-SALES_AREA-DISTRIBUTION_CHANNEL_CODE-CONTENT = LS_/SPA/SO_TER_MAP-DIST_CHANNEL.
LS_TRADE_PROMOTION-TRADE_PROMOTION-PLANNING_ACCOUNT-CUSTOMER_INTERNAL_ID = <l_customer>.
LS_TRADE_PROMOTION-TRADE_PROMOTION-PLANNING_PROFILE_GROUP_CODE-CONTENT = '4TPM'.
LS_TRADE_PROMOTION-TRADE_PROMOTION-TYPE_CODE-CONTENT = 'Z002'.
LS_TRADE_PROMOTION-TRADE_PROMOTION-UPLIFT_ACTIVE_INDICATOR = 'X'.
LS_TRADE_PROMOTION-TRADE_PROMOTION-PLANNING_INFORMATION-MARKETING_PROJECT_PLANNING_PRO = '5'.
LS_TRADE_PROMOTION-TRADE_PROMOTION-PLANNING_INFORMATION-CALENDAR_UNIT_CODE = 'WEE'.
LS_TRADE_PROMOTION-TRADE_PROMOTION-TRADE_SPEND = LT_TRADE_SPEND.
LS_TRADE_PROMOTION-TRADE_PROMOTION-PARTY = LT_CUSTOMER.
LS_TRADE_PROMOTION-TRADE_PROMOTION-DESCRIPTION = LT_DESCRIPTION.
LS_TRADE_PROMOTION-TRADE_PROMOTION-PLANNING_INFORMATION-PRODUCT = LT_PRODUCT.
LS_TRADE_PROMOTION-TRADE_PROMOTION-PERIOD_TERM = LT_PERIOD_TERM.
LS_TRADE_PROMOTION-MESSAGE_HEADER-ID-CONTENT = LV_GUID_MESSAGE.
LS_TRADE_PROMOTION-MESSAGE_HEADER-UUID-CONTENT = LV_UUID_MESSAGE.
LS_/SPA/REPORT_TAB-SPA_TP_ID = <l_bbtype>.
LS_/SPA/REPORT_TAB-MESSAGE_ID = LV_GUID_MESSAGE.
LS_/SPA/REPORT_TAB-CREATE_DATE = SY-DATUM.
INSERT /SPA/REPORT_TAB FROM LS_/SPA/REPORT_TAB.
APPEND LS_TRADE_PROMOTION TO LT_TRADE_PROMOTION.
OUTPUT-TRADE_PROMOTION_CRMBULK_CREATE-TRADE_PROMOTION_CRMCREATE_REQU = LT_TRADE_PROMOTION.
CLEAR : LT_DESCRIPTION, LT_PERIOD_TERM,LT_CUSTOMER, LT_PRODUCT, LT_PRODUCT_KF, LT_TRADE_SPEND,LS_/SPA/HEADER_TAB.
ENDIF.
CLEAR lv_flg .
ENDAT.
ENDLOOP.
My problem is AT-END OF STATEMENT IS executing for each and every record of same /B28/S_D1DVOX5.
Please help me from this problemHello,
First of all to know clearly about AT END.
Let's say In IT_DATA fields are F1 F2 F3 /B28/S_D1DVOX5 F5.
then AT END of /B28/S_D1DVOX5 means for each new value of this field at the end it will trigger.
Please ensure thet IT_DATA is sorted by this field and then used Control break.
Thanks,
Pramod -
Problems with explain plan and statement
Hi community,
I have migrated a j2ee application from DB2 to Oracle.
First some facts of our application and database instance:
We are using oracle version 10.2.0.3 and driver version 10.2.0.3. It runs with charset Unicode 3.0 UTF-8.
Our application is using Tomcat as web container and jboss as application server. We are only using prepared statements. So if I talk about statements I always mean prepared statements. Also our application is setting the defaultNChar property to true because every char and varchar field has been created as an nchar and nvarchar.
We have some jsp sites that contains lists with search forms. Everytime I enter a value to the form that returns a filled resultset, the lists are performing great. But everytime I enter a value that returns an empty resultset, the lists are 100 times slower. The jsp sites are running in the tomcat environment and submitting their statements directly to the database. The connections are pooled by dbcp. So what can cause this behaviour??
To anaylze this problem I started logging all statements and filled-in search field values and combinations that are executed by the lists described above. I also developed a standalone helper tool that reads the logged statements, executes them to the database and generates an explain plan for every statement. But now there appears a strange situation. Every statement, that performs really fast within our application, is now executed by the helper tool extremely slow. So I edited some jsp pages within our application to force an explain plan from there (tomcat env). So when I'm executing the same statement I'm getting with the exactly same code two completely different explain plans.
First the statement itself:
select LINVIN.BBASE , INVINNUM , INVINNUMALT , LINVIN.LSUPPLIERNUM , LSUPPLIERNUMEXT , LINVIN.COMPANYCODE , ACCOUNT , INVINTXT , INVINSTS , INVINTYP , INVINDAT , RECEIPTDAT , POSTED , POSTINGDATE , CHECKCOSTCENTER , WORKFLOWIDEXT , INVINREFERENCE , RESPONSIBLEPERS , INVINSUM_V , INVINSUMGROSS_V , VOUCHERNUM , HASPOSITIONS , PROCESSINSTANCEID , FCURISO_V , LSUPPLIER.AADDRLINE1 from LINVIN, LSUPPLIER where LINVIN.BBASE = LSUPPLIER.BBASE and LINVIN.LSUPPLIERNUM = LSUPPLIER.LSUPPLIERNUM and LINVIN.BBASE = ? order by LINVIN.BBASE, INVINDAT DESC
Now the explain plan from our application:
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 101 | 28583 | 55 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 101 | 28583 | 55 (0)| 00:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| LINVIN | 93709 | 12M| 25 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN | LINV_INVDAT | 101 | | 1 (0)| 00:00:01 |
| 4 | TABLE ACCESS BY INDEX ROWID| LSUPPLIER | 1 | 148 | 1 (0)| 00:00:01 |
|* 5 | INDEX UNIQUE SCAN | PK_177597 | 1 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
3 - access("LINVIN"."BBASE"=:1)
filter("LINVIN"."BBASE"=:1)
5 - access("LSUPPLIER"."BBASE"=:1 AND "LINVIN"."LSUPPLIERNUM"="LSUPPLIER"."LSUPPLIERNUM")
Now the one from the standalone tool:
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 93773 | 25M| | 12898 (1)| 00:02:35 |
| 1 | SORT ORDER BY | | 93773 | 25M| 61M| 12898 (1)| 00:02:35 |
|* 2 | HASH JOIN | | 93773 | 25M| 2592K| 7185 (1)| 00:01:27 |
| 3 | TABLE ACCESS BY INDEX ROWID| LSUPPLIER | 16540 | 2390K| | 332 (0)| 00:00:04 |
|* 4 | INDEX RANGE SCAN | LSUPPLIER_HAS_BASE_FK | 16540 | | | 11 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID| LINVIN | 93709 | 12M| | 6073 (1)| 00:01:13 |
|* 6 | INDEX RANGE SCAN | LINVOICE_BMDT_FK | 93709 | | | 84 (2)| 00:00:02 |
Predicate Information (identified by operation id):
2 - access("LINVIN"."BBASE"="LSUPPLIER"."BBASE" AND "LINVIN"."LSUPPLIERNUM"="LSUPPLIER"."LSUPPLIERNUM")
4 - access("LSUPPLIER"."BBASE"=:1)
6 - access("LINVIN"."BBASE"=:1)
The size of the tables are: LINVIN - 383.692 Rows, LSUPPLIER - 115.782 Rows
As you can see the one executed from our application is much faster than the one from the helper tool. So why picks oracle a completely different explain plan for the same statement? An why is a hash join much slower than a nested loop? Because If I'm right a nested loop should only be used when the tables are pretty small..
I also tried to play with some parameters:
I set optimizer_index_caching to 100 and optimizer_index_cost_adj to 30. I also changed optimizer_mode to FIRST_ROWS_100.
I would really appreciated, if somebody can help me with this issue, because I'm really getting more and more distressed...
Thanks in advance,
Tobias
Edited by: tobiwan on Sep 3, 2008 11:49 PM
Edited by: tobiwan on Sep 3, 2008 11:50 PM
Edited by: tobiwan on Sep 4, 2008 12:01 AM
Edited by: tobiwan on Sep 4, 2008 12:02 AM
Edited by: tobiwan on Sep 4, 2008 12:04 AM
Edited by: tobiwan on Sep 4, 2008 12:06 AM
Edited by: tobiwan on Sep 4, 2008 12:06 AM
Edited by: tobiwan on Sep 4, 2008 12:07 AMtobiwan wrote:
Hi again,
Here ist the answer:
The problem, because I got two different explain plans, was that the external tool uses the NLS sesssion parameters coming from the OS which are in my case "de/DE".
Within our application these parameters are changed to "en/US"!! So if I'm calling in my external tool the java function Locale.setDefault(new Locale("en","US")) before connecting to the database the explain plans are finally equal.That might explain why you got two different execution plan, because one plan was obviously able to avoid a SORT ORDER BY operation, whereas the second plan required to run SORT ORDER BY operation, obviously because of the different NLS_SORT settings. An index by default uses the NLS_SORT = 'binary' order whereas ORDER BY obeys the NLS_SORT setting, which probably was set to 'GERMAN' in your "external tool" case. You can check the "NLS_SESSION_PARAMETERS" view to check your current NLS_SORT setting.
For more information regarding this issue, see my blog note I've written about this some time ago:
http://oracle-randolf.blogspot.com/2008/09/getting-first-rows-of-large-sorted.html
Now let me make a guess why you observe the behaviour that it takes so long if your result set is empty:
The plan avoiding the SORT ORDER BY is able to return the first rows of the result set very quickly, but could take quite a while until all rows are processed, since it requires potentially a lot of iterations of the loop until everything has been processed. Your front end probably by default only display the first n rows of the result set and therefore works fine with this execution plan.
Now if the result set is empty, depending on your data, indexes and search criteria, Oracle has to work through all the data using the inefficient NESTED LOOP approach only to find out that no data has been found, and since your application attempts to fetch the first n records, but no records will be found, it has to wait until all data has been processed.
You can try to reproduce this by deliberately fetching all records of a query that returns data and that uses the NESTED LOOP approach... It probably takes as long as in the case when no records are found.
Note that you seem to use bind variables and 10g, therefore you might be interested that due to the "bind variable peeking" functionality you might potentially end up with "unstable" plans depending on the values "peeked" when the statement is parsed.
For more information, see this comprehensive description of the issue:
http://www.pythian.com/blogs/867/stabilize-oracle-10gs-bind-peeking-behaviour-by-cutting-histograms
Note that this changes in 11g with the introduction of the "Adaptive Cursor Sharing".
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Performance problem with selecting records from BSEG and KONV
Hi,
I am having performance problem while selecting records from BSEG and KONV table. As these two tables have large amount of data , they are taking lot of time . Can anyone help me in improving the performance . Thanks in advance .
Regards,
PrashantHi,
Some steps to improve performance
SOME STEPS USED TO IMPROVE UR PERFORMANCE:
1. Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.
2. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.
3. Design your Query to Use as much index fields as possible from left to right in your WHERE statement
4. Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.
5. Avoid using nested SELECT statement SELECT within LOOPs.
6. Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.
7. Avoid using SELECT * and Select only the required fields from the table.
8. Avoid nested loops when working with large internal tables.
9. Use assign instead of into in LOOPs for table types with large work areas
10. When in doubt call transaction SE30 and use the examples and check your code
11. Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search. This is a general thumb rule but typically if you are sure that the data in internal table is less than 200 entries you need not do SORT and use BINARY SEARCH since this is an overhead in performance.
12. Use "CHECK" instead of IF/ENDIF whenever possible.
13. Use "CASE" instead of IF/ENDIF whenever possible.
14. Use "MOVE" with individual variable/field moves instead of "MOVE-
CORRESPONDING" creates more coding but is more effcient. -
Problem with Business Partner List - State
I'm using SAP B1 2007A. We recently added several International countries and their regions (states). We are having a problem with the state that appears on the Business Partner List (list that appears when you search using part of a company name or *). The query that gets the data does not take into consideration the Country where the state is located. The result is that the query returns the first state it finds based on the state code not the state associated with the country.
Is there a fix for this query or is there a way I can adjust the query to get the correct state results in the Business Partner List.
Thanks,
MarkNo. Different state name but same state code.
Ex:
GA - Georgia in USA
GA - Galapagos Islands in Galapagos Islands
When searching for the Business Partner the city is Atlanta the Country is USA but the State is Galapagos Islands not Georgia. -
Hi All,
I am Facing one problem in select query. My requirement is as follows.
User Screen will Have 4 Fileds.
Country Code, Zip Code From, Zip Code To, Delivery Area.
All are Parameter's only.
For Example ZTABLE having below Entries.
US 12345-6787 12345-6789 AKRON AKRON/CANTON
Once User try to create new entry by Click on SAVE, Below Possiblities are there.
Case 1: US 12345-6787 12345-6789 AKRON AKRON/CANTON ( Error Message)
Case 2: US 12345-6786 12345-6787 AKRON AKRON/CANTON ( Error Message)
Case 3: US 12345-6789 12345-6790 AKRON AKRON/CANTON ( Error Message)
Case 4: US 12345-6789 12345-6790 AKRON AKRON/CANTON ( Error Message)
Case 5: US 12345-6786 12345-6787 AKRON AKRON/CANTON ( Error Message)
Case 6: US 12345-6785 12345-6786 AKRON AKRON/CANTON ( Record Need To Insert)
Case 7: US 12345-6785 12345-6785 AKRON AKRON/CANTON ( Record Need To Insert)
Case 8: US 12345-6790 12345-6790 AKRON AKRON/CANTON ( Record Need To Insert)
Case 9: US 12345-6790 12345-6791 AKRON AKRON/CANTON ( Record Need To Insert)
Case 10: US 12345-6788 12345-6788 AKRON AKRON/CANTON ( Error Message)(This Condition is Failing)
Case 11: US 12345-6788 12345-6789 AKRON AKRON/CANTON ( Error Message)(This Condition is Failing)
In the above cases 10 and 11 is failing.
I am using the below select statment.
SELECT SINGLE * FROM zdt_sd_dlv_zcode WHERE mandt = sy-mandt
AND land1 = g_land1
AND ( post_code_from GE g_pbox_from AND post_code_from LE g_pbox_to )
OR ( post_code_to GE g_pbox_from AND post_code_to LE g_pbox_to ).
Friends can anyone give me some valuable inputs to solve this problem.
Points will reward.
Thanks in Advance,
Srinivas.Please use Select-options instead of Parameters so that you can use complex "and" and "or" in your select statements.
for eg:if you are declaring parameters like this below.
parameters post_code1 LIKE adrc-post_code1.
change to
select-options post_code1 for adrc-post_code1 no intervals.
siddu -
Problem with select query in search
Hi,
Here i am using MYSQL database and when i am insertind date to database it is saving like '2009-11-10 00:00:00' and when i used to dispaly this in dateformat as '11/10/2009' .
here is the problem occurs , when i write a search query as
select recruitername,interviewdate ,skillset
from details
where interviewdate = #form.interviewdate#
i am getting problem with date . would u please help me how to solve this issue .Try to use DateFormat
select recruitername,interviewdate ,skillset
from details
where interviewdate = #DateFormat(form.interviewdate, "yyyy-dd-mm")# -
Problem with Select query fetching records.
Hi All,
SELECT bukrs belnr gjahr bldat cpudt aedat cputm usnam xblnr bktxt waers
FROM bkpf INTO TABLE bkpf_tbl
WHERE bukrs IN s_bukrs AND blart IN ('RE' , 'ZL')
AND ( ( cpudt > prv_date )
OR ( cpudt = prv_date AND cputm >= prv_time ) )
OR ( ( aedat > prv_date )
OR ( aedat = prv_date AND cputm >= prv_time ) )
AND gjahr IN s_gjahr
AND monat IN s_monat
AND belnr IN s_belnr
My prv_date is 05/04/2010 while debugging.
CPUDT (Accounting Document Entry Date) in BKPF doesnu2019t have any entries.
But AEDAT (Date of the Last Document Change by Transaction) is having a single entry on date 05/04/2010.
While this query is showing number of records around 200000. I feel something is wrong with the AND/OR statements.
Please suggest some ideas?Hi Mishra,
I dont know the excaly wht u r passing in the prv_date and cpudt . But one thing i notice that blart part.
SELECT bukrs belnr gjahr bldat cpudt aedat cputm usnam xblnr bktxt waers
FROM bkpf INTO TABLE bkpf_tbl
WHERE bukrs IN s_bukrs AND blart eq 'RE' or blart eq 'ZL'
AND ( ( cpudt > prv_date )
OR ( cpudt = prv_date AND cputm >= prv_time ) )
OR ( ( aedat > prv_date )
OR ( aedat = prv_date AND cputm >= prv_time ) )
AND gjahr IN s_gjahr
AND monat IN s_monat
AND belnr IN s_belnr.
With Regards,
Sumodh.P -
Problem with select query inside a function.
Hi,
i have created a function as
create or replace function "NEW"
(emp in number,
s_date in DATE,
e_date in DATE)
return number
is
v_alo number default 0;
v_alo2 number default 0;
v_date date;
begin
select sum(allocation_percent) into v_alo from employeeproject where start_date < s_date and end_date > e_date and pid != 'BPDE-KER12' and employee_id = emp;
select allocation_percent into v_alo2 from employeeproject where start_date < s_date and end_date > e_date and pid = 'BPDE-KER12' and employee_id = emp;
select max(end_date) into v_date from employeeproject where employee_id=emp having max(end_date) <= S_DATE;
if v_alo < 100 then
return 1;
else if v_alo2 = 100 then
return 2;
else if v_date < s_date then
return 3;
else
return 4;
end if;
end if;
end if;
exception
when NO_DATA_FOUND then
return 5;
end;it is compiled correctly.
when executing the function with
select abc.a,new(a,'03-jan-2011','04-jan-2011') "status" from abc where new(a,'03-jan-2011','04-jan-2011') in (1,2,3,4);it is returning
A status
1 5
2 5
3 5
instead of
A status
1 1
2 2
3 3
and when i comment any two select statements then some part of my ans is correct.
unable to understand the behaviour.
can any pls help me understand it.
Thanks,
hariHi,
thanks for the reply, and sorry for my ugly code.
i am using Oracle database 10g express edition.
Case could be a option to use but i need to figure why my query is not returning any value when used together.
my requirement is to find
the employees who are have allocation percent sum < 100 for a defined period(excluding pid=BPDE-KER12) and
employee who is mapped to pid=BPDE-KER12 not in my first requirement in that period and
the employees whose latest end date is less than the new start date.
i have tried the new modified code as you said but this time it returns null, not even exceptions running.
i divide my requirement into three functions which will return value.
1. create or replace function "NEW4"
(emp in number,
s_date in DATE,
e_date in DATE)
return number
is
v_alo number default 0;
v_alo2 number default 0;
v_date date;
begin
--to check if the employee total percentage is <100 then return 1 else return 4
select sum(allocation_percent) into v_alo from pm_employee_project
where
start_date < s_date and end_date > e_date and pid !='BPDE-KER12' and employee_id = emp;
if v_alo < 100 then
return 1;
elsif v_alo2 = 100 then
return 2;
elsif v_date < s_date then
return 3;
else
return 4;
end if;
exception
when NO_DATA_FOUND then
return 5;
end;
then,
select abc.a,NEW4(a,'03-jan-2011','30-jan-2011') "STATUS" from abc
result,
A STATUS
1 *1*
2 4
3 4 2.create or replace function "NEW5"
(emp in number,
s_date in DATE,
e_date in DATE)
return number
is
v_alo number default 0;
v_alo2 number default 0;
v_date date;
begin
--To select employee who are in a specific pid.
select allocation_percent into v_alo2 from pm_employee_project where
start_date < s_date and end_date > e_date and pid = 'BPDE-KER12' and
employee_id = emp;
if v_alo2 = 100 then
return 2;
elsif v_alo < 100 then
return 1;
elsif v_date < s_date then
return 3;
else
return 4;
end if;
exception
when NO_DATA_FOUND then
return 5;
end;
then,
select abc.a,NEW5(a,'03-jan-2011','30-jan-2011') "STATUS" from abc
Result,
A STATUS
1 5
2 *2*
3 5 3. create or replace function "NEW6"
(emp in number,
s_date in DATE,
e_date in DATE)
return number
is
v_alo number default 0;
v_alo2 number default 0;
v_date date;
begin
--to select the employee whose project end date is less thann the new date.
select max(end_date) into v_date from pm_employee_project where
employee_id=emp having max(end_date) <= S_DATE;
if v_alo2 = 100 then
return 2;
elsif v_alo = 100 then
return 1;
elsif v_date < s_date then
return 3;
else
return 4;
end if;
exception
when NO_DATA_FOUND then
return 5;
end;
then,
select abc.a,NEW6(a,'03-jan-2011','30-jan-2011') "STATUS" from abc
Result,
A STATUS
1 5
2 5
3 *3* so my function works properly individually, but i want all the three conditions in a single function with same order as above 1 then 2 and then 3.
and when i try to do it that way i am not getting my result as
A STATUS
1 *1*
2 *2*
3 *3*
so how can i proceed.
my input table values,
select * from abc
A B C
1 2 2
2 1 3
3 1 2
select * from pm_employee_project
varchar2 varchar2 date date date varchar2
EMPLOYEE_ID PID START_DATE END_DATE ALLOCATION_PERCENT SUPERVISOR_ID
1 10 02-JAN-11 31-JAN-11 89 -
1 20 05-JAN-11 20-JAN-11 9 -
1 BPDE-KER12 21-JAN-11 31-JAN-11 11 -
2 BPDE-KER12 01-JAN-11 31-JAN-11 100 -
3 30 01-JAN-10 01-JAN-11 100 -
Problem with select max(FIELD)
I have a table with the following fields:
PARTID ART_TYP AEC SERVICE PLANT STATUS
4711 A A 2 P 230
4711 A B 0 P 230
4712 A B 2 P 230
4713 A B 0 P 230
I need a sqlscript where I get the records with MAX(SERVICE)
In this example
4711 A A 2 P 230
4712 A B 2 P 230
4713 A B 0 P 230
I tried this with:
select distinct partid,
art_typ,
aec,
max(service),
plant,
status
from t_msltmp
group by partid,art_typ,aec,plant,status
But I get both records of partid=4711
Can someone help me with this problem
kind regards
Menk SlotROW_NUMBER() requires explicit ORDER BY clause in OVER:
http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/functions105a.htm#86312
SQL> select partid, art_typ, aec, mx, plant, status
2 from(select partid,
3 art_typ,
4 aec,
5 max(service) over (partition by partid) mx,
6 row_number() over (partition by partid order by service desc) rn
7 plant,
8 status
9 from t_t)
10 where rn = 1
11 /
PARTID A A MX P STATUS
4711 A A 2 P 230
4712 A B 2 P 230
4713 A B 0 P 230Rgds.
P.S.
Another way to get this (more tedoius):
SQL> select partid,
2 max(art_typ) keep (dense_rank first order by service desc) art_typ,
3 max(aec) keep (dense_rank first order by service desc) aec,
4 max(service) service,
5 max(plant) keep (dense_rank first order by service desc) plant,
6 max(status) keep (dense_rank first order by service desc) status
7 from t_t
8 group by partid
9 /
PARTID A A SERVICE P STATUS
4711 A A 2 P 230
4712 A B 2 P 230
4713 A B 0 P 230Message was edited by:
dnikiforov
Maybe you are looking for
-
Reading trace file on the fly.
I came across one cool trick mentioned by Tanel Poder, but it doesn't seem to work for me. Could anyone please help in reading trace file on the fly. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production With the
-
Received an error during 10.4.11 Update and now can not boot
I downloaded the 10.4.11 update and tried to install it on my Macbook Pro that had 10.4.10 and there was an error during the update and it stopped. I closed the window and tried again and had the same result. Now, when I try to boot my computer, it g
-
My new backbeat GO 2 headset is not recognized by bluetooth service of my new ipad mini with ios 7.0.4! It doesńt appear in the list of bluetooth devices. It was working on previous versions! What happens? Could someone help me? Thanks!
-
I bought adobe creative suite 6 design and web premium
at the beginning of the year and i am trying to install it now, it is asking me for a 19 digit number as a redemption code, but i can not find this. HELP
-
Encypted CUCM Upgrade - HELP!!!
Hi all, i'v a question about the upgrade process for a CUCM Cluster. I Deployed a CUCM 7.1(5) with Encyption (Mixed Mode) and all works fine. Now i need to upgrade the cluster, with an hardware replace, t the last CUCM 9.1(1a) relase. I rebuild the e