Case expression error with a select query in the condition
Consider the two query below:
1. The first one use a case expression :
select case when 3 > (select 1 from dual)*2 then 1 else 0 end from dual
2. The equivalent with a decode expression:
select
decode(sign(3-(select 1 from dual)*2),1,1,0) from dual
The first query return an ORA-00905 error but not the second one. It seems that the arithmetic operation (select 1 from dual)*2 cause the error. The folowing query doesn't return this error:
select case when 3 > (select 2 from dual) then 1 else 0 end from dual
I run the test with Oracle 8.1.7.3 Enterprise Edition. Is it a known bug ?
Thomas
ora8174>select case when 3 > (select 1 from dual)*2 then 1 else 0 end from dual;
select case when 3 > (select 1 from dual)*2 then 1 else 0 end from dual
ERROR at line 1:
ORA-00905: missing keyword
ora8174>select case when 3 > cast((select 1 from dual)*2 as number) then 1 else 0 end from dual;
CASEWHEN3>CAST((SELECT1FROMDUAL)*2ASNUMBER)THEN1ELSE0END
1
1 row selected.
ora8174>select case when 3 > to_number((select 1 from dual)*2) then 1 else 0 end from dual;
CASEWHEN3>TO_NUMBER((SELECT1FROMDUAL)*2)THEN1ELSE0END
1
1 row selected.
ora8174>@connect
Connected.
ora9204>select case when 3 > (select 1 from dual)*2 then 1 else 0 end from dual;
CASEWHEN3>(SELECT1FROMDUAL)*2THEN1ELSE0END
1
1 row selected.
Similar Messages
-
What is the wrong with my select query
HI All,
TYPES: BEGIN OF t_equi,
equnr TYPE equi-equnr,
aedat TYPE equi-aedat,
matnr TYPE equi-matnr,
sernr TYPE equi-sernr,
kunde TYPE equi-kunde,
zzreg_date TYPE equi-zzreg_date,
zzin_indic TYPE equi-zzin_indic,
zzinvoice_num TYPE equi-zzinvoice_num,
zzinvoice_date TYPE equi-zzinvoice_date,
kund1 TYPE equz-kund1,
END OF t_equi,
DATA: it_equi TYPE TABLE OF t_equi,
SELECT equnr
aedat
matnr
sernr
kunde "Ship to
zzreg_date
zzin_indic
zzinvoice_num
zzinvoice_date
kund1 "Sold to
INTO TABLE it_equi
FROM equi AS a
INNER JOIN equz AS b
ON a~equnr = b~equnr
WHERE a~equnr IN s_equnr AND
* aedat GE gv_rdate AND
a~matnr IN s_matnr AND
a~sernr IN s_sernr AND
a~kunde IN r_shpbr_kunde AND
a~zzin_indic IN s_indic AND
b~datbi EQ c_datbi AND
b~kund1 IN r_sldbr_kund1 .
what is the wrong with this select query.. ?
its giving me error "The column name "EQUNR" is unclear ."
ThanksHi ,
write tablename or alias in select also
SELECT a~equnr and check.
Regards -
Performance issue after Upgrade from 4.7 to ECC 6.0 with a select query
Hi All,
There is a Performance issue after Upgrade from 4.7 to ECC 6.0 with a select query in a report painter.
This query is working fine when executed in 4.7 system where as it is running for more time in ECC6.0.
Select query is on the table COSP.
SELECT (FIELD_LIST)
INTO CORRESPONDING FIELDS OF TABLE I_COSP PACKAGE SIZE 1000
FROM COSP CLIENT SPECIFIED
WHERE GJAHR IN SELR_GJAHR
AND KSTAR IN SELR_KSTAR
AND LEDNR EQ '00'
AND OBJNR IN SELR_OBJNR
AND PERBL IN SELR_PERBL
AND VERSN IN SELR_VERSN
AND WRTTP IN SELR_WRTTP
AND MANDT IN MANDTTAB
GROUP BY (GROUP_LIST).
LOOP AT I_COSP .
COSP = I_COSP .
PERFORM PCOSP USING I_COSP-_COUNTER.
CLEAR: $RWTAB, COSP .
CLEAR CCR1S .
ENDLOOP.
ENDSELECT.
I have checked with the table indexes, they were same as in 4.7 system.
What can be the reson for the difference in execution time. How can this be reduced without adjusting the select query.
Thanks in advance for the responses.
Regards,
Dedeepya.Hi,
ohhhhh....... lots of problems in select query......this is not the way you should write it.
Some generic comments:
1. never use SELECT
endselect.
SELECT
into table
for all entries in table
where.
use perform statment after this selection.
2. Do not use into corresponding fields. use exact structure type.
3. use proper sequence of fields in the where condition so that it helps table go according to indexes.
e.g in your case
sequence should be
LEDNR
OBJNR
GJAHR
WRTTP
VERSN
KSTAR
HRKFT
VRGNG
VBUND
PARGB
BEKNZ
TWAER
PERBL
sequence should be same as defined in table.
Always keep select query as simple as possible and perform all other calculations etc. afterwords.
I hope it helps.
Regards,
Pranaya -
TIME-OUT error in BSAK select query(Progress Indicator is also used)
Hi,
In my report program one select query is there on BSAK table, which is as follows --
SELECT BUKRS
BELNR
GJAHR
SHKZG
BSCHL
UMSKZ
LIFNR
EBELN
EBELP
WRBTR
DMBTR
XZAHL
REBZG
AUGBL
BLART
AUFNR
AUGDT
BUZEI FROM BSAK
INTO TABLE IT_BSAK
FOR ALL ENTRIES IN IT_BKPF1
WHERE BUKRS = IT_BKPF1-BUKRS
AND AUGDT = IT_BKPF1-BUDAT
AND AUGBL = IT_BKPF1-BELNR
AND BSCHL IN ('31' , '29', '26', '39', '25').
I used Progress Indicator befor running this query and after this query also. But still It's giving me TIME-OUT error in this select query only.
I run the same query for 10 records in IT_BKPF1 table, it runs perfectly. But when I run it for 1000 records it giving dump.
And in actual bussiness my records are always more than 100 only.
I also check the indexing. It having secondary indexing on this BUKRS, AUGDT, AUGBL fields. Then also it's giving error.
so, How can I solve this dump..?? What could be the reason..??
Thanks in advance...!!
Regards,
Poonam.Hi Poonam Patil,
Try to provide BELNR and GJAHR in where condition...
BKPF-DBBLG ==> BSAK-BELNR
Also check
BKPF-BLDAT ==> BSAK-AUGDT
Check out above relation...
If data is there in these fields of the table and both are matching then you can pass it and as they are in primary key of BSAK it will improve the performance...
Hope it will solve your problem..
Thanks & Regards
ilesh 24x7
ilesh Nandaniya -
How an INDEX of a Table got selected when a SELECT query hits the Database
Hi All,
How an Index got selected when a SELECT query hits the Database Table.
My SELECT query is as ahown below.
SELECT ebeln ebelp matnr FROM ekpo
APPENDING TABLE i_ebeln
FOR ALL ENTRIES IN i_mara_01
WHERE werks = p_werks AND
matnr = i_mara_01-matnr AND
bstyp EQ 'F' AND
loekz IN (' ' , 'S') AND
elikz = ' ' AND
ebeln IN s_ebeln AND
pstyp IN ('0' , '3') AND
knttp = ' ' AND
ko_prctr IN r_prctr AND
retpo = ''.
The fields in the INDEX of the Table EKPO should be in the same sequence as in the WHERE clasuse?
Regards,
VijiHi,
You minimize the size of the result set by using the WHERE and HAVING clauses. To increase the efficiency of these clauses, you should formulate them to fit with the database table indexes.
Database Indexes
Indexes speed up data selection from the database. They consist of selected fields of a table, of which a copy is then made in sorted order. If you specify the index fields correctly in a condition in the WHERE or HAVING clause, the system only searches part of the index (index range scan).
The primary index is always created automatically in the R/3 System. It consists of the primary key fields of the database table. This means that for each combination of fields in the index, there is a maximum of one line in the table. This kind of index is also known as UNIQUE. If you cannot use the primary index to determine the result set because, for example, none of the primary index fields occur in the WHERE or HAVING clause, the system searches through the entire table (full table scan). For this case, you can create secondary indexes, which can restrict the number of table entries searched to form the result set.
reference : help.sap.com
thanx. -
Error: Encountered a SELECT WHEN EXPECTING the following ( + - all mod num
I have a conditional INSERT statement where I update the record if todays date is found in the table or i will INSERT a new record if that date is not found..
Insert statement that comes after ELSE works fine but IF part fails with the error
encountered a select when expecting the following
*( - + all case mod new null.. and lot more*
IF EXISTS
(SELECT (TO_CHAR(UpdateDate, 'MM/DD/YYYY')) FROM EmployeeUpdateEmails
WHERE UpdateDate = select (TO_CHAR(sysdate, 'MM/DD/YYYY')) from dual)
UPDATE EMPLOYEEUPDATEEMAILS
SET EMP_MGR_TOTAL_CHANGES = total
WHERE UpdateDate = select (TO_CHAR(sysdate, 'MM/DD/YYYY')) from dual
ELSE
This is how EmployeeUpdateEmails table is created
CREATE TABLE EmployeeUpdateEmails
UpdateNum SMALLINT PRIMARY KEY,
UpdateDate DATE,
Emp_Mgr_Total_Changes SMALLINT,
Emp_Term_Total_Chnages SMALLINT
Please HelpIF EXISTS is not aproppriate syntax:
SQL> declare
2 begin
3 if exists (select count(*) from dual)
4 then
5 dbms_output.put_line('it exists');
6 else
7 dbms_output.put_line('it doesn''t exist');
8 end if;
9 end;
10 /
if exists (select count(*) from dual)
ERROR at line 3:
ORA-06550: line 3, column 5:
PLS-00204: function or pseudo-column 'EXISTS' may be used inside a SQL statement only
ORA-06550: line 3, column 2:
PL/SQL: Statement ignored
SQL> declare
2 my_var number;
3 begin
4
5 select count(*) into my_var
6 from dual;
7
8 if my_var >= 1
9 then
10 dbms_output.put_line('it exists');
11 else
12 dbms_output.put_line('it doesn''t exist');
13 end if;
14 end;
15 /
it exists
PL/SQL procedure successfully completed.If you're using SQL then
1) post the complete statement
2) mention your database version ( the result of: select * from v$version; )
3) consider using CASE:
SQL> select case
2 when (select count(*) from dual) >= 1
3 then 'it exists'
4 else 'it doesn''t exist'
5 end
6 from dual;
CASEWHEN(SELECTC
it exists
1 row selected. -
How to write selection Query for the following requirment.
Hi All,
I am new to ABAP, I need a help ,
I need to select all plants(WERKS) from MARC at Plant/Material level,
then I need to take all sales organozation(VKORG) from T001w,
then I need the company code(BUKRS) from TVKO based on VKORG,
then I need the currency key(WAERS) from T001 based on BUKRS,
Can any one help me in writing selection Query for the same?
Thanks All,
Debrup.Hi,
Its easy for you if you learn SELECT with JOIN to complete your task. So SEARCH the forum with SELECT statement and you will get a lot of examples using which you can write your own.
If you struck up anywhere revert back.
Regards
Karthik D -
Can you pass a hidden value along with your select option in the form selec
Can you pass a hidden value along with your select option in the html form select
Off topic. Locking.
-
Error in Printer Selection while print the document
Dear All,
Error in Printer Selection, while print the document in Quotation.
Also both side Printing is not happening.
My Report is in Crystal Report format.
Suggest any solution on this as earlier as possible.
Regards,
Sumeet Vaityhi,
are you printing locally or shared printer?
pls check the ff.
1. make sure your printer is on and Online (For local and shared)
2. make sure the host PC is connected in the network., ping the host PC to make sure your host PC is Connected (Shared)
3. make it as your default printer.
regards,
Fidel -
Error erase Queries in Query Manager- The query is used with user-define...
Hello Experts
I have deleted a User Field that had a Formatted Search and now I can not remove it because it is linked according to a UF, the error message is as follows:
"The query is used with user-defined values [Message 952-23]"
There will be a way to resolve this issue???
Thanks in advanceHi Juan,
I have tried this very limited, but the formid, is this a number in your case?
SELECT * from cshs t0 inner join ouqr t1 on t0.queryid = t1.intrnalkey
where t1.qname = '[%0]'
Running this query I can get the form id that I need to recreate, but I have a feeling you already know the form id, is this correct?
- Is there an error when you try to recreate the form id?
- Will it not let you recreate the same form id because the id is given by the system?
If it is not possible to recreate the form id, please prepare a backup and log a message. Support should be able to correct the entry in table cshs.
Hope it helps.
Jesper -
Error While Firing select Query on Table
Hi aill,
we have Oracle 11g RG2 RAC on Production Machine. When I am firing select query on one partiton table,it will show me below error in Alter Log file :
Exception [type: SIGSEGV, Address not mapped to object] [ADDR:0x0] [PC:0x84056AA, kkpamDInfo()+38] [flags: 0x0, count: 1]
Errors in file /opt/app/oracle/diag/rdbms/winsdb/WINSDB2/trace/WINSDB2_ora_29686.trc (incident=288563):
ORA-07445: exception encountered: core dump [kkpamDInfo()+38] [SIGSEGV] [ADDR:0x0] [PC:0x84056AA] [Address not mapped to object] []
Incident details in: /opt/app/oracle/diag/rdbms/winsdb/WINSDB2/incident/incdir_288563/WINSDB2_ora_29686_i288563.trc
While checking the trace file :
========== FRAME [2] (ksedst1()+98 -> skdstdst()) ==========
defined by frame pointers 0x2ba371efaa40 and 0x2ba371efa990
CALL TYPE: call ERROR SIGNALED: no COMPONENT: KSE
RDI 0000000000000000 RSI 0000000000000000 RDX 00002BA371EF6118
RCX 0000000000000001 R8 0000000000000000 R9 0000000000000000
RAX 0000000000000000 RBX 0000000000000003 RBP 00002BA371EFAA40
R10 71EFA9A000000000 R11 0000000000000000 R12 0000000000000003
R13 0000000000000003 R14 0000000000000001 R15 0000000000000001
RSP 00002BA371EFA9A0 RIP 000000000349E72E
Dump of memory from 0x2ba371efaa40 to 0x2ba371efaaf0
2BA371EFAA40 71EFAB10 00002BA3 0349E77F 00000000 [...q.+....I.....]
2BA371EFAA50 00000000 00000000 00000000 00000000 [................]
2BA371EFAA60 71B996F0 00002BA3 02050034 00000000 [...q.+..4.......]
2BA371EFAA70 000000FF 00002BA3 00002004 00000000 [.....+... ......]
2BA371EFAA80 00000000 00000000 2338D058 00016DAB [........X.8#.m..]
2BA371EFAA90 00000003 00000000 085232F3 00000000 [.........2R.....]
2BA371EFAAA0 0000000D 00000000 00000002 00000000 [................]
2BA371EFAAB0 00000000 00000000 00000000 00000000 [................]
2BA371EFAAC0 71EFAAD0 00002BA3 085BBFCF 00000000 [...q.+....[.....]
2BA371EFAAD0 71EFAB10 00002BA3 0349E249 00000000 [...q.+..I.I.....]
2BA371EFAAE0 00000000 00002BA3 00000013 00000000 [.....+..........]
Can Anyone guide me for above Errors. How can I resolve the same.A quick search of Oracle Support shows that there are a handful of bugs that match ORA-07445 with an argument of kkpamDInfo()+38.
Whether yours is already identified and patched depends on the exact version of 11.2 and the specific circumstances.
If you're on 11.2.0.1 then this might be part of what sounds like quite a big bucket of such errors - Bug 9399991 relating to errors and dumps with SQL against partitioned tables. -
Issue with Select Query in the Delivery userexit USEREXIT_SAVE_DOCUMENT
Hi All,
I am facing a strang issue with delivery userexit
1) I have a delivery user exit MV50AFZ1 - USEREXIT_SAVE_DOCUMENT.
2) In this user exit. I have written a select query as shown below
*Get the already delivered data
SELECT vbeln
vgbel
vgpos
erdat
erzet
lfimg
FROM lips
INTO TABLE t_lips
FOR ALL ENTRIES IN t_xlips_reference
WHERE vgbel EQ t_xlips_reference-vgbel
AND vgpos EQ t_xlips_reference-vgpos.
IF sy-subrc EQ 0.
ENDIF.
3) The use of the above select query is to find out if there is any delivery that has already been created for the reference slaes order for which the current delivery is being created.
4) The issue here is that for the FIRST DELIVERY, this select query should fail becuase there is no delivery created earlier and LIPS table would not have data. But, I am seeing some data getting populated in the internal table. The data that I am seeing in the internal table is the data of XLIPS which is nothing but the one that is about to get saved in the database after finishing this userexit.
5) STRANGE Point is that this is working fine in case if I create delivery using the transaction VL01N. But, if I create delivery using VL10A program I am facing this issue.
<< Removed >>
Thanks,
Babu Kilari
Edited by: Rob Burbank on Jun 16, 2010 4:22 PMThen why don't you add
AND vbeln NE likp-vbeln -
How to create a Type Object with Dynamic select query columns in a Function
Hi Every One,
I'm trying to figure out how to write a piplined function that executes a dynamic select query and construct a Type Object in order to assigned it to the pipe row.
I have tried by
SELECT a.DB_QUERY INTO actual_query FROM mytable a WHERE a.country_code = 'US';
c :=DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(c,actual_query,DBMS_SQL.NATIVE);
l_status := DBMS_SQL.EXECUTE(c);
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
FOR j in 1..col_cnt LOOP
DBMS_SQL.DEFINE_COLUMN(c,j,v_val,2000);
END LOOP;
FOR j in 1..col_cnt LOOP
DBMS_SQL.COLUMN_VALUE(c,j,v_val);
END LOOP;
But got stuck, how to iterate the values and assign to a Type Object from the cursor. Can any one guide me how to do the process.
Thanks,
mallikj2Hi Justin,
First of thanks for your reply, and coming to my requirement, I need to report the list of items which are there in the dynamic select statement what am getting from the DB. The select statement number of columns may vary in my example for different countries the select item columns count is different. For US its '15', for UK it may be 10 ...like so, and some of the column value might be a combination or calculation part of other table columns (The select query contains more than one table in the from clause).
In order to execute the dynamic select statement and return the result i choose to write a function which will parse the cursor for dynamic query and then iterate the values and construct a Type Object and append it to the pipe row.
Am relatively very new for these sort of things, welcome in case of any suggestions to make it simple (Instead of the function what i thought to work with) also a sample narrating the new procedure will be appreciated.
Thanks in Advance,
mallikj2. -
Here is my code , i dont have any experience with writing the nested sql , i got the below code , which needs to be modified adding a case statement which will show util_rate for 2 conditions
1. given in where condition ( to_char(time_stamp,'HH24') >= '09' and to_char(time_stamp,'HH24') <= '19')
2.Apposite to the condition above (to_char(time_stamp,'HH24') < '09'and to_char(time_stamp,'HH24') > '19')
could anybody please help me in adding the 2nd condition to the below query , please share any documentation you have for learning how to write nested sql,
Thank you
select device,time_stamp,
sum(ActiveHRS)/sum(AvailHRS) as RATE
from
select device,time_stamp,
case when usage >0 then 1
else 0 end as ActiveHRS,
'1' as AvailHRS
from
select device,time_stamp,
sum(case
when state = 9 then 0
when state = 0 then 0
else 1 end) as usage
from A
where to_char(time_stamp,'HH24') >= '09'
and to_char(time_stamp,'HH24') <= '19'
and to_char(time_stamp, 'D') in (2,3,4,5,6)
group by device, time_stamp
group by device,time_stampHere is the DDL :
desc rumi_all
Name Null Type
RUMI_DEVICE VARCHAR2(20)
STATE NUMBER(38)
TIME_STAMP DATE
LOCATION VARCHAR2(50) Here is some sample data :
RUMI_DEVICE STATE TIME_STAMP LOCATION
10.45.28.86 0 15-JUN-10 WA-102
10.45.28.51 0 15-JUN-10 WA-102
10.45.28.63 0 15-JUN-10 WA-102
10.45.29.47 9 15-JUN-10 WA-120I used the below query to get the util for the hours 9am - 7pm
select rumi_device,time_stamp,
sum(ActiveHRS)/sum(AvailHRS) as RATE
from
select rumi_device,time_stamp,
case when usage >0 then 1
else 0 end as ActiveHRS,
'1' as AvailHRS
from
select rumi_device,time_stamp,
sum(case
when state = 9 then 0
when state = 0 then 0
else 1 end) as usage
from rumi_all
where to_char(time_stamp,'HH24') >= '09'
and to_char(time_stamp,'HH24') <= '19'
and to_char(time_stamp, 'D') in (2,3,4,5,6)
group by rumi_device, time_stamp
group by rumi_device,time_stamp
Acquired Out for the above query :
RUMI_DEVICE TIME_STAMP UTIL_RATE
10.45.29.47 15-JUN-10 0.234
10.45.28.63 15-JUN-10 0.123
10.45.29.47 15-JUN-10 0.987
10.45.29.47 16-JUN-10 0.23Desired output :I want 2 extra columns which shows util rate for the above condition i.e 9am - 7pm(core hours) and also opposite to that condition after 7pm - before 9am(say, non core hours)
Desired out put :
RUMI_DEVICE TIME_STAMP Core_Util_Rate Non_Core_UtilRate
10.45.29.4 15-JUN-10 0.234 0.003
10.45.28.63 15-JUN-10 0.123 0.001
10.45.29.47 15-JUN-10 0.987 0.023
10.45.29.47 16-JUN-10 0.23 0Hope this helps in answering my question , and also could you please share some document to learn writing nested sql's , i always had tough time in understanding this :-( -
"Invalid Expression " Error with Refreshing variable
Hi
When ever i try to validata following query in Refreshing tab of a variable, I am getting invalid expression error
select USER_NAME from SNP_SESSION where SESS_NO = <%=odiRef.getSession()%>
if i use following Query
select STEP_MESS
from <%=snpRef.getObjectName("L","SNP_STEP_LOG","D")%>
where SESS_NO = <%=snpRef.getSession("SESS_NO")%>
and STEP_STATUS = 'E'
Its giving invalid table
Need your suggestions
Thanks
BajiHi
Thanks alot for your information .But when ever i click on "Refresh" button available in refrshing tab.I am able to see following error in operator
Execution
java.sql.SQLException: ORA-00900: invalid SQL statement
Description
BeanShell script error: Sourced file: inline evaluation of: ``out.print("select USER_NAME from SNP_SESSION where SESS_NO = ") ; out.print(odiR . . . '' : Error in method invocation: Method getSession() not found in class'com.sunopsis.dwg.snpreference.b' : at Line: 2 : in file: inline evaluation of: ``out.print("select USER_NAME from SNP_SESSION where SESS_NO = ") ; out.print(odiR . . . '' : odiRef .getSession ( )
BSF info: Filter_Records at line: 0 column: columnNo
out.print("select USER_NAME from SNP_SESSION where SESS_NO = ") ;
out.print(odiRef.getSession()) ;
out.print(" \n\n\n\n\n\n") ;
****** ORIGINAL TEXT ******
select USER_NAME from SNP_SESSION where SESS_NO = <%=odiRef.getSession()%>
Thanks
Baji
Maybe you are looking for
-
I keep getting this error when I try to transform an xml file into html. org.apache.jasper.JasperException: Unable to open taglibrary http://jakarta.apache.org/taglibs/xsl-1.0 : null Here is the jsp file <%@taglib uri="http://jakarta.apache.org/tagli
-
BizTalk using a SQL failover cluster in IAAS?
The "BizTalk Offerings: Server, IaaS, and PaaS Feature List" (see http://social.technet.microsoft.com/wiki/contents/articles/19743.biztalk-offerings-server-iaas-and-paas-feature-list.aspx) say that when running BizTalk as IAAS in Azure, No Failover C
-
How to Create Rule in Interface Data Transformer.
Hi, If any one know how to Create Rule in Interface Data Transformer(IDT) Super user by using Lookup(Oracle R12 Version) Please help me on this. I have one value in GL Interface table, while loding data into base tables (GL_JE_BATCHES, GL_JE_HEADERS,
-
Installing Acrobat 8 in Windows 7
Attempting to install Acrobat 8 fr dnloaded files to Windows 7 but keep getting error - "A problem occured while extracting some files. Please check available space on your computer and the write priveleges on the desitnation folder." Attempted to ad
-
Error creating sales order in VA01
Hi Experts, While creating order in VA01, im getting error 'Define deadline category during maintenance of billing plan type'. Message V2404. Can anybody suggest, why it is coming? Thanx, RR