Help in to convert sql from CASE to DECODE in 11g
11gr2, Windows.
Can somebody help me out in re-writing below sql from CASE statement to DECODE ?
SELECT INVOICE_ID,sum(TOTAL_EXCL_VAT),LEVEL2 as descr,
sum(case when instr(LEVEL2,'Internet')>0 then SUM_QUANTITY else 0 end) as KB --- >> Here
from rator_cdr.INVOICE_DETAIL_LINE
WHERE INVOICE_ID ='000000000000000000' and CALLER='0000000000' and LEVEL1='Gesprekskosten'
group by LEVEL2,INVOICE_ID;Thanks
There is no difference in performance. CASE is a standard syntax that is relatively easy for any developer to read and follow. DECODE is an Oracle-specific function that is much less flexible (you can only use equality conditions, for example) and generally results in more cryptic code.
Justin
Similar Messages
-
Help on converting query with case into decode
Hi Can anyone help me to revise my plsql query? Below is a portion og the procedure I am changing to meet Oracle 8i.
SELECT SUM(NVL(CASE WHEN (weeks='wk1' ) THEN qty END, 0)) wk1,
SUM(NVL(CASE WHEN (weeks='wk2' ) THEN qty END, 0)) wk2,
SUM(NVL(CASE WHEN (weeks='wk3' ) THEN qty END, 0)) wk3,
SUM(NVL(CASE WHEN (weeks='wk4' ) THEN qty END, 0)) wk4
FROM TABLE1
Thanks in advance.pls try this....(code not tested as no create table etc provided).
select dt
from (select decode(is_tbd,
'yes',
decode(is_tbd_order,
'no',
'tbd',
decode(sign(ex_fac_date - (v_asofdate + 131)),
1,
'tbd',
null),
decode(sign(ex_fac_date - (v_asofdate + 131)),
1,
'tbd',
null)),
null) dt
from dual
union all
select decode(sign(ex_fac_date - (v_asofdate - 1)),
1,
decode(sign(ex_fac_date - (v_asofdate + 5)),
0,
decode(is_tbd, 'no', 'wk1', null),
null),
null)
from dual
union all
select decode(sign(ex_fac_date - (v_asofdate + 6)),
1,
decode(sign(ex_fac_date - (v_asofdate + 12)),
0,
decode(is_tbd, 'no', 'wk2', null),
null),
null)
from dual
select decode(sign(ex_fac_date - (v_asofdate + 13)),
1,
decode(sign(ex_fac_date - (v_asofdate + 19)),
0,
decode(is_tbd, 'no', 'wk3', null),
null),
null)
from dual
union all
select decode(sign(ex_fac_date - (v_asofdate - 1)),
0,
decode(is_tbd, 'no', 'past_due', null),
null)
from dual
where dt is not null
Regards -
Help needed in converting Excel from XML file
Hi Can anyone help me in converting XML in to Excel.
Thanx,
Ananth.well, that still isn't much to go off of. I give it a try though.
I guess you want to parse out the relevent data out of the xml file and then decide on your favorite delimated file format for Excel. Two popular formats are comma delimated:
"info1","info2","info3","info4"
and tab delimeted:
info <tab> info2 <tab> info3 <tab> info4
Excel should be able to unsestand either of these formats. -
Please help to build an sql from the given expression to build case condition with Where clause
if @rollno is not null then
Select top 1 studentid from student where rollno =:@rollno
else
if @regno is not null then
Select top 1 studentid from student where regno =:@regno
Please help me to create the above condition as a single sql statement . I will pass two argument in to the sql.
With Thanks
Pol
polachanSelect top 1 studentid from student
where (rollno =:@rollno or :@rollno is null)
and (regno =:@regno or :@regno is null)
The above expression will work in SQL server
I'm not sure you're using sql server as syntax like :@regno are not t-sql valid
so you can try the above and if it doesnt work please try in the relevant forums for more help in case you're using a different RDBMS
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
Help Required in Converting datatype from Microsoft SQL To Oracle
I Have one Table in Microsoft SQL,
Create Table sk_a(number(1000,1));
Now I want to create the same table with similar column in Oracle,
but Oracle datatype precision is only max 38, so please let me know the best way to do it,
Thanks,
Sunil . NYou want a 1000 numbers as precision? Wow.... huge numbers...
How would you call a number like that?
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111.1 -
Converting SQL from MSSQL to Oracle
Hi,
I have the following sql written in TSQL. I wanted to convert it into SQL so that i can use it in oracle.
select distinct DT_APPROVAL_GRP,dbo.MagicToDbBoolean(DT_MUST_BE_APPVD) as DT_MUST_BE_APPVD,DT_REVIEW_INTERVAL,DT_REVIEW_UNIT,
case DT_APPROVAL_GRP
when ' ' then '[NoGroup]'
else DT_APPROVAL_GRP
END + '['+cast(dbo.MagicToDbBoolean(DT_MUST_BE_APPVD) as varchar) + ']' +'[' cast( DT_REVIEW_INTERVAL as varchar) ']' +'[' + cast(DT_REVIEW_UNIT as varchar)+']' as ReviewModelCode from dt_document_Type, ag_approval_group WHERE (AG_NAME = DT_APPROVAL_GRP or DT_APPROVAL_GRP=' ' );
Thanks in advance.
MuneerHello
Case is more flexible than decode as you have more comparison operators at your disposal and you can combine multiple conditions in a single test, although for numbers and dates you can use decode with SIGN(arithmetic expression). You can nest decodes(as with case), but they can sometimes be difficult to understand if they're not formatted properly.
I have been told that decode is faster than case, but I haven't personally benchmarked it, so it could well be one of the many myths.
HTH -
Help in my pl/sql from blob to a file
i found the code here: http://www.oracle-base.com/articles/9i/ExportBlob9i.php but somehow i was confused by errors:
CREATE OR REPLACE
procedure sp_readBlob
declare
l_file UTL_FILE.FILE_TYPE;
l_buffer RAW(32767);
l_amount BINARY_INTEGER := 32767;
l_pos INTEGER := 1;
l_blob BLOB;
l_blob_len INTEGER;
BEGIN
-- Get LOB locator
SELECT fileupload
INTO l_blob
FROM rsmaster
WHERE rownum = 1;
l_blob_len := DBMS_LOB.getlength(l_blob);
-- Open the destination file.
l_file := UTL_FILE.fopen('BLOBS','MyImage.gif','w', 32767);
-- Read chunks of the BLOB and write them to the file
-- until complete.
WHILE l_pos < l_blob_len LOOP
DBMS_LOB.read(l_blob, l_amount, l_pos, l_buffer);
UTL_FILE.put_raw(l_file, l_buffer, TRUE);
l_pos := l_pos + l_amount;
END LOOP;
-- Close the file.
UTL_FILE.fclose(l_file);
EXCEPTION
WHEN OTHERS THEN
-- Close the file if something goes wrong.
IF UTL_FILE.is_open(l_file) THEN
UTL_FILE.fclose(l_file);
END IF;
RAISE;
END;
Error(2,1): PLS-00103: Encountered the symbol "DECLARE" when expecting one of the following: ( ; is with authid as cluster compress order using compiled wrapped external deterministic parallel_enable pipelined
Error(40): PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following: begin case declare end exception exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable> << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe
thanks in advance!You haven't used the quoted code very well!
That is an 'anonymous pl/sql block and uses the explicit DECLARE to define the area for declarations.
You are using a named pl/sql procedure and do not require the explicit DECLARE.
I think you must have miss-read the 'Create or replace Directory' line above. -
Change in SQL from case sensitive to case insensitive
Hi Experts
We have to change the collation setting for one of my clients databases (SAP doc at the time was erroneous) I am wondering if I can change at the same time the DB from being case sensitive to being case insensitive?
thx,
RichardHi Richard,
Are you upgrading from SQL2005 to 2008? We had this problem as it was installed w/SQL2005. What we did was install SQL2008 concurrently with 2005 so we could do a test to ensure fixing the collation would solve some problems with core functionality as well as add-ons, which it did.
Even though all the databases were CI/case insensitive, because the server was CS/case sensitive, it caused problems. You probably have the same. And if you don't, when you upgrade to SQL2008 it seems to do this for you.
Heather -
How to convert SQL server stored procedures to Oracle 11g
Hi Experts,
In SQL server 30 stored procedures are there how to convert all the stored procedure
from SQL server to Oracle 11g.
Please help me,
Thanks.ramya_162 wrote:
In SQL server 30 stored procedures are there how to convert all the stored procedure
from SQL server to Oracle 11g.
The single most fundamental concept you need to understand (grok in its fullness) is:
ORACLE IS NOT SQL-SERVER
There is very little, to NOTHING, in common between T-SQL (a language extension to SQL) and PL/SQL (integration of SQL with the language Ada, part of ALGOL family of languages that includes Pascal and C++).
So taking a T-SQL procedure and porting it as is to PL/SQL is plain stupid.
Why?
Oracle sucks at trying to be SQL-Server.
So how do you migrate from SQL-Server to Oracle?
By taking the REQUIREMENTS that the T-SQL procedures address, and addressing these requirements using Oracle SQL and PL/SQL. -
Logical Standby SQL Apply Using Incorrect Decode Statement
We are seeing statements erroring out on our logical standby that have been rewritten (presumably by sql apply) with decode statements that don't appear to be correct. For example, here is one of the rewritten statements.
update /*+ streams restrict_all_ref_cons */ "CADPROD"."OMS_SQL_STATEMENT" p
set *"APPLICATION"=decode(:1,'N',"APPLICATION",:2)*,
"STATEMENT"=dbms_reputil2.get_final_lob(:3,"STATEMENT",:4)
where (:5='N' or(1=1 and (:6='N' or(dbms_lob.compare(:7,"STATEMENT")=0)or(:7 is null and "STATEMENT" is null)))) and(:8="APPLICATION")
The problem comes in, we believe, with the attempt to write the value "APPLICATION" to the application column which is only a 10 character field. the value for the :1 bind variable is "N" and the value for :2 is null.
We see the following error on the logical standby:
ORA-00600: internal error code, arguments: [kgh_heap_sizes:ds], [0x01FCDBE60], [], [], [], [], [], []
ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [kxtoedu+54] [PC:0x2542308] [ADDR:0xFFFFFFFFFFFFFFFF] [UNABLE_TO_READ] []
ORA-12899: value too large for column "CADPROD"."OMS_SQL_STATEMENT"."APPLICATION" (actual: 19576, maximum: 10)
Is this a configuration issue or is it normal for SQL Apply to convert statements from logminer into decode statements?
We have an Oracle 10.2.0.4 database running on windows 2003 R2 64-bit os. We have 3 physical and 2 logical standby's, no problems on the physical standbys.Hello;
I noticed some of your parameters seem to be wrong.
fal_client - This is Obsolete in 11.2
You have db_name='test' on the Standby, it should be 'asadmin'
fal_server=test is set like this on the standby, it should be 'asadmin'
I might consider changing VALID_FOR to this :
VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES)Would review 4.2 Step-by-Step Instructions for Creating a Logical Standby Database of Oracle Document E10700-02
Document 278371.1 is showing its age in my humble opinion.
-----Wait on this until you fix your parameters----------------------
Try restarting the SQL Apply
ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATEI don't see the parameter MAX_SERVERS, try setting it to 8 times the number of cores.
Use these statements to trouble shoot :
SELECT NAME, VALUE, UNIT FROM V$DATAGUARD_STATS;
SELECT NAME, VALUE FROM V$LOGSTDBY_STATS WHERE NAME LIKE ;TRANSACTIONS%';
SELECT COUNT(1) AS IDLE_PREPARERS FROM V$LOGSTDBY_PROCESS WHERE
TYPE = 'PREPERER' AND STATUS_CODE = 16166;Best Regards
mseberg
Edited by: mseberg on Feb 14, 2012 7:37 AM -
Error while converting schema from oracle to SQL server
Hello,
I am getting following error while converting schema from oracle to SQL server using SSMA.
I get Errors 1-3 while migrating procedures and error 4 while migrating a table.
1- O2SS0050: Conversion of identifier 'SYSDATE' is not supported.
2- O2SS0050: Conversion of identifier 'to_date(VARCHAR2, CHAR)' is not supported.
3- O2SS0050: Conversion of identifier 'regexp_replace(VARCHAR2, CHAR)' is not supported.
4- O2SS0486: <Primary key name> constraint is disabled in Oracle and cannot be converted because SQL Server does not support disabling of primary or unique constraint.
Please suggest.
Thanks.The exact statement in oracle side which causing this error (O2SS0050:
Conversion of identifier 'to_date(VARCHAR2, CHAR)' is not supported.) is below:
dStartDate:= to_date(sStartDate,'MON-YYYY');
Statement causing error O2SS0050:
Conversion of identifier 'regexp_replace(VARCHAR2, CHAR)' is not supported is below.
nCount2:= length(regexp_replace(sDataRow,'[^,]'));
So there is no statement which is using to_date(VARCHAR2,
CHAR) and regexp_replace(VARCHAR2, CHAR) in as such. 'MON-YYYY' and '[^,]'
are CHAR values hence SSMA is unable to convert it from varchar2 to char.
Regarding SYSDATE issue, you mean to put below code in target(SQL) side in SSMA ?
dDate date := sysdate;
Thanks. -
PLS HELP CONVERT QUERY FROM UPDATE TO MERGE
Hi all,
Can you help me in converting this update statement into merge? I will really appreciate your help. Thanks
UPDATE dm_organizations tt
SET (cost_ctr_desc, cost_ctr_hier_lvl_1, cost_ctr_hier_lvl_2,
cost_ctr_hier_lvl_3, cost_ctr_hier_lvl_4, cost_ctr_hier_lvl_5, rgn_nm,
cntry_nm, load_date, update_date) =
(SELECT t.cost_ctr_desc, t.cost_ctr_hier_lvl_1,
t.cost_ctr_hier_lvl_2, t.cost_ctr_hier_lvl_3,
t.cost_ctr_hier_lvl_4, t.cost_ctr_hier_lvl_5, t.rgn_nm,
t.cntry_nm, t.load_date, SYSDATE
FROM dmi_cc_upload_stg t
WHERE t.run_id = 1831
AND t.status = 'Published'
AND t.cost_ctr_id = tt.cost_ctr_id
AND t.div_code = tt.div_code
AND t.fcn_code = tt.fcn_code
AND t.mkt_code = tt.mkt_code
AND t.corp_id = tt.corp_id
AND ROWNUM = 1)
WHERE EXISTS (
SELECT t.cost_ctr_desc, t.cost_ctr_hier_lvl_1,
t.cost_ctr_hier_lvl_2, t.cost_ctr_hier_lvl_3,
t.cost_ctr_hier_lvl_4, t.cost_ctr_hier_lvl_5, t.rgn_nm,
t.cntry_nm, t.load_date, SYSDATE
FROM dmi_cc_upload_stg t
WHERE t.run_id = 1831
AND t.status = 'Published'
AND t.cost_ctr_id = tt.cost_ctr_id
AND t.div_code = tt.div_code
AND t.fcn_code = tt.fcn_code
AND t.mkt_code = tt.mkt_code
AND t.corp_id = tt.corp_id);why not use existing UPDATE?
UPDATE dm_organizations tt
SET ( cost_ctr_desc, cost_ctr_hier_lvl_1, cost_ctr_hier_lvl_2,
cost_ctr_hier_lvl_3,
cost_ctr_hier_lvl_4, cost_ctr_hier_lvl_5, rgn_nm, cntry_nm,
load_date, update_date ) = (SELECT t.cost_ctr_desc,
t.cost_ctr_hier_lvl_1,
t.cost_ctr_hier_lvl_2,
t.cost_ctr_hier_lvl_3,
t.cost_ctr_hier_lvl_4,
t.cost_ctr_hier_lvl_5,
t.rgn_nm,
t.cntry_nm,
t.load_date,
SYSDATE
FROM dmi_cc_upload_stg t
WHERE t.run_id = 1831
AND t.status = 'Published'
AND t.cost_ctr_id = tt.cost_ctr_id
AND t.div_code = tt.div_code
AND t.fcn_code = tt.fcn_code
AND t.mkt_code = tt.mkt_code
AND t.corp_id = tt.corp_id
AND ROWNUM = 1)
WHERE EXISTS (SELECT t.cost_ctr_desc,
t.cost_ctr_hier_lvl_1,
t.cost_ctr_hier_lvl_2,
t.cost_ctr_hier_lvl_3,
t.cost_ctr_hier_lvl_4,
t.cost_ctr_hier_lvl_5,
t.rgn_nm,
t.cntry_nm,
t.load_date,
SYSDATE
FROM dmi_cc_upload_stg t
WHERE t.run_id = 1831
AND t.status = 'Published'
AND t.cost_ctr_id = tt.cost_ctr_id
AND t.div_code = tt.div_code
AND t.fcn_code = tt.fcn_code
AND t.mkt_code = tt.mkt_code
AND t.corp_id = tt.corp_id); -
Help me! converting to pdf from word, missing pictures and formating?
I wrote a book, was able to create a press quality pdf without any problem during my free trial of acrobat pro xi, now that I have made edits and have bought acrobat, everytime I create a pdf from this (large) word file, some of the images are missing, some text is blurry, and my formatting is off. It's maddening because it worked so easily before.
Any help is much appreciated.
Also, for a company that charges so much for their products that they basically have a monopoly on, it's very annoying that I can't get some sort of tech support on the phone and this appears to be my only option. VERY ANNOYING.
Anyhoo... thanks for any help from the forums/experts.
-ChrisI don't know what cause this and it's really annoying. I met the same problem when converting pdf from .docx file.
The solution is, re-save your .docx file (Word Document) into .doc file(Word 97-2004 Document) first. Then save the .doc file as pdf. It worked for me. -
Please help me to convert from 5.0 to 2009
Please help me to convert from 5.0 to 2009
Source LabVIEW version: LabView 5.0
Target LabVIEW Version: LabView 9.0
Thank you so much..
Solved!
Go to Solution.
Attachments:
shutter.llb 255 KBLabVIEW 9.0
Attachments:
shutter.llb 90 KB -
Convert sql select statement to oracle
Hi All,
Can anyone help me converting this Sql select statement to oracle ....
-----------------------------------------Query--------------------------------------------------------------
select emp_master.emp_code ,
emp_master.dept_cd ,
attendance_master.daily_attn_code ,
attendance_master.linked_column ,
case when location.payroll_status <> 'N' and eDocsNetEmployeesLeave.StartDate < dateadd(mm, 1 , convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01'))
then
dateadd(mm, 1 , convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01'))
when eDocsNetEmployeesLeave.StartDate < convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01')
then convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01') else eDocsNetEmployeesLeaveDetails.StartDate
end ,
eDocsNetEmployeesLeaveDetails.NoOfDays,
case when eDocsNetEmployeesLeave.StartDate > location.next_pay_date
then convert(datetime , convert(varchar, dateadd(ss,-1, dateadd(mm, 1, convert(datetime , datename(yy,eDocsNetEmployeesLeave.StartDate)+ '/' + datename(mm,eDocsNetEmployeesLeave.StartDate)+ '/01') )),106) )
else
case when location.payroll_status <> 'N'
then dateadd(mm,1,location.next_pay_date)
else location.next_pay_date
end
end as PaymentDate ,
isnull(grade_master.leave_type,'C') ,
eDocsNetEmployeesLeave.StartDate ,
eDocsNetEmployeesLeaveDetails.LeaveType
from eDocsNetEmployeesLeave ,
eDocsNetEmployeesLeaveDetails ,
eDocsNetLeaveTypes ,
emp_master ,
grade_master ,
attendance_master ,
location
where eDocsNetEmployeesLeaveDetails.RequestID = eDocsNetEmployeesLeave.RequestID and
eDocsNetEmployeesLeave.EmployeeID = emp_master.emp_code and
eDocsNetEmployeesLeaveDetails.LeaveType = eDocsNetLeaveTypes.LeaveTypeID and
eDocsNetLeaveTypes.loc_cd = emp_master.loc_cd and
location.loc_cd = emp_master.loc_cd and
attendance_master.loc_cd = emp_master.loc_cd and
attendance_master.linked_column = eDocsNetLeaveTypes.LinkedAttendance and
grade_master.loc_cd = emp_master.loc_cd and
grade_master.grade_cd = emp_master.grade_cd and
eDocsNetEmployeesLeaveDetails.RequestID = @RequestID
order by eDocsNetEmployeesLeaveDetails.StartDate
Thanks in Advance
SmileySeems like you want to convert a SQL statement from the ??? dialect to the Oracle dialect. *(It would be useful to indicate the non-ANSI standard SQL you are starting with.)
Part of the problem is that you use several date related functions. Some are unnecessary in Oracle and some need to translated into Oracle functions as found in the Functions section (chapter 5) of the SQL Reference manual at http://www.oracle.com/pls/db102/homepage
Note that columns and expressions of type 'date' in ORacle always contain all of "yyyy mm dd hh mi ss" and you need to format and trauncate as necessary.
Also note that '09-JAN-31' is NOT an Oracle date, but rather a character representation of a date which must be converted to/from a date expression. You will often need to use the to_date() and to_char() functions with a format mask as the second parameter. This is also descreibed in the first 2 chapters of the SQL Reference manual.
Maybe you are looking for
-
UDF to capture the source file name or the source folder for mapping
Hi All, i have 2 files - File1 from File2 from 2 different folders- single comm channel FTP (FCC). i have to pass a constant A and B respectively to a field in target structure. my options are - either create a new field in source str populating dif
-
Hi experts, I need this : I have my variable num_pack = 0,04 type i. I need my variable becomes 1. Which operator do I need ( if exists ) ? Thanks in advance. Marco
-
Dear All, I want to fetch any 5 records from a table without using internal table.Basically I want an abap equivalent for the 'rownum' keyword in oracle. For e.g. select * from emp where rownum < 5. How can this be done in abap? Yours tr
-
How to view the login log in window NPS after login cisco switch and without SQL server database
how to view the login log in window NPS after login cisco switch and without SQL server database in summary there is only log with event id 4400 A LDAP connection with domain controller XCPAWS20.cyberport.noc for domain NOC2 is established.
-
Why don't selected photos sync on iPad2?
I've selected some albums to synch from iPhoto on my Mac onto my iPad. Only a few of the photos go across, most don't. There's plenty of room in the memory. Am I missing something?