If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2 UDF (Oracle, MSSQL)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-02-03, 08:45
KontinMonet KontinMonet is offline
Registered User
 
Join Date: Dec 2003
Posts: 1
DB2 UDF (Oracle, MSSQL)

I must be looking in all the wrong places whether IBM manuals, online Help or on the Net....

I create a scalar UDF such as:

create function one()
returns integer
return 1

Now, in MS SQL or Oracle, I can then enter a SQL statement such as:

SELECT one(); or SELECT one() from DUAL; and I get the number "1" returned as one row but I can't seem to get the equivalent in DB2.

If I try my UDF - or a system scalar function, for example:

select tan(1.5) from syscat.functions

I get the answer hundreds of times (it's probably not the right way then...)

Can anybody tell me the equivalent in DB2? The documentation always refers to some user defined table somewhere. Thanks...
Reply With Quote
  #2 (permalink)  
Old 12-02-03, 09:03
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Re: DB2 UDF (Oracle, MSSQL)

Quote:
Originally posted by KontinMonet
I must be looking in all the wrong places whether IBM manuals, online Help or on the Net....

I create a scalar UDF such as:

create function one()
returns integer
return 1

Now, in MS SQL or Oracle, I can then enter a SQL statement such as:

SELECT one(); or SELECT one() from DUAL; and I get the number "1" returned as one row but I can't seem to get the equivalent in DB2.

If I try my UDF - or a system scalar function, for example:

select tan(1.5) from syscat.functions

I get the answer hundreds of times (it's probably not the right way then...)

Can anybody tell me the equivalent in DB2? The documentation always refers to some user defined table somewhere. Thanks...
When you execute

select tan(1.5) from syscat.functions

you, obviously, receive the value of tangent for each row in syscat.functions, which may well be in the hundreds.

There is an equivalent of Oracle's DUAL table in DB2; its name is "SYSIBM.SYSDUMMY1". It only contains one row; as a result,

SELECT TAN(1.5) FROM SYSIBM.SYSDUMMY1

will return only one row. Another way to get the same result would be

VALUES(TAN(1.5))
Reply With Quote
  #3 (permalink)  
Old 12-02-03, 09:05
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Your problem is that you need a table with only one row so that your result set has only one row. IBM provides just such a table: sysibm.sysdummy1

try:

select tan(1.5) from sysibm.sysdummy1

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On