Between with decode
can you please tell me how should i write this
DECODE(G.EARLY_PREV, 'Y', E.sDATE BETWEEN last_run_date And run_date, E.sDATE BETWEEN (last_run_date + 1) And run_date)
Thanks
Hi,
Another way:
e.sdate BETWEEN last_run_date + DECODE ( g.early_prev
, 'Y' , 0
, 1
AND run_dateIt depends on your data and your requirements.
See the forum FAQ {message:id=9360002}
Similar Messages
-
Guys,
I want to replace CASE statement with DECODE. How ?
case when msg.is_swap = 'Y' and msg.buy_sell = 1 then 'SO'
when msg.is_swap = 'Y' and msg.buy_sell = 0 then 'SI'
else ''
end As TransactionType
How should i implement DECODE function to do the above one ?
Regards
KarthikKarthik_ORACLE wrote:
Thanks for all your replies.
As i am new to ORACLE, one of my friend told me that DECODE will be faster than CASE. is it true ? Thats why i wanted to convertNeed to be proved ! See the following thread :
Re: what is better and fast to use between decode and case
Oracle version dependant, plateform dependant, and still the difference is near to 0.
Nicolas. -
Error while replacing IF statements with DECODE function in procedure
Hi All,
I have created a procedure which has nested IF statements. Now I want to replace the IF statements with DECODE functions to improve performance.
Procedure:
IF (var_int_sev = '0')
THEN
var_sev := '2';
ELSE
SELECT sev
INTO var_int_sev
FROM errorconfig
WHERE errorcode = var_errorcode;
var_sev := var_int_sev;
END IF;
I converted the above IF statement into DECODE function as mentioned below:
var_Sev := DECODE(var_int_sev,0,2,SELECT severity FROM errorconfig WHERE errorcode=var_ErrorCode)
But it throws below error at the select statement used inside DECODE.
Error(58,51): PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( - + case mod new not null others <an identifier> <a double-quoted delimited-identifier> <a bind variable> avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date <a string literal with character set specification> <a number> <a single-quoted SQL string> pipe <an alternatively-quoted string literal with character set specification> <an alternativ
Can someone help me in converting the IF to DECODE in the above case. Also how can we use a select statement inside decode.instead of trying to rewrite all your code and hoping that the performance will be better, it's a better option to investigate and find out which part of your application is slow
read this:
When your query takes too long ... -
Problem with DECODE block in WHERE clause
Hi,
I'm facing problem with DECODE statement. I just simulated my problem in the simple way as follows. If I execute this following query, I should get "hello", but I'm not getting anything (ZERO rows returned).
SELECT 'hello' FROM DUAL
WHERE 'sample1' in (DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
2, '''sample4'', ''sample5'', ''sample6'''
I think some problem is there in my WHERE clause.
But When I'm exeucting the following query as a seperate query, then I'm getting the value of DECODE block properly, but didn;t understnad why its not returning the same way when I'm putting the same DECODE statement in WHERE clause.
SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
2, '''sample4'', ''sample5'', ''sample6'''
FROM DUAL;
Please help me to get out of this problem. Thank you so much in advance.
Thanks,
Ramji.The value returned by SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6''') FROM DUAL;
'sample1', 'sample2', 'sample3' is a single string. Consider it x.
SELECT 'hello' FROM DUAL WHERE 'sample1' in ( DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6'''));
is like SELECT 'hello' FROM DUAL WHERE 'sample1' in ('x');
or
SELECT 'hello' FROM DUAL WHERE 'sample1' in ('''sample1'', ''sample2'', ''sample3''') and not
SELECT 'hello' FROM DUAL WHERE 'sample1' in ('sample1', 'sample2', 'sample3');
For this same reason SELECT 'hello' FROM DUAL WHERE 'sample1' in (select '''sample1'', ''sample2'', ''sample3''' from dual);
also does'nt work.
Please use INSTR to find whether 'sample1' exists in the string 'sample1', 'sample2', 'sample3'. -
Problems with decoding an latin1-encoded url
Hi,
i have a problem with decoding german umlaut-characters from an URL.
I'm using Tomcat 5.5 on a Linux server and one on a windows machine for development. Both webapps have the same configurations.
A servlet decodes the URL-String, parses it and stores the parsed data into a mysql-DB.
For decoding the query-string i'm using org.apache.commons.codec.net.URLCodec.URLCodec.decode .
Here's the code:
String unparsedParameters = request.getQueryString();
URLCodec codec = new URLCodec("ISO-8859-1");
result = codec.decode(unparsedParameters);Here an example for a query-string: http://servername:8080/servlet/Import?Etwas%20wurde%20am%2025.08.2010%2010%3A16%3A50%20*ge%E4ndert*
On the windows machine the word "*geändert*" is decoded correctly. But on the linux server i get "*ge?ndert*". It makes no difference if i write the result into the database or just into a logfile.
Can anyone help?
Thanks in advance.
Edited by: sol1640 on Aug 26, 2010 5:59 AMProblem resolved.
Instead of using the decode-method as described in my fist message now i'm doing the folowing:
fURLDecodigCharset = "ISO8859-1";
byte[] bytes = originalParam.getBytes(fURLDecodigCharset);
byte[] decodeUrl = URLCodec.decodeUrl(bytes);
result = new String (decodeUrl, fURLDecodigCharset);because the method "decode" decodes the string by using the defaultcharset. And that was the problem.
>
The default charset is determined during virtual-machine startup and typically depends upon the locale and charset of the underlying operating system.
>
Thats why i've got different behaviours on different systems.
Thanks -
OWB3i - Validate with DECODE function
Hi,
in OWB 3i when I validate an expression defined inside an expression operator with DECODE() function (which is not include in default transformation) come this error:
Line 1, Col 1:
PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only
but it seems only a warning because when i generate the scripts and run no other error happen and all works fine.
RegardsHi,
Welcome to the forum!
When you use a default value, the last argument to DECODE is the actual value you want as a default.
For example:
SELECT ename
, deptno
, DECODE ( deptno
, 30 , 'Sales'
, 'All others' -- Default value
) AS dname
FROM scott.emp
ORDER BY ename
;Output:
ENAME DEPTNO DNAME
ADAMS 20 All others
ALLEN 30 Sales
BLAKE 30 Sales
CLARK 10 All others
FORD 20 All others
JAMES 30 Sales
JONES 20 All others
KING 10 All others
MARTIN 30 Sales
MILLER 10 All others
SCOTT 20 All others
SMITH 20 All others
TURNER 30 Sales
WARD 30 Sales
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
If you can show the problem using commonly available tables (such as those in the scott schema) then you don't need to post any sample data; just the results and the explanation.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
How to get the required output with single query to acheive IF SAL>2500 and job='manager' then display job as 'seniormanager'.
CREATE TABLE EMP(EMPNO NUMBER(4) NOT NULL,ENAME VARCHAR2(10),JOB VARCHAR2(9),MGR NUMBER(4),HIREDATE DATE,SAL NUMBER(7, 2),COMM NUMBER(7, 2),DEPTNO NUMBER(2));
INSERT INTO EMP VALUES(7521, 'WARD', 'SALESMAN', 7698,TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250, 500, 30);
INSERT INTO EMP VALUES(7566, 'JONES', 'MANAGER', 7839,TO_DATE('2-APR-1981', 'DD-MON-YYYY'), 2975, NULL, 20);
INSERT INTO EMP VALUES(7698, 'BLAKE', 'MANAGER', 7839,TO_DATE('1-MAY-1981', 'DD-MON-YYYY'), 2850, NULL, 30);
INSERT INTO EMP VALUES(7782, 'CLARK', 'MANAGER', 7839,TO_DATE('9-JUN-1981', 'DD-MON-YYYY'), 2450, NULL, 10);
INSERT INTO EMP VALUES(7788, 'SCOTT', 'ANALYST', 7566,TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3000, NULL, 20);
IF SAL>2500 and job='manager' then display job as 'seniormanager'
SELECT * FROM EMP
expected output
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES SENIORMANAGER 7839 02-APR-81 2975 20
7698 BLAKE SENIORMANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20Hi,
The answer to "How do I ... using DECODE?", no matter how you fill in the blank, is "Don't use DECODE; use CASE instead." If you have to ask, then it's too complicated to do with DECODE.
Here's one way using CASE:
SELECT empno, ename
, CASE
WHEN job = 'MANAGER'
AND sal > 2500
THEN 'SENIORMANAGER'
ELSE job
END AS d_job
, mgr, hiredate, sal, comm, deptno
FROM emp
;If you really, really, really want to use DECODE:
SELECT empno, ename
, DECODE ( job
, 'MANAGER'
, DECODE ( SIGN (sal - 2500)
, 1
, 'SENIORMANAGER'
, job
, job
) AS d_job
, mgr, hiredate, sal, comm, deptno
FROM emp
;Nothing is literally too difficult to do in DECODE. Anything that case be done with CASE can also be done using DECODE, often using several times the amount of code. Bit which would you rther maintain: the CASE soltuion I posted first, of this DECODE soltuion. Which do you think will have more bugs? Which so you think will be faster? If you're using Oracle 8.1 (or higher) then don't use inefficient, high-maintenance code like this. Use CASE instead.
Edited by: Frank Kulash on Dec 26, 2012 3:27 PM
Added DECODE solution -
Problem with DECODE statement while migrating forms to 6i
Hi,
I'm migrating a form from 5 to 6i. When I compiled the form, I got this error witha decode statement.
The error is
Error 307 at line 15 column 7
too many declarations of "DECODE" match this call
The trigger has this code:
IF :PRUN_RECS_INSERTED = 'Y' THEN
RETURN ;
END IF ;
INSERT INTO GJBPRUN
( GJBPRUN_JOB,
GJBPRUN_ONE_UP_NO,
GJBPRUN_NUMBER,
GJBPRUN_ACTIVITY_DATE,
GJBPRUN_VALUE )
SELECT :KEYBLCK_JOB,
:ONE_UP_NO,
GJBPDFT_NUMBER,
SYSDATE,
DECODE(GJBPDFT_VALUE, 'SYSDATE',
DECODE(GJBPDEF_LENGTH,'11',TO_CHAR(SYSDATE,'DD-MON-YYYY'), SYSDATE),
GJBPDFT_VALUE)
FROM GJBPDFT G, GJBPDEFEdited by: Charan on Mar 16, 2011 9:15 AMHi Charan
i think it's all about using both CHARACTER and DATE values at the same time in a DECODE statment u should either use char or date datatype.
DECODE compares expr to each search value one by one. If expr is equal to a search, then Oracle Database returns the corresponding result. If no match is found, then Oracle returns default. If default is omitted, then Oracle returns null.
e.g.
If expr and search are character data, then Oracle compares them using nonpadded comparison semantics.
expr, search, and result can be any of the datatypes CHAR, VARCHAR2, NCHAR, or NVARCHAR2.
The string returned is of VARCHAR2 datatype and is in the same character set as the first result parameter.
for more pls have a look here
Hope this helps,
Regards,
Abdetu... -
Problem with decode!!!
Hi guys,
I have a problem with "decode"!
How can I tell the decode expression
that if a rowset don't exists --> then doing something.
I've tried that with "NULL" but that don't works.
here my code:
I wanted that if tx.text doesn't exists then
it returns fs.anlageschwerpunkt_lang, and otherwise
it returns tx.Text.
select
decode(tx.Text,NULL,fs.anlageschwerpunkt_lang,tx.Text) Anlageschwerpunkt_1 from
POI.Fondsstamm fs,
Texte tx,
Texttypstamm txy
where
tx.match='amfcomm'
and tx.match=rtrim(fs.match)
and tx.TEXTTYPID=txy.TEXTTYPID
and txy.BEREICHSID=14
and txy.texttyp='Marketingstrategie'
I hope somebody of you can help me
thanxx
SchoeibI read Schoeibs question differently; no ROWS are being returned. In that case you cannot expect DECODE or any other function to do anything. Assuming that rows always exist in fs and txy and are only missing in tx, then you need an outer join. Note that the join of tx.match = rtrim(fs.match) has been altered to avoid outer joining to more than one table. As mentioned before, although the decode is OK, NVL could be used instead.
select
decode(tx.Text,NULL,fs.anlageschwerpunkt_lang,tx.Text) Anlageschwerpunkt_1 from
POI.Fondsstamm fs,
Texte tx,
Texttypstamm txy
where
tx.match(+)='amfcomm'
and rtrim(fs.match) = 'amfcomm'
and tx.TEXTTYPID(+)=txy.TEXTTYPID
and txy.BEREICHSID=14
and txy.texttyp='Marketingstrategie' -
I want to count several categories(say a b c d) under same count and some catogories under another count ..there I need to use count with decode pls let me know the syntacs to write my query..this is ergent
regards
BuddhikeSomething like this ?
select count(decode(your_column,'a',1)) as "a",
count(decode(your_column,'b',1)) as "b",
count(decode(your_column,'c',1)) as "c",
count(decode(your_column,'d',1)) as "d"
from your_table;But maybe you can give us more details about what do you expected ?
Nicolas. -
ViewObjects Order by clause with DECODE
Hello!
I am using Jdeveloper 11g, version 11.1.1.2.0.
The problem I'm having is this.
If I use a DECODE statement in view objects ORDER BY clause, I get an error: "java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 2".
Let me give an example. I'll be using EmployeesView view object, which is using Employees entity from HR schema.
This is a part of view objects XML.
<ViewObject
xmlns="http://xmlns.oracle.com/bc4j"
Name="EmployeesView"
Version="11.1.1.55.36"
SelectList="Employees.EMPLOYEE_ID,
Employees.FIRST_NAME,
Employees.LAST_NAME,
Employees.EMAIL,
Employees.PHONE_NUMBER,
Employees.HIRE_DATE,
Employees.JOB_ID,
Employees.SALARY,
Employees.COMMISSION_PCT,
Employees.MANAGER_ID,
Employees.DEPARTMENT_ID"
FromList="EMPLOYEES Employees"
BindingStyle="OracleName"
CustomQuery="false"
PageIterMode="Full"
UseGlueCode="false"
OrderBy="Employees.MANAGER_ID">
As you can see in this case, the Order by clause is very simple. This works like a charm.
But, if put something like this "DECODE(Employees.MANAGER_ID, NULL, 1, 2)" in the Order by, I get an internal parsing error.
I replicated this error on my home machine as well as on my work machine. I'm using the same version of Jdeveloper on both.
Has anyone else stumbled upon this problem and solved it?
Any thoughts would be greatly appreciated :)
KristjanThe second example works, but the first one doesn't, unfortunately :/
Also, the example I gave is unfortunately just that, a proof-of-concept example that there is a problem with DECODE if it is written inside the Order by clause.
My real DECODE use case is a bit different. Like this: "DECODE(attribute, 'N', 1, 2) ASC".
Since posting my original question, I did some research-by-example work and I discovered that this is not just a problem of DECODE, but more like a problem of brackets and commas.
No database function that uses more than one parameter can be used in Order by clause.
The reason is, if a function with more than one parameter is used, commas inside brackets have to be used. Something along the lines of: "database_function(param1, param2, ...)".
The parser seems to have a problem with this kind of expressions.
Is there a work around?
Kristjan
p.s.: Thank you for your quick response. -
Replace characters between with single * in variable
Hi Experts ,
I want to replace all characters between < > with *. Data is stored in variable type char255.
Example ,
Suppose variable contains : Wage Type <Wage Type> Not Valid For Interface ID <ID>
I want output as Wage Type * Not Valid For Interface ID *.
Thanks & Regards ,
Jigar ThakkarHi Jigar,
Find the length of the string and use DO...ENDDO statement. Inside the loop, didnt consider the text between < and > and move to another string and add * when > is encountered in the string.
data:
gv_len type i,
gv_str type string value 'Wage Type <Wage Type> Not Valid For Interface ID <ID>',
gv_rep_str type string,
gv_flag type char1,
gv_index type sy-index.
gv_len = strlen( gv_str ).
do gv_len times.
gv_index = sy-index - 1.
if gv_str+gv_index(1) = '<'.
gv_flag = 'X'.
continue.
elseif gv_str+gv_index(1) = '>'.
clear gv_flag.
concatenate gv_rep_str '*' into gv_rep_str.
continue.
elseif gv_flag is initial.
concatenate gv_rep_str gv_str+gv_index(1) into gv_rep_str.
endif.
enddo.
write:/ gv_rep_str.
Thanks,
Vinay
Edited by: Vinaykumar G on May 29, 2009 8:04 PM -
Difference between WITH CLAUSE and INLINNE VIEW.
Hi experts.
Can anyone explain me the diff. between WITH CLAUSE and INLINNE VIEW with some example.
Thanks in advance.user10314274 wrote:
Hi experts.
Can anyone explain me the diff. between WITH CLAUSE and INLINNE VIEW with some example.Generally, they are the same thing with a few minor differences.
The WITH clause gives you a little more control on how the sub-queries are to be set up and used and allows the same subquery to be used multiple times without re-reading the data. Both simulate the functionality of views.
I feel the WITH clause provides better strucure and maintainablility.
The WITH clause aslo offesr two hints, INLINE and MATERIALIZE that can affect performance - both are used with the query in the IN clause. INLINE causes the subquery to be used as a subquery (inline view) while MATERIALIZE requests that the data be copied to a temporary table first. These hints are undocumented but are recognized by the user community.
Edited by: riedelme on Jan 20, 2010 6:32 AM -
Difference between with table name with * and without *
Hi..
I had seen some of the standard abap that the table name had *, like *ekpo. What is the meaning? What is the difference between with * and without * ?
Thanks and Regards,
RishikaHi rishika,
1. This is actually a facility provided in abap syntax.
2. It is usually checked while saving a record.
3. For eg.
If we have one variable
EKKO
and another *EKKO
(They both are same only, with same structure)
(but two different variables)
4. The functional meaning, for usage purpose,
of *EKKO is OLDEKKO.
5. While saving the transaction,
the data is saved only if there is any change
in the values.
IF EKKO <> *EKKO.
*--- SAVE
ELSE.
MESSAGE 'NO DATA CHANGED'
ENDIF.
6. We can aswell use any other variale
eg. oldekko
oekko
myekko
etc,
7. But for business meaning,
R/3 has the facility for *
1. we can use almost everywhere.
2. just copy paste
report abc.
TABLES : T001.
TABLES : *T001.
DATA : ITAB LIKE EKKO.
DATA : *ITAB LIKE EKKO.
DATA : NUM TYPE I.
DATA : *NUM TYPE I.
regards,
amit m. -
Between clause with DECODE function.
Hi All,
I have one table which has object, date and quantity columns, Now based on date range I can find out the objects and quantity but the question is: I want a query which returns all the objects and should show quantity 0(zero or null) for those objects which don't falls under that date range. So I thought to use a decode function but it only uses the relational operation, I thought something like this but it's wrong,
select object,decode(created_date,BETWEEN '01/01/2008' TO '08/01/2008',quantity,0) from table;
Does anyone have any idea how can I make this work in single sql statement?
Thanks for your help.select object,decode(created_date,BETWEEN '01/01/2008' TO '08/01/2008',quantity,0) from table;
Does anyone have any idea how can I make this work in single sql statement?If you're still interested in using DECODE over Case when, please try this.
Check for employees hired between 6/17/1987 and 9/30/1987
SQL> select first_name||' '||last_name as emp_name, hire_date,
2 decode(sign((to_date('06/17/1987','MM/DD/YYYY')-1)-hire_date)
3 + sign((to_date('09/30/1987','MM/DD/YYYY')+1)-hire_date)
4 ,0,'Between','Not between') as IsBetween
5 from employees
6 where hire_date <to_date('01/01/1991','MM/DD/YYYY')
7 /
EMP_NAME HIRE_DATE ISBETWEEN
Steven King 17-JUN-87 Between
Neena Kochhar 21-SEP-89 Not between
Alexander Hunold 03-JAN-90 Not between
Jennifer Whalen 17-SEP-87 BetweenMessage was edited by:
Bobbydj
Maybe you are looking for
-
A/R User Exit Spec and code
The spec - 1. Canadian tax - currently based on Freight type: Read the country(?) Ship-from (plant jurisdiction) to Ship-to(customer jurisdiction) and the inco term on the line item of the sales order and if it's not equal to 'DDP' the line ite
-
Firefox4 w/Vista - Page freezes when I attempt to open some PDFs. What's up?
Firefox 4.0.1 Toshiba Satellite A215 AMD TK-55 Dual-Core Processor, 1.8 Ghz 4 GB RAM 32-Bit Windows Vista Home Premium 2007, SP2 This problem has cropped up since installing your Version 4 & Adobe Reader 10. I think I have the latest versions of both
-
So Spry is gone in DW CC. Spry of course made deploying menus very quick and easy. Does anyone have any suggestions for an equivalent tool for menus using Jquery? Thanks
-
InsertSyncBo is not allowed in reset mode ?
Hi guys, Do you have any idea what can cause this: com.sap.ip.me.api.smartsync.ModificationNotAllowedException: insertSyncBo is not allowed in reset mode. at com.sap.ip.me.smartsync.data.SyncBoDataFacadeImpl.insertSyncBo() It is triggered in MAM
-
Safari 7.0.4 update, kb HT1222
The Safari 7.0.4 update web page redirects to other page of kb HT1222 for update's more details - a hyperlink. The hyperlink destination however does not mention any single word about Safari 7.0.4. That's the quality made by Apple!!!! Not the first i