How to do is decode ?
Hi,
I have the following sql in place :-
SELECT TD_MAIN_ACNT_CODE, SUM(DECODE(TD_DOC_DRCR_FLAG,'C', 0 - TD_DOC_AMT, TD_DOC_AMT)) NETT
FROM FV_TRANS_DETAIL
GROUP BY TD_MAIN_ACNT_CODE
The output is as below :
TD_MAIN_ACNT_CODE NETT
41060_____________________-990.8
41060_____________________-1231.4
41060_____________________-423.5
41060_____________________543.33
41060_____________________989.99
from the query, I want to convert those figure (NETT) with < 0 to be changed to positive value. How am I going to achieve this?
Please advise.
Regards,
Lim
Excellent point, they are not the same thing.
How about:
WITH test AS
( SELECT integer_tt(1,3,5,7,9) AS coll1
, integer_tt(3,7) AS coll2
FROM dual
UNION ALL
SELECT integer_tt(3,5,7) AS coll1
, integer_tt(1,3,7,9) AS coll2
FROM dual )
SELECT coll1
, coll2
, CASE
WHEN coll2 SUBMULTISET coll1 THEN 'True'
ELSE 'False'
END
, DECODE(CARDINALITY(coll2 MULTISET EXCEPT coll1),
0,'True', 'False')
FROM test;
COLL1 COLL2 CASEW DECOD
INTEGER_TT(1, 3, 5, 7, 9) INTEGER_TT(3, 7) True True
INTEGER_TT(3, 5, 7) INTEGER_TT(1, 3, 7, 9) False False
Similar Messages
-
[Urgent!!] How to do quadrature decoding using DAQCard 6062E??
Hi,
I am Xiaofei, a beginner of LabVIEW. Now i am dealing with a project involving quadrature decoding by using DAQ Card 6062E and breakout board CB68LP. We need to use 2 optical encoders simutaneously, and for each encoder, we need to use 3 digital channels (A,B and Index), therefore there will be totally 6 digital channels in use. For this reason, is it still good to use the counter channel? or we'd better use 6 DIO?
I'm not sure if there is any existing VI that can help us with decoding, if there is, could you please let me know how we can find it?
If we will need to make the decoding code by ourselves, could you please give me some hint so that we can start it?
I heard that there should be an example called "How to Count.vi" that shows how to decode, however i failed to find it by using example finder, so does anyone know how to find it?
This is kinda urgent, i have to figure it out by tonight in order to keep my project rolling. So if you have any idea about it, pleeeeeeeeeease let me know! Thanks a million!!!
Regards,
XiaofeiDuplicate post.
Please do not generate a new message thread with the same question.
Keep your messages to the original post. -
How to do quadrature decoding using DAQCard6062E?
Hi,
My name is Xiaofei, a beginner of LabVIEW. Now i am dealing with a project involving quadrature decoding by using DAQ Card 6062E and breakout board CB68LP. We need to use 2 optical encoders simutaneously, and for each encoder, we need to use 3 digital channels (A,B and Index), therefore there will be totally 6 digital channels in use. For this reason, is it still good to use the counter channel? or we'd better use 6 DIO?
I'm not sure if there is any existing VI that can help us with decoding, if there is, could you please let me know how we can find it?
If we will need to make the decoding code by ourselves, could you please give me some hint so that we can start it?
I heard that there should be an example called "How to Count.vi" that shows how to decode, however i failed to find it by using example finder, so does anyone know how to find it?
Thanks a million!!!
Regards,
XiaofeiHi Xiaofei,
Our 6062E DAQ cards can be used with either our DAQmx drivers or our older
Traditional DAQ (Legacy) drivers. The example that I've provide below is
for use with our DAQmx driver set. If you’re using Traditional DAQ
drivers I would recommend upgrading to our newest DAQmx drivers. You can
click here
for help determining what version of DAQmx works with your version of LabVIEW.
To do hardware timed quadrature encoder applications you will want to use the
counters on your 6062E DAQ card. Click here for a guide to
using quadrature encoders on E-series DAQ cards. Unfortunately, our
E-Series cards do not support Z-indexing as described in the following
developer zone tutorial: Quadrature
Encoder / Position Measurement. However, you should be able to use
your encoders without using Z-indexing. Each of your encoders will
use one counter source and one digital line for your A and B inputs. The
counters will count the edges of the A input while the digital line determines
the direction (Up or Down). A good example can be in the example finder
under the following location: (Help » Find Examples » Hardware Input and Ouput
» DAQmx » Counter Measurements » Count Digital Events » Count Digital Events.vi).
This example should give you a good start for use with encoder. You will
just want to replicate the code for your additional encoder.
I hope this helps,
Paul C. -
How to replace huge decode statements with lookups to some simple code/key
I have a legacy PL/SQL application, composed of many very huge decode statements. And the most terribe one is that the guys who develops the application left the company now, leaves no documentation.
We are trying to read and understand those PL/SQL programs, and I'm asked to replace those huge decode statements with lookups to some simple code/key tables? But I have no idea about how to design such code/key tables. Is there any one who has similar experience may help me? Besides code/key tables, any idea will be welcome.
Thank you very much!Not sure what your data looks like but sometimes decode can be replaced with more appropriate functions, ie;
SQL> with t as (
select 'DAY' a, 30 b, null c, null d from dual union all
select null a, null b, 'MONTH' c, 12 from dual)
select coalesce(b,d)
from t
COALESCE(B,D)
30
12
2 rows selected.
SQL> with t as (
select 'DAY' a, 30 b, null c, 0 d from dual union all
select null a, 0 b, 'MONTH' c, 12 from dual)
select greatest(b,d)
from t
GREATEST(B,D)
30
12
2 rows selected. -
I want to use the following with decode, recently started on BODS.
Can you please provide the steps to use decode function
in source tabke fieldname is ordid and in target fieldname is Orderid
decode(Order_ID = 1709,lpad(Order_ID,7,'700'),Order_ID)
thank you very much for the helpful i1) In the mapping tab of target column, click on Functions, select Miscellaneous Functions category, you can find decode function in it. Lpad can be found in String functions category.
OR
2) You can directly script this or paste this code at the mapping tab. In this case, remove the Order_ID from the script wherever used, drag and drop this column from the input schema of Query transform to avoid the syntax error.
Regards,
Suneer -
How can we use DECODE function in where clause.
Hi Guys,
I have to use DECODE function in where clause.
like below
select * from tab1,tab2
where a.tab1 = b.tab2
and decode(code, 'a','approved')
in this manner its not accepting?
Can any one help me on this or any other aproach?
Thanks
-LKR>
I am looking for to decode the actual db value something in different for my report.
like if A then Accepted
elseif R then Rejected
elseif D then Denied
these conditions I have to check in where clause.
>
what are you trying to do?
may be you are looking for
select * from tab1,tab2
where a.tab1 = b.tab2
and
(decode(:code, 'A','Accepted') = <table_column>
or
decode(:code, 'R','Rejected') = <table_column>
or
decode(:code, 'D','Denied') = <table_column>
) -
How to use Decode with a variable
Maybe you've seen this done.
I want to take statement strMenu4 and subtract the previous value
that is stored in an array as shown in strMenu5.
My problem is this change as shown in strMenu5 produces
an error code:
ORA-00904 invalid column name
So either I'm coding something wrong or it can't be done within the
SUM(decode) construct. If I replace the variable with a literal
like 1000 the code works:
SUM(decode(name,'DBWR lru scans', c1.value) - 1000) DBWR_lru_scans
but with an array variable or even a constant the code fails:
SUM(decode(name,'DBWR lru scans', c1.value) - Array(3)) DBWR_lru_scans, "
Any ideas how I can use Decode with a variable and not have it interrupt it
as a invalid column name?
Thanks,
Joseph Karpinski
[email protected]
[email protected]
strMenu4 = "SELECT d1.instance, " _
& " to_char(sysdate, 'dd-mon-yy hh24:mi:ss') start_time, " _
& " SUM(decode(name,'DBWR buffers scanned', c1.value)) DBWR_buffers_scanned, " _
& " SUM(decode(name,'DBWR lru scans', c1.value)) DBWR_lru_scans, " _
& " SUM(decode(name,'db block gets', c1.value)) db_block_gets , " _
& " SUM(decode(name,'consistent gets', c1.value)) consistent_gets , " _
& " SUM(decode(name,'physical reads', c1.value)) physical_reads " _
& " from dual, v$sysstat c1, v$thread d1 " _
& " group by d1.instance "
strMenu5 = "SELECT d1.instance, " _
& " to_char(sysdate, 'dd-mon-yy hh24:mi:ss') start_time, " _
& " SUM(decode(name,'DBWR buffers scanned', c1.value) - Array(2)) DBWR_buffers_scanned, " _
& " SUM(decode(name,'DBWR lru scans', c1.value) - Array(3)) DBWR_lru_scans, " _
& " SUM(decode(name,'db block gets', c1.value) - Array(4)) db_block_gets , " _
& " SUM(decode(name,'consistent gets', c1.value) - Array(5)) consistent_gets , " _
& " SUM(decode(name,'physical reads', c1.value) - Array(6)) physical_reads " _
& " from dual, v$sysstat c1, v$thread d1 " _
& " group by d1.instance "Re-posting in the SQL and PL/SQL forum.
It's more appropriate.
Thanks,
Closing -
How to Use Decode for manipulating time
How can i use Decode function to manipulate time...
Example
suppose ive employee and his time in...i want to display status field by using decode,which reflects if that employee came after 09:15:00 the status='L' else this will print 'P'
i tried this
SELECT pin_code,DECODE( to_char(ACCESS_TIME,'HH24:MI:SS'>'09:15:00','l','P'))STATUS
FROM ATTENDANCE_REG
this query hasn't work...
waiting for reply
Regards
Danish HayderSQL> select case when to_number(to_char(sysdate,'sssss')) > 33300 then 'L'
2 else 'P' end status
3 from dual;
S
L
1 row selected. -
How to encode/decode URLs ...
Hello,
I wanted to send an entire URL as parameter to a Stored Procedure.
How can I encode/decode this URL?
Thanks
MadhavI don't know of an encoder, but IBM alphaWorks has a decoder:
http://www.alphaworks.ibm.com/tech/mpeg-4 -
SELECT v_startdate, v_enddate,
(CASE WHEN SYSDATE BETWEEN v_startdate AND v_enddate THEN
‘active’
ELSE
‘inactive’
END) status
FROM correction_tab;
Could you kindly guide us as to how can we use DECODE and get the desired output.
Thanks,
Rami Reddy.You can, like this.
However, the CASE seems a lot clearer to me so why bother with a DECODE?
sql> with correction_tab as
2 ( select trunc(sysdate)-1 as v_startdate, trunc(sysdate) as v_enddate from dual
3 union all
4 select trunc(sysdate) as v_startdate, trunc(sysdate)+1 as v_enddate from dual
5 union all
6 select trunc(sysdate)+1 as v_startdate, trunc(sysdate)+2 as v_enddate from dual
7 )
8 SELECT v_startdate
9 , v_enddate
10 , CASE
11 WHEN SYSDATE BETWEEN v_startdate AND v_enddate
12 THEN 'active'
13 ELSE 'inactive'
14 END status
15 , decode ( sign(sysdate-v_startdate), 1, decode(sign(v_enddate-sysdate), 1, 'active', 'inactive'), 'inactive')
as status2
16 FROM correction_tab
17 /
V_STARTDA V_ENDDATE STATUS STATUS2
12-DEC-12 13-DEC-12 inactive inactive
13-DEC-12 14-DEC-12 active active
14-DEC-12 15-DEC-12 inactive inactive -
Hi could u please assist me as to how to use a decode function in a control file for sql loader to replace a certain row with datatype DATE...
OPTIONS (DIRECT=TRUE) UNRECOVERABLE
LOAD data REPLACE
PRESERVE BLANKS INTO TABLE <tablename> FIELDS TERMINATED BY "Ï" TRAILING NULLCOLS
date_field DATE DECODE(:date_field,0,"01/01/1900")
Is what I have done correct.
Please assist.
What abt the remaining rows which have different values, will those be taken as is...
Thanks
Mairahi Jens,
I did try as u suggested but I'm getting the folowing error.
Record 1: Rejected - Error on table <tablename>.
ORA-00604: error occurred at recursive SQL level 1
ORA-01841: (full) year must be between -4713 and +9999, and not be 0
Any suggestions.
REgards -
Hi All,
There is a Amount column in my table contain both credit(-amount) and debit(+amount) ,i hv to split this Amount in two column of positive amount(debit) and negative amount (credit) as i am using decode function to get output but i am unable to get , can anyone help how to write the decode function.
Thanks...Hi,
Something like this,
SQL> With t As(select -29 amount from dual union all
2 select 5 amount from dual union all
3 select -10 amount from dual)
4 SELECT Amount
5 , Decode(Sign(amount), 1,Amount) As Debit
6 , Decode(Sign(amount),-1,Amount) As Credit
7 FROM t;
AMOUNT DEBIT CREDIT
-29 -29
5 5
-10 -10or
SQL> With t As(select -29 amount from dual union all
2 select 5 amount from dual union all
3 select -10 amount from dual)
4 SELECT Amount
5 , Decode(sign(amount),1,'Debit',-1,'Credit') Amount
6 FROM t;
AMOUNT AMOUNT
-29 Credit
5 Debit
-10 CreditRegards,
Christian Balz
Edited by: Christian Balz on 16/06/2009 21:36 -
SQL Cost of using DECODE built-in
I'm trying to tune some SQL and wondering about the cost of using DECODE. I believe that by using this function, it prevents any index on the related column from being used.
Do any "Tuning Gurus" have opinions on the use of DECODE?
TIA,As a general rule, the Oracle built-in functions are pretty fast to execute. You will not really see any difference in performance between a sql statement using a built-in function in the SELECT clause, and one not using one.
However, a lot depends on where and how you use the DECODE.
SELECT col1,DECODE(col2,1,'YES',2,'NO',3,'MAYBE')
FROM table
will be no slower than
SELECT col1,col2
FROM table
If there is an index on col2, then
SELECT col1,DECODE(col2,1,'YES',2,'NO',3,'MAYBE')
FROM table
WHERE col2 BETWEEN 1 AND 3
will use it. However
SELECT col1,col2
FROM table
WHERE DECODE(col2,1,'YES',2,'NO',3,'MAYBE') IN ('YES','NO','MAYBE')
will not (unless you have a function based index). But,
SELECT col1,col3
FROM table
WHERE col2 BETWEEN 1 and 3 and
col3 = DECODE(col2,1,'YES',2,'NO',3,'MAYBE') IN ('YES','NO','MAYBE')
will.Note that "will" in the above really means can. it is up to the optimizer whether it actually is used or not.
HTH
John -
Problem with URLDecoder.decode(s, enc)
Hi!
I'm having problems with the URLDecoder.decode(s, enc) method... When I send a string, encoded with the Javascript escape() function, to the server side of my application, I get a problem decoding it using this:
myString = URLDecoder.decode(myString, "iso-8859-1");It gives me this error: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "u2"
My html defines the encoding as follows:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />The string being submitted contains a special apostrophe ( ' ) copy/pasted from MS Word wich then translates it as %u2019 (what's that??? Unicode???).
Can anyone tell me what is happening? How can I encode / decode this properly?I'm having exactly the same issue.
Did you solved the problem?
Regards,
Gabriel -
Hi,
How to convert this decode statements into CASE WHEN syntax
phone_v := DECODE (c_rec.phone, NULL, NULL, DECODE ( is_it_number (c_rec.phone), 'F', DBMS_RANDOM.STRING ('a', LENGTH (c_rec.phone)), SUBSTR (DBMS_RANDOM.VALUE, 2, LENGTH (c_rec.phone))));
thanks, BcjThat should be easiest written like the following :
phone_v := DECODE (c_rec.phone
, NULL, NULL
, DECODE ( is_it_number (c_rec.phone)
, 'F', DBMS_RANDOM.STRING ('a', LENGTH (c_rec.phone))
, SUBSTR (DBMS_RANDOM.VALUE, 2, LENGTH (c_rec.phone))
);Is it ?
Nicolas.
Maybe you are looking for
-
In 5.0 URL does not show in location bar when I am using a second Firefox window
I have a lot of problems when using a second window for Firefox 5.0. (I have two monitors and like an open browser on each.) One problem is that when I open a new tab, the URL of a site that I go to does not show in the location bar. It just says "Go
-
How to embed URL (Longer than 60 Chars) into CRM-Web UI
Hello i would like to have a textfield with an URL embeded into the Incident UI So far i managed to create the Char-Field and fill it with the URL Unfortunately the generated Fields are limited to 60 Chars, but i need 100 for the URL with all paramet
-
I have some Chinese songs, titles of which are displayed as garbage. Recent additions show Chinese characters. Anyway to fix this.
-
How to quick import Tags from a xml file?
Good morning/afternoon/night everyone. I have this client that want me to import something like 1000 tags from a xml file in CQ5.5. I know I can do it programatically and in dev.day.com I have already found some instructions, but, there is some ea
-
Hi , i'am a beginner.i'am in the initial stages of my carrer in mobile industry. i'am well versed in java. i want to learn J2ME.i'am unable to know the starting point. Anyone, please guide me how to start off with learning J2ME. desperately waiting f