Jump to content

[SOLVED] Comparing different type columns


Recommended Posts

I have the following two tables:

funding(FundingID number, Name varchar);

programs(PID number, Funding varchar);

 

In MySQL I can use "WHERE p.Funding = f.FundingID" even though they are different types. This also works in Oracle as long as the varchar column actually holds a number, but if there is a string I get the error:"SQL error: [Oracle][ODBC][Ora]ORA-00918: column ambiguously defined , SQL state S1000 in SQLExecDirect"

 

This is the actual query:

"SELECT f.NAME FROM funding f LEFT JOIN programs p ON p.FUNDING = f.FUNDINGID WHERE p.PID = 7")

 

I tried to cast the varchar column as number and tried to_number function, but neither changed anything. Does anyone know of a way I can get around this? Even just suppressing the error would work because I want it to be null if there is no match, but it would have to actually return a result.

Link to comment
Share on other sites

Well, I figured out a way around it:

"SELECT DECODE(replace(translate(p.FUNDING,'1234567890','##########'),'#'),NULL,(SELECT f.NAME FROM funding f WHERE f.FUNDINGID = p.FUNDING),p.FUNDING) as testing FROM programs p"

 

It seems a bit ridiculous, but it works.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.