Problem in excuting select statement
Hi,
I have created simple report and in start-of-selection i have writen select statement with bukrs and lifnr as parameters. But i am unable to execute the query.
find the code
start-of-selection.
select bukrs
lifnr
name1
name2
name3
from zapv_names
into table it_zapv
where bukrs = p_bukrs
and lifnr = p_lifnr.
I am not under stand why it is not working. The code is correct. I have taken names as zname field and others are standered data elements.
Thanks,
RamuV
I'm going to take a wild guess that since you show this to be the first statement
after the START-OF-SELECTION line, that is is coming from a report program
where the two field you are testing for are actually RANGEs on the selection screen.
select bukrs
lifnr
name1
name2
name3
from zapv_names
into table it_zapv
where bukrs = p_bukrs " This is likely a RANGE
and lifnr = p_lifnr. " This is likely a RANGE
Change them to this
select bukrs
lifnr
name1
name2
name3
from zapv_names
into table it_zapv
where bukrs IN p_bukrs " This is likely a RANGE
and lifnr IN p_lifnr. " This is likely a RANGE
Ranges would be tables and have value like 'IEQ0101' where with the = sign would never be equal.
Edited by: Paul Chapman on Jan 12, 2009 12:23 PM
Similar Messages
-
Problem in jdbc select statement
{{ public List dis(int getmodified,int getindex){
List outerList=null;
outerList=new ArrayList();
List display=null;
try{
System.out.println("testing.....3");
con=getconnection();
pstmt= con.prepareStatement("SELECT title from newss where nno >(10*(?)) and nno <=(10*?)");
pstmt.setInt(1,getmodified);
pstmt.setInt(2,getindex);
System.out.println("testing.....2");
//pstmt.setInt(1,pgno);
rs=pstmt.executeQuery();
while(rs.next())
display=new ArrayList();
display.add(rs.getString(1));
System.out.println("###########################" +rs.getString(1));
System.out.println("(((((((((((())))))))))" +display);
outerList.add(display);
}catch(Exception e){
System.out.println ("exception in select statement" +e.getMessage());
System.out.println("*************" +outerList);
return outerList;
my problem is it says exception in select statement and no data found
can someone resolve my problem}Check the below code snippet this what my fellow poster meant.check whether the proposed works well or not.
public List dis(int getmodified,int getindex){
List outerList = new ArrayList();
List display=null;
try{
System.out.println("testing.....3");
con = getconnection();
pstmt = con.prepareStatement("SELECT title from newss where nno > ? and nno <= ?");
pstmt.setInt(1,10*getmodified);
pstmt.setInt(2,10*getindex);
System.out.println("testing.....2");
rs = pstmt.executeQuery();
while(rs.next()){
display=new ArrayList();
String title = rs.getString(1);
display.add(title);
System.out.println("###########################" +title);
System.out.println("(((((((((((())))))))))" +display);
outerList.add(display);
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs != null){
try{rs.close();}catch(Exception e){e.printStackTrace();}
if(pstmt != null){
try{pstmt.close();}catch(Exception e){e.printStackTrace();}
if(con != null){
try{con.close();}catch(Exception e){e.printStackTrace();}
con = null;
pstmt = null;
rs = null;
return outerList;
REGARDS,
RaHuL -
Problem in the select statement
I have to select the values of the fields BEZEI depending on tha sales order number vbeln. HOw can i write the select statement what will be the tables associated?
Hi,
tables: vbak.
types: begin of ty_vbak,
vbeln type vbeln,
kokrs type kokrs,
end of ty_vbak,
begin of ty_it_tka01,
kokrs type kokrs,
bezei type bezei,
end of ty_tka01.
data: it_vbak type table of ty_vbak,
wa_vbak type ty_vbak,
it_tka01 type table of ty_tka01,
wa_tka01 type ty_tka01.
Select-options: s_vbeln for vbak-vbeln.
Select VBELN KOKRS from VBAK into table it_VBAK where vbeln in s_vbeln.
if sy-subrc = 0.
select KOKRS BEZEI from TKA01 into it_tka01 for all entries in it_vbak where kokrs = it_vbak-kokrs.
endif.
Loop at it_vbak into wa_vbak.
read table it_tka01 into wa_tka01 with key kokrs = wa_vbak-kokrs.
if sy-subrc = 0.
* Move data to final internal table.
endif.
endloop.
Regards,
Satish -
Performance problem of asset selection statement.
Hi guys quick question.
SELECT a~bukrs
a~anln1
b~anln2
a~anlkl
a~aktiv
a~txt50
a~lvtnr
b~afabe
b~afabg
b~ndjar
b~ndper
INTO TABLE it_anla
FROM anla AS a
INNER JOIN anlb AS b
ON a~bukrs EQ b~bukrs
AND a~anln1 EQ b~anln1
WHERE a~bukrs IN s_bukrs
AND a~anln1 IN s_anln1
AND a~anln2 EQ '0000'
AND a~anlkl IN s_anlkl
AND a~aktiv EQ '00000000'
AND a~lvtnr IN s_lvtnr
AND b~afabe EQ 01.
I have a select statement which is filtered by capitalization date which is the field AKTIV. This select alone has 450 thousand hits. Having an ANLN2 = 0 and AKTIV = blank/no date means that the asset group is no longer active.
Now for another scenario I have to retrieve table ANLA again excluding all the Main Asset Number/ANLN1 found on that table.
Is there a way to select by doing it only once?
I tried to pass all the anln1 to a range table but the program dumps. I think the range table can't handle too many entries.
Retrieving all the entries from the DB then processing it takes longer.
I tried to delete the table using a loop but it takes to long as it process the table every loop.
LOOP AT it_anla WHERE anln2 EQ '0000' AND aktiv EQ '0000000'.
DELETE it_anla WHERE bukrs EQ it_anla-bukrs AND anln1 EQ it_anla-anln1.
ENDLOOP.
Thanks.
Edited by: Thomas Zloch on Sep 21, 2010 5:39 PM - please use code tagsModerator message - Welcome to SCN
If the range table for anln1 is large and contains distinct values, you can try using it in a FOR ALL ENTRIES construct rather than IN.
Rob -
Problem with my select statement
Dear buddies,
Really seeking someone to guide me in this sql issue.
Here is the scenario.
- should check for the number of prospects(to be customers) downloaded from a file for every dealer based on the
region
description about columns shown
1st column, region
2nd column, dealer code
3rd column, number of prospect received
4th column, the percentage of conversion
5th column, i must order by the 4th column and select the top 20 percentage and take its average.
sample data
region dealer_code no. of no of % of % of Comparing with
prospect prospect prospect Top 20 top 20 conversion
received converted conversion Conversion
A dealer 1 150 50 33% 56% Red
dealer 2 100 40 40% 56% Red
dealer 3 120 60 50% 56% Red
130 70 54% 56% Red
200 20 10% 56% Red
B 140 60 43% 56% Red
110 60 55% 56% Red
100 60 60% 56% Green
130 69 53% 56% Red
140 75 54% 56% Red
D 110 40 36% 56% Red
100 30 30% 56% Red
140 74 53% 56% Red
100 70 70% 56% Green
110 65 59% 56% Green
E 130 85 65% 56% Green
150 65 43% 56% Red
150 70 47% 56% Red
160 95 59% 56% Green
170 100 59% 56% Green
F 200 150 75% 56% Green
100 65 65% 56% Green
120 40 33% 56% Red
140 80 57% 56% Green
150 85 57% 56% Green
Legend (for the sample data)
when % of prospect conversion > % of top 20 conversion, then green
when % of prospect conversion = % of top 20 conversion, then yellow
when % of prospect conversion < % of top 20 conversion, then red
NOTE
i have a few more columns after this, but if i know how to fix these columns, i can manage them too.
here is my sql
select a.dealer_region,
a.dealer_code,
count(b.id) as "No of Prospect Received",
COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code)
then b.id end) "No of Prospect Converted to Booking",
(COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code)
then b.id end)
/ (count(b.id))*100 || '%')"%of Prospect Conversion" ,
((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code
and rownum <20)
then b.id end)
/20 )* 100 || '%')"% Top 20 Conversion",
/*(avg((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code)
then b.id end)
/ (count(b.id))*100 || '%'))
(case when((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code
and rownum <20)
then b.id end)
/ 20 )* 100) > ((count(case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code
and rownum <20)
then b.id end)
/ 20 )* 100)
then 'Green'
when((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code
and rownum <20)
then b.id end)
/ 20 )* 100) = ((count(case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code
and rownum <5)
then b.id end)
/ 20 )* 100)
then 'Yellow'
else
'Red'
end) "Comparison with Top 20 Convers",
/* i can handle this part if the sql given above is solved */
COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code)
then b.id end) "#of Lead ConvertedC",
(COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code)
then b.id end)
/ (count(b.id))*100 || '%')"%of Lead ConversionC",
((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code
and rownum <21)
then b.id end)
/ 20 )* 100 || '%')"% Top 20 ConversionC",
/* (avg((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='04'
and d.dealer_code = c.dealer_code)
then b.id end)
/ (count(b.id))*100 || '%'))
(case when((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code
and rownum <21)
then b.id end)
/ 20 )* 100) > ((count(case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code
and rownum <21)
then b.id end)
/ 20 )* 100)
then 'Green'
when((COUNT (case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code
and rownum <21)
then b.id end)
/ 20 )* 100) = ((count(case when b.id in (select d.id
from contact_details d
where d.contact_result ='05'
and d.dealer_code = c.dealer_code
and rownum <21)
then b.id end)
/ 20 )* 100)
then 'Yellow'
else
'Red'
end) "Comparison with Top 20 ConverC"
from dealers a, prospect_list b, files c, marketing_details e, customer f
where b.file_id = c.file_uid
and c.dealer_code = a.dealer_code
and b.id = e.id
and e.id = f.id
group by a.dealer_region, a.dealer_code; hope someone can help me out.
i actually can change the count(d.dealer_code) to 20 and solve the problem but what if they are less than 20 dealers in the table?
because the table will be refreshed every morning with new data and the unnecessary one will be removed.
it works fine now when i divide it by 20.
pls advice
thanks
alagu
Edited by: user645399 on Jul 1, 2009 7:49 PM
Edited by: user645399 on Jul 1, 2009 7:56 PM
Edited by: user645399 on Jul 1, 2009 8:14 PM
Edited by: user645399 on Jul 1, 2009 10:20 PMHope this helps. First rank all the rows. Then find the average for the top3 using CASE statement
LPALANI@l11gr2>select ename, sal, dense_rank() over (order by sal desc) dr,
2 avg(sal) over() avg_sal_all
3 from scott.emp;
ENAME SAL DR AVG_SAL_ALL
KING 5,000 1 2,073
FORD 3,000 2 2,073
SCOTT 3,000 2 2,073
JONES 2,975 3 2,073
BLAKE 2,850 4 2,073
CLARK 2,450 5 2,073
ALLEN 1,600 6 2,073
TURNER 1,500 7 2,073
MILLER 1,300 8 2,073
WARD 1,250 9 2,073
MARTIN 1,250 9 2,073
ADAMS 1,100 10 2,073
JAMES 950 11 2,073
SMITH 800 12 2,073
14 rows selected.
LPALANI@l11gr2>
LPALANI@l11gr2>select ename, sal,
2 avg(case when dr <=3 then sal end) over () avg_sal_top,
3 count(case when dr <=3 then 1 end) over() cnt_of_top3_earners,
4 avg_sal_all,
5 dr
6 from (select ename, sal, dense_rank() over (order by sal desc) dr, avg(sal) over() avg_sal_all from scott.emp);
ENAME SAL AVG_SAL_TOP CNT_OF_TOP3_EARNERS AVG_SAL_ALL DR
KING 5,000 3,494 4 2,073 1
FORD 3,000 3,494 4 2,073 2
SCOTT 3,000 3,494 4 2,073 2
JONES 2,975 3,494 4 2,073 3
BLAKE 2,850 3,494 4 2,073 4
CLARK 2,450 3,494 4 2,073 5
ALLEN 1,600 3,494 4 2,073 6
TURNER 1,500 3,494 4 2,073 7
MILLER 1,300 3,494 4 2,073 8
WARD 1,250 3,494 4 2,073 9
MARTIN 1,250 3,494 4 2,073 9
ADAMS 1,100 3,494 4 2,073 10
JAMES 950 3,494 4 2,073 11
SMITH 800 3,494 4 2,073 12 -
Problem in executing select statement using hetrogenous services
I am trying to import data from SqlServer 2005 to oracle 10g using hetrogenous services.
Oracle is installed on solaris 10 platform. I am running my query by Windows platform using Pl/Sql Developer
when i run the following query,
select * from GSecMstr@demodata2;
i get the following error message
Error: ORA-04052: error occurred when looking up remote object [email protected]
ORA-00604: error occurred at recursive SQL level 1
ORA-07268: szguns: getpwuid error.
But strange thing is that when i logon to the solaris server machine with user oracle and execute the same command using sqlplus from solaris console, then command is executed successfullyServer side tnsnames.ora file
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = solaris.ssilhr.com.pk)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
SQLServer =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = tcp)(HOST = solaris.ssilhr.com.pk)(PORT = 1522))
(CONNECT_DATA =
(SID = SQLServer)
(HS = OK)
Server side sqlnet.ora file
SQLNET.AUTHENTICATION_SERVICES= (NONE)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
Client side tnsnames.ora file
# tnsnames.ora Network Configuration File: E:\Oracle\product\10.2.0\db_2\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
ORCL_SUN =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.235)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = orcl)
Client side sqlnet.ora file
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
Another thing i want to mention is that by mistake, i changed the role of user oracle from dba to root, which i have changed back to dba now.
To create database link, i used the following SQL
create public database link DEMODATA2
connect to "username"
IDENTIFIED BY "MyPassword"
using 'SQLServer'; -
Hi Experts,
I am facing the problem in the select statement where it giving the short dump
DBIF_RSQL_INVALID_RSQL CX_SY_OPEN_S.
i have searched many forms, but i found that the select option s_matnr have the limitaion 2000 entreis, but i am passing same s_matnr to other select statement with more than 2000 entries but it is not giving me any short dump.
but i am facing problem with only one select statement where if i pass select option s_matnr more than 1500 entris also giving short dump.
my select statement is
SELECT * FROM bsim
INTO CORRESPONDING FIELDS OF TABLE g_t_bsim_lean
FOR ALL ENTRIES IN t_bwkey WHERE bwkey = t_bwkey-bwkey
AND matnr IN matnr
AND bwtar IN bwtar
AND budat >= datum-low.
in the internal table g_t_bsim_lean internal table contain all the fields of the table bsim with 2 fields from other table.
Please let me know whether i need to change the select statement or any other solution for this.
Regards,
udupimy select query is like this:
DATA: BEGIN OF t_bwkey OCCURS 0, "184465
bwkey LIKE bsim-bwkey, "184465
END OF t_bwkey. "184465
LOOP AT g_t_organ WHERE keytype = c_bwkey.
MOVE g_t_organ-bwkey TO t_bwkey-bwkey.
COLLECT t_bwkey. "184465
ENDLOOP. "184465
READ TABLE t_bwkey INDEX 1. "184465
CHECK sy-subrc = 0. "184465
SELECT * FROM bsim "n443935
INTO CORRESPONDING FIELDS OF TABLE g_t_bsim_lean "n443935
FOR ALL ENTRIES IN t_bwkey WHERE bwkey = t_bwkey-bwkey
AND matnr IN matnr
AND bwtar IN bwtar
AND budat >= datum-low. -
Select statement for generic select options
Hello,
I have a problem implementing a SELECT-Statement. I have a generic number of select options on my selection screen and I have a range table for each select option. How can a generate a database select for these generic number of range tables?
Thank you very much in advance & regards,
Alexanderthe answer I gave you will work if you have a ranges table for every possible select-options and refer to every ranges table in your where clause.... that way, you don't have to know which are populated and which are not at the time of SELECT.
You could also choose to create a dynamic where clause, based upon what you had select-options for and use with
WHERE ( whereclause ).
Edited by: BreakPoint on Mar 2, 2011 4:31 PM -
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 -
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 -
Performance problem(ANEA/ANEP table) in Select statement
Hi
I am using below select statement to fetch data.
Does the below where statement have performance issue?
can you Pls suggest.
1)In select of ANEP table, i am not using all the Key field in where condition. will it have performance problem?
2)does the order of where condition should be same as in table, if any one field order change also will have effect performance
SELECT bukrs
anln1
anln2
afabe
gjahr
peraf
lnran
bzdat
bwasl
belnr
buzei
anbtr
lnsan
FROM anep
INTO TABLE o_anep
FOR ALL ENTRIES IN i_anla
WHERE bukrs = i_anla-bukrs
AND anln1 = i_anla-anln1
AND anln2 = i_anla-anln2
AND afabe IN s_afabe
AND bzdat =< p_date
AND bwasl IN s_bwasl.
SELECT bukrs
anln1
anln2
gjahr
lnran
afabe
aufwv
nafal
safal
aafal
erlbt
aufwl
nafav
aafav
invzv
invzl
FROM anea
INTO TABLE o_anea
FOR ALL ENTRIES IN o_anep
WHERE bukrs = o_anep-bukrs
AND anln1 = o_anep-anln1
AND anln2 = o_anep-anln2
AND gjahr = o_anep-gjahr
AND lnran = o_anep-lnran
AND afabe = o_anep-afabe.
Moderator message: Please Read before Posting in the Performance and Tuning Forum
Edited by: Thomas Zloch on Aug 9, 2011 9:37 AM1. Yes. If you have only a few primary keys in youe WHERE condition that does affect the performance. But some times requirement itself may be in that way. We may not be knowing all the primary keys to given them in WHER conditon. If you know the values, then provide them without fail.
2. Yes. It's better to always follow the sequence in WHERE condition and even in the fields being fetched.
One important point is, whenever you use FOR ALL ENTRIES IN, please make sure that the itab IS NOT INITIAL i.e. the itab must have been filled in. So, place the same conditin before both the SELECT queries like:
IF i_anla[] IS NOT INITIAL.
SELECT bukrs
anln1
anln2
afabe
gjahr
peraf
lnran
bzdat
bwasl
belnr
buzei
anbtr
lnsan
FROM anep
INTO TABLE o_anep
FOR ALL ENTRIES IN i_anla
WHERE bukrs = i_anla-bukrs
AND anln1 = i_anla-anln1
AND anln2 = i_anla-anln2
AND afabe IN s_afabe
AND bzdat =< p_date
AND bwasl IN s_bwasl.
ENDIF.
IF o_anep[] IS NOT INITIAL.
SELECT bukrs
anln1
anln2
gjahr
lnran
afabe
aufwv
nafal
safal
aafal
erlbt
aufwl
nafav
aafav
invzv
invzl
FROM anea
INTO TABLE o_anea
FOR ALL ENTRIES IN o_anep
WHERE bukrs = o_anep-bukrs
AND anln1 = o_anep-anln1
AND anln2 = o_anep-anln2
AND gjahr = o_anep-gjahr
AND lnran = o_anep-lnran
AND afabe = o_anep-afabe.
ENDIF. -
Problem - Creating a Dynamic LOV using duplicate value in select statement
I am trying to create a Dynamic LOV by attempting to follow a pattern similar to the following:
select shop_name d, shop_id r
from shops
order by 1
However, I want to use the shop_name twice as in the following because I do not have any other unique identifier available such as a shop_id to associate with the shop name:
select shop_name d, shop_name r
from shops
order by 1
But I get an error where I am not allowed to duplicate the shop_name in the select statement. I read somewhere on this forum where it can be done but I can't find exactly how.
Can someone tell or show me how to accomplish this?
Thanks in anticipation for your answer.
Thanks,
RicRic,
I just tried to do this on APEX 3.0, and it worked just fine with this SQL:
select ename d, ename r from emp order by 1Perhaps you could put an example on apex.oracle.com or specify the error message that you're getting.
So as long as you have uniquely aliased both columns, this should not present a problem.
Thanks,
- Scott - -
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 -
Problem in Matrix Like Select Statement.
Hi All,
I have table like this
Name Null? Type
ROLL NUMBER
DD DATE
ATT VARCHAR2(2)
Along with the data--
SELECT * FROM ATT;
ROLL DD AT
2 02-FEB P
2 01-FEB P
2 03-FEB P
2 04-FEB P
2 05-FEB P
2 06-FEB P
2 07-FEB A
2 09-FEB A
1 01-FEB A
1 02-FEB P
1 03-FEB A
1 04-FEB A
1 05-FEB P
1 06-FEB P
1 07-FEB P
1 09-FEB P
I want to write the select statement which fetch the data in matrix like I shown below.
ROLL 01-FEB = 02-FEB = 03-FEB = 04-FEB
1 A P A A
2 P P P P
I tried with sub-queries but not working Any Help...
SKMsorry i did not look at the problem complete.
the first solution works with the number of values in the date columns are known.
then you can hardcode them , but when the values are unknown you should use something like this.
i have given my example, you just change the queries in the code accordingly and it works great. Thanks to Thomas Kyte who provided this example, i took it and modified for my own.
CREATE TABLE TABL_RESULTDATA
Loadpoints VARCHAR2(125)
, LoadPointSteps VARCHAR2(125)
, Variable VARCHAR2(125)
, Step NUMBER
, Value NUMBER
, VariableType VARCHAR2(20)
, ReadBackValue NUMBER
insert into tabl_resultdata values('HA_000_LP_000','S_001', 'AD1Out(ADcard_1)',1,5, 'SET', 10)
insert into tabl_resultdata values('HA_000_LP_000','S_001','N',1,100,'SET', 10)
insert into tabl_resultdata values('HA_000_LP_000','S_001','Load(DDE)',1,1,'SET', null)
insert into tabl_resultdata values('HA_000_LP_000','S_002','Q_quer(Emi2)',1,9.5,'MEAS', null)
insert into tabl_resultdata values('HA_000_LP_000','S_002','T_I(Emi2)',1,0,'MEAS', null)
insert into tabl_resultdata values('HA_000_LP_000','S_002','AD1Out(ADcard_1)',1,0,'SET', null)
insert into tabl_resultdata values('HA_000_LP_000','S_002','N',1,100,'SET', null)
insert into tabl_resultdata values('HA_000_LP_000','S_002','Load(DDE)',1,1,'SET', null)
insert into tabl_resultdata values('HA_000_LP_001','S_001','Q_Ueber(KMM)',1,49.83,'MEAS', null)
insert into tabl_resultdata values('HA_000_LP_001','S_001','T_Volkor(KMM)',1,0,'MEAS', null)
insert into tabl_resultdata values('HA_000_LP_001','S_001','C1(LeCroy)',1,0,'MEAS', null)
insert into tabl_resultdata values('HA_000_LPSCHL_000','S_001','AD1Out(ADcard_1)',1,10,'SET', null)
insert into tabl_resultdata values('HA_000_LPSCHL_000','S_001','AD1Out(ADcard_1)',2,12,'SET', 17)
insert into tabl_resultdata values('HA_000_LPSCHL_000','S_001','AD1Out(ADcard_1)',3,12,'SET', 19)
insert into tabl_resultdata values('HA_000_LPSCHL_000','S_001','AD1(ADcard_1)',1,9.025,'MEAS', null)
insert into tabl_resultdata values('HA_000_LPSCHL_000','S_001','AD1(ADcard_1)',2,9.05,'MEAS', null)
create or replace package pivot
as
type rc is ref cursor;
procedure data(p_cursor in out rc);
end;
create or replace package body pivot
as
procedure data( p_cursor in out rc )
is
l_stmt long;
l_index number := 0;
begin
l_stmt := 'select loadpoints, loadpointsteps ,step ';
for x in ( select distinct variable, variabletype from tabl_resultdata order by 2 )
loop
l_index := l_index + 1;
l_stmt := l_stmt ||', max(decode(variable,' || ''''|| x.variable||''''||', value )) ' ||replace(replace(x.variable||'('||x.variabletype||')', '('), ')');
end loop;
l_stmt := l_stmt || ' from tabl_Resultdata group by loadpoints,loadpointsteps, step order by loadpoints';
open p_cursor for l_stmt;
end;
end;
set linesize 198
column loadpoints format a17
column loadpointsteps format a5
column step format 999
column value_1 format 999.999
column value_2 format 999.999
column value_3 format 999.999
column value_4 format 999.999
column value_5 format 999.999
column value_6 format 999.999
column value_7 format 999.999
column value_8 format 999.999
column value_9 format 999.999
variable x refcursor
set autoprint on
exec pivot.data( :x ); -
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.
Maybe you are looking for
-
Looking for a particular offset
Hello all, I have been forced to deal with a binary file in java that is 100MB+ made of 64 byte records. What I have done is to build a pointers hashtable to point out the various records in the file but what I want is to skip to that offset. I looke
-
Shared Variable Engine Buffering Enable/Disable
Hello - I am running into a problem where I am seeing a read of data that seems to be lagging the writing of the data. The reading and writing functions are utilizing the same shared variable - a control to write to it and an indictor to display it s
-
Hi, I have a little problem with the bapi's BAPI_PRODORDCONF_CREATE_TT and BAPI_PRODORDCONF_GET_TT_PROP 1. in abap i call BAPI_PRODORDCONF_GET_TT_PROP first , the proposed goodsmovement is not the same as the default on co11n, it does not includ
-
Constructor and Class constructor
Hi all Can any one explain me the functionality about Constructor and class constructor?? As well as normal methods, which you call using CALL METHOD, there are two special methods called CONSTRUCTOR and CLASS_CONSTRUCTOR, which are automatically cal
-
Where is it referencing its music from?
Hi Anyone know where IDVD 6.4 is referencing music for its themes from? I want to use a piece in another program. the only link I can see to the music is where it says "edit drop zones" there is a music icon there but I cant seem to find any more inf