473,387 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Strange problem after use coalesce()

hi, we are using db2 v8.2 EE on windows, with jcc driver. try to create
a join view, after that i check the syscat.columns table, for those
decimal field use COALESCE method, all the length become 11 instead of
the actual length of the field inside table, can anyone explain this to
me ? thank you

create view ML101PD.ARJMBAL1 (ARNM05, ARNO01, ARNM01, ARNO07, ARNO08,
ARNO09, ARFL17, ARFL03, ARMO12, ARDY12, ARCC12, ARYR12, ARNO15,
systimestamp, loginname, id ) as select ML101PD.ARPMCUS.ARNM05,
ML101PD.ARPMCUS.ARNO01, ML101PD.ARPMCUS.ARNM01, ML101PD.ARPMCUS.ARNO07,
ML101PD.ARPMCUS.ARNO08, ML101PD.ARPMCUS.ARNO09,
COALESCE(ML101PD.ARPMBAL.ARFL17, ' '), COALESCE(ML101PD.ARPMBAL.ARFL03,
' '), COALESCE(ML101PD.ARPMBAL.ARMO12, 0),
COALESCE(ML101PD.ARPMBAL.ARDY12, 0), COALESCE(ML101PD.ARPMBAL.ARCC12,
0), COALESCE(ML101PD.ARPMBAL.ARYR12, 0),
COALESCE(ML101PD.ARPMBAL.ARNO15, 0), ML101PD.ARPMBAL.systimestamp,
ML101PD.ARPMBAL.loginname, COALESCE(ML101PD.ARPMCUS.id,
ML101PD.ARPMBAL.id ) from ML101PD.ARPMCUS left join ML101PD.ARPMBAL on
ML101PD.ARPMCUS.ARNO01 = ML101PD.ARPMBAL.ARNO01 where
((ML101PD.ARPMBAL.ARFL03='Y')) and ((ML101PD.ARPMBAL.ARFL17<>'C'))

Nov 1 '06 #1
10 3828
Looks like this is the default behavior. From page 115 of volume 1 of
the SQL Reference:

Operand 1: DECIMAL(w,x)
Operand 2: DECIMAL(y,z)
Result: DECIMAL(p,s) where p = max(x,z)+max(w-x,y-z)1s = max(x,z)

Perhaps an RTRIM is in order.

--Jeff

db2group88 wrote:
hi, we are using db2 v8.2 EE on windows, with jcc driver. try to create
a join view, after that i check the syscat.columns table, for those
decimal field use COALESCE method, all the length become 11 instead of
the actual length of the field inside table, can anyone explain this to
me ? thank you

create view ML101PD.ARJMBAL1 (ARNM05, ARNO01, ARNM01, ARNO07, ARNO08,
ARNO09, ARFL17, ARFL03, ARMO12, ARDY12, ARCC12, ARYR12, ARNO15,
systimestamp, loginname, id ) as select ML101PD.ARPMCUS.ARNM05,
ML101PD.ARPMCUS.ARNO01, ML101PD.ARPMCUS.ARNM01, ML101PD.ARPMCUS.ARNO07,
ML101PD.ARPMCUS.ARNO08, ML101PD.ARPMCUS.ARNO09,
COALESCE(ML101PD.ARPMBAL.ARFL17, ' '), COALESCE(ML101PD.ARPMBAL.ARFL03,
' '), COALESCE(ML101PD.ARPMBAL.ARMO12, 0),
COALESCE(ML101PD.ARPMBAL.ARDY12, 0), COALESCE(ML101PD.ARPMBAL.ARCC12,
0), COALESCE(ML101PD.ARPMBAL.ARYR12, 0),
COALESCE(ML101PD.ARPMBAL.ARNO15, 0), ML101PD.ARPMBAL.systimestamp,
ML101PD.ARPMBAL.loginname, COALESCE(ML101PD.ARPMCUS.id,
ML101PD.ARPMBAL.id ) from ML101PD.ARPMCUS left join ML101PD.ARPMBAL on
ML101PD.ARPMCUS.ARNO01 = ML101PD.ARPMBAL.ARNO01 where
((ML101PD.ARPMBAL.ARFL03='Y')) and ((ML101PD.ARPMBAL.ARFL17<>'C'))
Nov 1 '06 #2
so you do rtrim(COALESCE(ML101PD.ARPMBAL.ARMO12, 0))?

Nov 1 '06 #3
rtrim() is for string, how it works for decmial field? thanks

Nov 1 '06 #4
db2group88 wrote:
so you do rtrim(COALESCE(ML101PD.ARPMBAL.ARMO12, 0))?
CAST the 0 to the type of ML101PD.ARPMBAL.ARMO12. That should do it.
COALESCE(ML101PD.ARPMBAL.ARMO12, CAST(0 AS <..>))

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Nov 1 '06 #5
i tried, and the length become from 11 to 5, but the actual field
armo12 in table arpmbal is 2.

Serge Rielau wrote:
db2group88 wrote:
so you do rtrim(COALESCE(ML101PD.ARPMBAL.ARMO12, 0))?
CAST the 0 to the type of ML101PD.ARPMBAL.ARMO12. That should do it.
COALESCE(ML101PD.ARPMBAL.ARMO12, CAST(0 AS <..>))

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Nov 1 '06 #6
db2group88 wrote:
i tried, and the length become from 11 to 5, but the actual field
armo12 in table arpmbal is 2.
Can you clarify what you mean by length?
DECIMAL has scale and precision.
Which output are you looking at?
Can you post a complete example illustrating the problem? Including
CREATE TABLE and whatever you use to show the (bad) result.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Nov 1 '06 #7
length is the column name for syscat.columns, our application need to
get the info to initialize the field properly,

here is the row i get from this table for the field ARMO12 with
tabname='ARPMBAL'

ML101PD ARPMBAL ARMO12 64 SYSIBM DECIMAL 2 0 Y 0 0 3 0 -1

2 is the length of the field.

the way i create the view is create view ML101PD.ARJMBAL1 (ARNM05,
ARNO01, ARNM01, ARNO07, ARNO08, ARNO09, ARFL17, ARFL03, ARMO12, ARDY12,
ARCC12, ARYR12, ARNO15, systimestamp, loginname, id ) as select
ML101PD.ARPMCUS.ARNM05, ML101PD.ARPMCUS.ARNO01, ML101PD.ARPMCUS.ARNM01,
ML101PD.ARPMCUS.ARNO07, ML101PD.ARPMCUS.ARNO08, ML101PD.ARPMCUS.ARNO09,
COALESCE(ML101PD.ARPMBAL.ARFL17, ' '), COALESCE(ML101PD.ARPMBAL.ARFL03,
' '), COALESCE(ML101PD.ARPMBAL.ARMO12, 0),
COALESCE(ML101PD.ARPMBAL.ARDY12, 0), COALESCE(ML101PD.ARPMBAL.ARCC12,
0), COALESCE(ML101PD.ARPMBAL.ARYR12, 0),
COALESCE(ML101PD.ARPMBAL.ARNO15, 0), ML101PD.ARPMBAL.systimestamp,
ML101PD.ARPMBAL.loginname, COALESCE(ML101PD.ARPMCUS.id,
ML101PD.ARPMBAL.id ) from ML101PD.ARPMCUS left join ML101PD.ARPMBAL on
ML101PD.ARPMCUS.ARNO01 = ML101PD.ARPMBAL.ARNO01 where
((ML101PD.ARPMBAL.ARFL03='Y')) and ((ML101PD.ARPMBAL.ARFL17<>'C'))

after i create the view, do the query on the syscat.columns with
tabname='ARJMBAL1'

ML101PD ARJMBAL1 ARMO12 8 SYSIBM DECIMAL 11 0 Y 0

you can see the field length is 11 instead of 2.

Nov 1 '06 #8
You'd cast your argument to RTRIM as a string, e.g.,
RTRIM(CHAR(your_value_expression)).

db2group88 wrote:
rtrim() is for string, how it works for decmial field? thanks
Nov 1 '06 #9
here is the row i get from this table for the field ARMO12 with
tabname='ARPMBAL'

ML101PD ARPMBAL ARMO12 64 SYSIBM DECIMAL 2 0 Y 0 0 3 0 -1

2 is the length of the field.

the way i create the view is create view ML101PD.ARJMBAL1 (ARNM05,
....., ARMO12, ....) as select
ML101PD.ARPMCUS.ARNM05, .....
, COALESCE(ML101PD.ARPMBAL.ARMO12, 0),
....) from ML101PD.ARPMCUS left join ML101PD.ARPMBAL on
ML101PD.ARPMCUS.ARNO01 = ML101PD.ARPMBAL.ARNO01 where
((ML101PD.ARPMBAL.ARFL03='Y')) and ((ML101PD.ARPMBAL.ARFL17<>'C'))

after i create the view, do the query on the syscat.columns with
tabname='ARJMBAL1'

ML101PD ARJMBAL1 ARMO12 8 SYSIBM DECIMAL 11 0 Y 0

you can see the field length is 11 instead of 2.
My guess is as followings.
In the view, column ARMO12 is defined as
COALESCE(ML101PD.ARPMBAL.ARMO12, 0).
Data types of arguments are DEC(2,0) ("ARMO12") and INTEGER ("0").
Result of data type of COALESCE will be promoted highest precedence.
DECIMAL is precedent to INTEGER. So, INTEGER will promoted DEC(11,0).
Consequently, COALESCE(DEC(2,0), INTEGER) =COALESCE(DEC(2,0),
DEC(11,0)) =Result data type is DEC(11,0)

Please refer P94 Table 7. Data Type Precedence Table, P113-5 Rules for
result of data type and Function COALESCE in SQL Reference Vol1.

Nov 2 '06 #10
Easiest way to keep precision may be.....
COALESCE(ML101PD.ARPMBAL.ARMO12, 0.)
[Add dot(".") to 0]

Nov 2 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Dave | last post by:
Hi all, I've been trying to figure this out for the last day and a half and it has me stumped. I've got a web application that I wrote that keeps track of trading cards I own, and I'm moving it...
2
by: Jeff Roughgarden | last post by:
I am using a clever product called SQL Expert Pro to optimize problematic SQL statements. It works by generating syntactically identical variations of the original SQL, finding all unique execution...
3
by: Steffen Vulpius | last post by:
Hi everybody, VARCHAR has a higher precedence than CHAR. If you have a query SELECT COALESCE(c1,c2) FROM T1 where c1 is CHAR(5) and c2 is VARCHAR(10), I would expect the return type to be...
4
by: Andrei Ivanov | last post by:
Hello, I have 2 tables: CREATE TABLE products ( id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL ); CREATE TABLE products_daily_compacted_views ( product ...
5
by: John Greve | last post by:
Any ideas on why my the result 'green' row column DELTA does not yield -1 for? That is not how I expected COALESCE( ... ) to work. Every other row for DELTA (including 'black') comes out the...
1
by: Bob Stearns | last post by:
Please explain tome why the third row of my result is not the fourth row. In most Western alphabets 'dd'>'c'. SELECT t1.*, lot_numb, lot_suffix, part_of_lot_numb, part_of_lot_suffix, CASE...
6
by: db2group88 | last post by:
hi , i am trying to create such sql on db2 v8.2 on windows. create view AP (APAM32, APNO20, APQY05, pocd01) as select APP1.APAM32, APP1.APNO20, APP1.APQY05, COALESCE(POPT.POCD01, ' ') from APP1...
4
by: Don | last post by:
If I have an SQL query which returns an aggregate of several decimal fields like so: (sum(COALESCE(myDecimal1, 0)+ sum(COALESCE(myDecimal2, 0)+ sum(COALESCE(myDecimal3, 0)) as MyTotal I get...
1
by: r035198x | last post by:
This is a short tip describing the sql coalesce function. Description COALESCE accepts a comma separated list of parameters and returns the first value that is not null in that list or null...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.