Solved

Trimming a number forces failure on MERGE

Posted on 2011-09-27
5
357 Views
Last Modified: 2012-05-12
Greetings,
With this SQL, (in both select statements, the datatype is number(15,0))
 
SELECT NVL(TRIM(K3A.BSA_ID), 0) as FINANCIAL_INST_BRANCH_SEQ_NUM
FROM CASH_8300_3A K3A
UNION
SELECT 0 AS FINANCIAL_INST_BRANCH_SEQ_NUMB
FROM CTR_1A

Open in new window


I get the following error:
ORA-01790: expression must have same datatype as corresponding expression
01790. 00000 -  "expression must have same datatype as corresponding expression"
*Cause:    
*Action:
Error at Line: 1 Column: 7

Why does TRIM fail the MERGE?  If it's job is to just remove leading zeros, I am not understanding the fail here.
0
Comment
Question by:Evan Cutler
5 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
Comment Utility
Jut like the last question:  TRIM returns a varchar2.

Change to:
NVL(to_number(TRIM(K3A.BSA_ID)), 0)
0
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
Trim removes leading a
nd trailing spaces
Which causes an implicit conversion from number to string
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
>> If it's job is to just remove leading zeros

Not quite what it does.

From the docs:

TRIM enables you to trim leading or trailing characters (or both) from a character string

http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions219.htm#SQLRF06149
0
 
LVL 34

Expert Comment

by:johnsone
Comment Utility
Also, what datatype is BSA_ID?  If it is a NUMBER, there is no need for the trim.
0
 
LVL 9

Author Closing Comment

by:Evan Cutler
Comment Utility
AWESOME...
Thanks Much.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now