SQLLoader: Using decode
Hi,
I'm having some trouble getting a decode function to work in
my .ctl file. Any help or suggestions? Thx much!
LOAD DATA
INFILE 'c:\test\prodrate.dat'
INTO TABLE prodrate_delete
WHEN ACT_STATUS = '9'
( DIR_CODE POSITION(01:06) ,
DIR_VER POSITION(07:11) ,
PROD_CODE POSITION(12:16) ,
RESERVED POSITION(17:28) ,
TIER_CRIT_CODE POSITION(29:30) ,
TIER_NUM POSITION(31:32) ,
RATE POSITION(33:47) ,
PROD_RATE_LOCK_INDICT POSITION(48:48) ,
DECODE (PROD_RATE_LOCK_DATE, "00000000", "01011900") POSITION
(49:56) DATE "MMDDYYYY"),
TRIAL_INDICT POSITION(57:57) ,
PROD_SELL_INDICT POSITION(58:58) ,
EXPIRE_DATE POSITION(59:66)
DATE "MMDDYYYY",
LATE_UPDATE POSITION(67:74)
DATE "MMDDYYYY",
ACT_STATUS POSITION(75:75)
Brian
Try using the decode like this
prod_rate_lock_date position (49:56) DATE "MMDDYYYY" "decode
(:prod_rate_lock_date,"00000000","01011900",:prod_rate_lock_date)
HTH
Similar Messages
-
Use DECODE in sqlloader with DIRECT=TRUE?
hi.. i have this .ctl
load data
infile 'invoice.dat'
APPEND
into table INVOICE_TMP1
when (43:50)='RIN4331'
bill_date position(1:8) DATE 'YYYYMMDD'
,acct_no position(9:22)
,bill_period position(51:52)
,due_date position(139:146) DATE 'YYYYMMDD' "decode(:due_date,00000000,null,:due_date)"
,last_bill_amt position(84:94) DECIMAL EXTERNAL
,sys_appl_id CONSTANT "CTLA"
i have to use DIRECT=TRUE because my .dat file contains large file (about 17 million records)
my problem now is because i use direct=true, so i cannot use decode because it is in SQL string. My data for due_date maybe contains 00000000 for datatype date. that is why i have to use decode.
How to solve my problem?
please help ASAP.
TQ.Duplicate post
Re: Using DIRECT=TRUE in SQLLOADER -
I need to know if there is any way to use a range of values from
database and decode to certain text. I am able to do with one
value.
for example:
DECODE(column_name,'216767111','Unlimited',column_name)
above argument works with one value only. How about a range,
ex: 216767000 to 216767111. I need to use only SQL. No PL/SQL.
Kinldly need some body's help
Thanks
MunisWhich version of the database? If it's 8i+ then you can use
the CASE function
for example:
(CASE WHEN column_name between 216767000 and 216767111
THEN 'Unlimited' ELSE column_name END)
This won't work in PL/SQL because they're introducing a CASE
statement does soemthing different.
rgds, APCHello Andrew
Thank you for response. I am using 8i. 8.1.6. However using
CASE, I get inconsistent data type, ORA-00932: inconsistent
datatypes. I able to work it out with other response using
DECODE(sign(. Do you have any idea why i am getting this error.
If time permits, let me know -
How to use decode function in oracle apex 3.2.1
Hello Friends,
how to use decode
var_decode := 'decode'||'('|| var1 ||','|| -800000000000000||','||'.A'||','||
appreciate your help.
regards/kumar
Edited by: kumar73 on Apr 23, 2010 12:25 PM
Edited by: kumar73 on Apr 23, 2010 12:27 PMHey just on this particular point, there's a handy PL/SQL method for escaping quotation characters which may reduce the complexity of the string.
For example, if I had a string:
I can't understand why quoting my 'quote' characters never seems to "work"!and I wanted to pass that into a variable, I could do this:
vc_foo:= 'I can''t understand why my ''quote'' characters never seems to "work"!';or I could use the q function, whereby you enclose your string within a quote delimiter of your choice, like so:
vc_foo:= q'^I can't understand why quoting my 'quote' characters never seems to "work"!^';
note: I used the caret (^) character by convention but any valid character will do
...all of which leaves your original string more or less unadulterated.
I find this particularly useful for generating dynamic SQL and dynamic PL/SQL, as it leave the query looking a tad more readable, although if you are chaining together multiple strings with double-pipes, it can make it a little muddier. I find it particularly useful if I'm going to deal with string data from, for example, a field with Irish-derived surnames such as "O'Reilly"...
Give it a go! -
How to use DECODE function in Exspression?
Hi,
Can we use DECODE in Expression?
I'm trying to use DECODE function but there is an error during the validation. But when i validate the mapping, it is successfully compiled but it is failed during deployment.
But if I use CASE instead of DECODE, it works fine.
Can we use DECODE in OWB???
Thanks
RajHi,
In OWB 10gR2, if your are using only one DECODE in an expression, it's working. The package will compile when deploying the mapping. OWB will replace the DECODE by a CASE.
But when you are using nested decode in an expression ( for example : decode(col1, 1, 'M', decode(col2, 'Madame', 'Mme', null)) ) only the first one is replaced by a case at deployment.
In ROW_BASED mode, text of the expression is used outside of an sql statement and deployment will fails with "PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only."
If operating mode for the mapping is set to SET_BASED, it's working because the expression is used in an sql statement.
I have logged a SR in metalink for this issue and a bug is opened (bug 5414112).
But I agree with you, it's better to use case statement.
Bernard -
Hi all
We can use decode function in the Select columns as well as Group by Columns as well as Having Clause
Can we use decode function in the where clause also. If yes can u give small sample
Suresh Bansal""DECODE in the WHERE clause"
http://psoug.org/reference/decode_case.html
WHERE empid = DECODE(posn,
0, st.areadir,
1, st.areamgr,
2, NVL(st.storemgr1, st.storemgr2),
3, NVL(st.asstmgr1, NVL(st.asstmgr2,
st.asstmgr3))) -
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>
) -
Query to find out sum by using decode or case
Hi, I have data like below and required an output as given below, could you please help me to get the same by using decode / case .....Thanks for your help
INSNAME INSID STATUS
AAA 1000 Scheduled
AAA 1000 Processing
BBB 1001 Inspector
BBB 1001 Scheduled
BBB 1001 Processing
BBB 1001 Inspector
CCC 1002 Scheduled
CCC 1002 Processing
CCC 1002 Inspector
CCC 1002 Scheduled
CCC 1002 Processing
CCC 1002 Inspector
Required Output...
INSNAME INSID sum_of_scheduled sum_of_Processing sum_of_Inspector
AAA 1000 1 1 0
BBB 1001 1 1 2
CCC 1002 2 2 2And if you want it with CASE statement:
WITH test_table AS
SELECT 'AAA' insname, 1000 insid, 'Scheduled' status FROM DUAL UNION ALL
SELECT 'AAA' insname, 1000 insid, 'Processing' status FROM DUAL UNION ALL
SELECT 'BBB' insname, 1001 insid, 'Inspector' status FROM DUAL UNION ALL
SELECT 'BBB' insname, 1001 insid, 'Scheduled' status FROM DUAL UNION ALL
SELECT 'BBB' insname, 1001 insid, 'Processing' status FROM DUAL UNION ALL
SELECT 'BBB' insname, 1001 insid, 'Inspector' status FROM DUAL UNION ALL
SELECT 'CCC' insname, 1002 insid, 'Scheduled' status FROM DUAL UNION ALL
SELECT 'CCC' insname, 1002 insid, 'Processing' status FROM DUAL UNION ALL
SELECT 'CCC' insname, 1002 insid, 'Inspector' status FROM DUAL UNION ALL
SELECT 'CCC' insname, 1002 insid, 'Scheduled' status FROM DUAL UNION ALL
SELECT 'CCC' insname, 1002 insid, 'Processing' status FROM DUAL UNION ALL
SELECT 'CCC' insname, 1002 insid, 'Inspector' status FROM DUAL
SELECT insname
,insid
,SUM(CASE WHEN status = 'Scheduled'
THEN 1
ELSE 0
END
) sum_of_scheduled
,SUM(CASE WHEN status = 'Processing'
THEN 1
ELSE 0
END
) sum_of_processing
,SUM(CASE WHEN status = 'Inspector'
THEN 1
ELSE 0
END
) sum_of_inspector
FROM test_table
GROUP BY insname
,insid;
Regards
Arun -
Using decode function without negative values
Hi friends
I am using oracle 11g
I have at doubt regarding the following.
create table Device(Did char(20),Dname char(20),Datetime char(40),Val char(20));
insert into Device values('1','ABC','06/13/2012 18:00','400');
insert into Device values('1','abc','06/13/2012 18:05','600');
insert into Device values('1','abc','06/13/2012 18:55','600');
insert into Device values('1','abc','06/13/2012 19:00','-32768');
insert into Device values('1','abc','06/13/2012 19:05','800');
insert into Device values('1','abc','06/13/2012 19:10','600');
insert into Device values('1','abc','06/13/2012 19:15','900');
insert into Device values('1','abc','06/13/2012 19:55','1100');
insert into Device values('1','abc','06/13/2012 20:00','-32768');
insert into Device values('1','abc','06/13/2012 20:05','-32768');
Like this I am inserting data into table for every 5 minutes Here i need the result like
output:
Dname 18:00 19:00 20:00
abc 400 -32768 -32768
to retrieve this result i am using decode function
SELECT Dname,
MAX(DECODE ( rn , 1,val )) h1,
MAX(DECODE ( rn , 2, val )) h2,
FROM
(SELECT Dname,Datetime,row_number() OVER
(partition by Dname order by datetime asc) rn FROM Device
where substr(datetime,15,2)='00' group by Dname.
According to above data expected result is
Dname 18:00 19:00 20:00
abc 400 600(or)800 1100
This means I dont want to display negative values instead of that values i want to show previous or next value.
Edited by: 913672 on Jul 2, 2012 3:44 AMAre you looking for something like this?
select * from
select dname,
datetime,
val,
lag(val) over (partition by upper(dname) order by datetime) prev_val,
lead(val) over (partition by upper(dname) order by datetime) next_val,
case when nvl(val,0)<0 and lag(val) over (partition by upper(dname) order by datetime) >0 then
lag(val) over (partition by upper(dname) order by datetime)
else
lead(val) over (partition by upper(dname) order by datetime)
end gt0_val
from device
order by datetime
where substr(datetime,15,2)='00';Please take a look at the result_column gt0_val.
Edited by: hm on 02.07.2012 04:06 -
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 -
How to use decode to calculate sum for different date range
I'm stuck with decode() function:
I have a table like this:
(project_id, approve_date, value, builder_code)
I want to write a SQL query to get sum of values for different month of the approve_date, and group by builder_code)
The result is like this:
builder_code Sum(value)_Sep-03 Sum(value)_Oct-03 Sum(value)_Nov03
1001 1,299 1,322 990
1002 3,332 1,222 333
I tried to use decode for this question but could not get the answer.
Thanks a lotI don't think you need a DECODE() here. I'd do something like this-
create table builder (
project_id number,
approve_date date,
value number,
builder_code number
insert into builder values( 1, to_date('09-01-2003', 'MM-DD-YYYY'), 100, 990 )
insert into builder values( 2, to_date('09-03-2003', 'MM-DD-YYYY'), 150, 990 )
insert into builder values( 3, to_date('09-05-2003', 'MM-DD-YYYY'), 250, 990 )
insert into builder values( 3, to_date('09-05-2003', 'MM-DD-YYYY'), 250, 333)
SELECT sept.builder_code, sept.sept_sum, oct.oct_sum
FROM (SELECT builder_code, sum(value) sept_sum
FROM builder
WHERE approve_date >= to_date('09-01-2003','MM-DD-YYYY')
AND approve_date < to_date('10-01-2003','MM-DD-YYYY')
GROUP BY builder_code) sept,
(SELECT builder_code, sum(value) oct_sum
FROM builder
WHERE approve_date >= to_date('10-01-2003','MM-DD-YYYY')
AND approve_date < to_date('11-01-2003','MM-DD-YYYY')
GROUP BY builder_code) oct
WHERE oct.builder_code(+) = sept.builder_code
BUILDER_CODE SEPT_SUM OCT_SUM
333 250
990 500Justin
Distributed Database Consulting, Inc.
www.ddbcinc.com/askDDBC -
Hello,
i have question regarding PL/SQL using DECODE when i use following qurey in SQL plus it is working fine but when i try to run in tode it only display value of g.
everything else is blank........
so can u plz assist me on that .....
thanks in advance!!!!!!!!!!
SELECT
b.g,b.s,
COUNT(DECODE(a.u,'R',a.rep)) AS R,
COUNT(DECODE(a.u,'u',a.rep)) AS U,
COUNT(DECODE(a.u,'C',a.rep))AS C,
COUNT(DECODE(a.u,'I',a.rep)) AS I,
COUNT(DECODE(a.u,NULL,a.rep)) AS B
FROM AREA a, data b
WHERE a.rep = '454637'
AND a.rep = b.emp
GROUP BY b.g,b.sVery strange.
Find out if there are alterations to your SQL*PLUS envirionment. Warren mentioned user/database wierdness; the ALTER SCHEMA and other commands can affect privilges and what objects you can see. Sometimes these commands are buried in LOGIN.SQL and GLOGIN.SQL files (for SQL*PLUS), and more hard to find they can call files buried on a network somewhere.
Try the query without the DECODE() and see what's in the table without trying to modify the values in both envirionments. -
Hello Friends,
I have a query that has different columns and I am not sure what the data type of each column is ...
I want to use decode function which displays the following if the value of the column is like this ..
if the value of column is -714E ie -700000000000000 then display as .A
if the value of column is -814E ie -800000000000000 then display as .B
NOTE ; don't know which column is having the value - and i don't know the data type of the column is ..
got to use the decode function for all the columns selected ..
I want to use decode function pls let me know how to write for this kind of requirement.
appreciate your help in this rgds.
thanks/kumarDear Sir / Madam,
Thanks for your understanding.
Right now I am facing a unique problem.
I am using decode function in a select statement. The columns are dynamic some columns are of type number and some are varchar datatypes. I want to apply decode function for every column irrespective of datatype.
What i am finding difficult is if the column is a number datatype , the decode funciton is working good but if the column datatype is varchar or char datatype then i am getting ..
here's the decode function..
decode (CHAI.EVNDRIVE,
-800000000000000,'.A',
-700000000000000, '.B',
-600000000000000 ,'.C',
-500000000000000 , '.D',
-400000000000000 , '.E',
-300000000000000 , '.F',
-200000000000000, '.G',
-100000000000000 , '.H',
-1000000000, '.R' ,CHAI.EVNDRIVE ) EVNDRIVE
report error:
ORA-01722: invalid number
pls let me know how to over come this kind of scenario.
is their a way to find whether the column datatype is number or char , so that i can check the column datatype before the decode funciton is applied ..
thanks ..
kumar -
Using Decode in where clause in free hand sql
Hi,
I want to use decode in free hand sql.
for eg : this is a where condition
Outlet_Lookup.City = @variable('Enter City')
Requirement :
if we put the user prompt as "Enter City and % for all cities"
and the user enters % then the data display should be all cities or else it shld be the specific city entered in the prmpt..
Can we do that using Decode statement,
I have tried
Outlet_Lookup.City = Decode(@variable('Enter City'),'%',Outlet_Lookup.City,(@variable('Enter City')))
This is not working....
Pls guide on the same..
Thanks.Hi Mathieu,
Thanks for the solution,
I tried the following
((Outlet_Lookup.City = @variable('Enter City or % for All') or @variable('Enter City or % for All')='%'))
This is working fine....
Thanks
Regards,
Aparna. -
Using 'DECODE' instead of 'CASE' in select
Hi,
I am using CASE statements in my Select clause using 9i.
SELECT
CASE
WHEN S.cmpy_num = S.cpty_borg_num THEN
''OURS''
ELSE
''THEIRS''
END AS SDIOwner,
S.active_flag,
from SDI sI wud like to try this in 8I but 8i doesnt support CASE statements
in Select clauses.
It was recommended to use Decode in place of CASE in 8I
How can i write the decode statement for the above CASE statement in 9IGOT IT RUNNIG.THANKS A LOT JAMES...
I AM TESTING SYSTEMS ON 9I AND 8I...
Maybe you are looking for
-
Why I am buying a new MacBook Pro now, but, first, any major issues?
With the delay of Ivy Bridge, and with my personal view that the next generation of MacBook Pro notebooks will be dropping FireWire 800 to service a better design, I have decided to purchase a new MacBook Pro now. I just cannot imagine the new notebo
-
DOwnload finished but got X RedCircle Runtime Error! PROGRAM: C:\Program Files(x86)\iTunes\iTunes.exe R6034 An application has made an attempt to load the C runtime library incorrectly. Need Support Team to give Resolution to me and others? I have do
-
HP Mini 110-3150CA - RAM Upgrade?
I just picked up a HP Mini 110-3150CA - I have 1gb Ram - But I would like to upgrade to 2GB ram -- can this be done? And what type of Ram do I buy?
-
I have a h67ma-e35 mainboard with a I5-2500K CPU and I wan't to overclock, but it seems to be impossible to do so on this mainboard. Whenever I put the cpu on a higher mulitplyer and reboot it always reverts back to the old multiplyer and thereby und
-
Process Order Blending Solution
Hi , Is anybody have experience on process order blending scenario ? For example : We produce 5 different batch finish goods Now we want to blend those 5 different batch into 1 batch Thanks for help !