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 > What's Wrong ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-12-11, 17:11
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Thumbs down What's Wrong ?

I want create SQL UDF function (V9 z/os):

Code:
CREATE FUNCTION RandInt(Core Int)
RETURNS integer 
contains SQL 
NO EXTERNAL ACTION 
not DETERMINISTIC 
RETURN 
Select Integer(RandInt.Core * Rand()) FROM sysibm.sysdummy1
;
Instead of function I have a message together with sqlcode = -104:

Quote:
SQL0104N An unexpected token "INTEGER" was found following "". Expected tokens may include: "SOURCE PARAMETER STOP INHERIT RETURNS CALLED ALLOW CONTAINS". SQLSTATE=42601

State:42601,Native:-104,Origin:[IBM][CLI Driver][DB2]
Can somebody explain me where I have made mistake ?

Thanks, Lenny

Last edited by Lenny77; 07-12-11 at 17:14.
Reply With Quote
  #2 (permalink)  
Old 07-12-11, 17:17
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Although I don't know the relationship with the message,
I think that contains SQL should be READS SQL DATA.

Last edited by tonkuma; 07-12-11 at 17:20.
Reply With Quote
  #3 (permalink)  
Old 07-12-11, 17:17
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
You are returning a table, not an integer.
Reply With Quote
  #4 (permalink)  
Old 07-12-11, 17:20
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Post Updated

Quote:
Originally Posted by tonkuma View Post
Although I don't know the relationship with the message SQL0214N,
I think that contains SQL should be READS SQL DATA.
This message was the wrong one. I changed it.
Please, read again.
Reply With Quote
  #5 (permalink)  
Old 07-12-11, 17:23
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Cool ...returns table (...)...

Quote:
Originally Posted by n_i View Post
You are returning a table, not an integer.
Where you find the word "TABLE" ?

Nor a Table, nor a Row -- scalar function.

Last edited by Lenny77; 07-12-11 at 17:28.
Reply With Quote
  #6 (permalink)  
Old 07-12-11, 17:28
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
There is not a puzzle, but a real production problem !

Thanks
Reply With Quote
  #7 (permalink)  
Old 07-12-11, 17:29
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
RETURN Integer(RandInt.Core * Rand())
would work with CONTAINS SQL.
Reply With Quote
  #8 (permalink)  
Old 07-12-11, 17:33
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Quote:
Originally Posted by tonkuma View Post
RETURN Integer(RandInt.Core * Rand())
would work with CONTAINS SQL.
That's right. I know that.
But I want to use Select statement on Return clause. What I show to you just the simplest form of the return/select.

Thanks
Reply With Quote
  #9 (permalink)  
Old 07-12-11, 17:42
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
DB2 9 - DB2 SQL - RETURN statement

No select-statement(nor subselect) for returned value.

Quote:
RETURN statement

The RETURN statement is used to return from the routine.

For SQL functions, it returns the result of the function. For an SQL procedure, it optionally returns an integer status value.

Syntax

Code:
>>-+--------+--RETURN--+------------+--------------------------><
   '-label:-'          +-expression-+   
                       '-NULL-------'
Reply With Quote
  #10 (permalink)  
Old 07-12-11, 17:53
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
scalar-fullselect was included in Expressins.

DB2 9 - DB2 SQL - Expressions

DB2 9 - DB2 SQL - Scalar-fullselect

So, try
RETURN (Select Integer(RandInt.Core * Rand()) FROM sysibm.sysdummy1)

And
Quote:
I think that contains SQL should be READS SQL DATA.
Reply With Quote
  #11 (permalink)  
Old 07-12-11, 17:56
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Arrow

Quote:
Originally Posted by tonkuma View Post
scalar-fullselect was included in Expressins.

DB2 9 - DB2 SQL - Expressions

DB2 9 - DB2 SQL - Scalar-fullselect

So, try
RETURN (Select Integer(RandInt.Core * Rand()) FROM sysibm.sysdummy1)
In this case I have had a message which you saw already on the very first screen:
Quote:
SQL0214N An expression in the ORDER BY clause in the following position, or starting with "0" in the "RETURN" clause is not valid. Reason code = "6". SQLSTATE=42822

State:42822,Native:-214,Origin:[IBM][CLI Driver][DB2]
Thanks
Reply With Quote
  #12 (permalink)  
Old 07-12-11, 18:03
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Please see my previous posts.
Quote:
I think that contains SQL should be READS SQL DATA.
Reply With Quote
  #13 (permalink)  
Old 07-13-11, 10:54
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Question DB2 Bug

Quote:
Originally Posted by tonkuma View Post
Please see my previous posts.
I begun with this with the same result:
Quote:
SQL0104N An unexpected token "INTEGER" was found following "". Expected tokens may include: "SOURCE PARAMETER STOP INHERIT RETURNS CALLED ALLOW CONTAINS". SQLSTATE=42601

State:42601,Native:-104,Origin:[IBM][CLI Driver][DB2]
Maybe we have DB2 bug ?

Thanks
Reply With Quote
  #14 (permalink)  
Old 07-13-11, 11:20
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
I thought that
you got SQL0104N by
CONTAINS SQL
and
RETURN SELECT ...

and you got SQL0214N by
CONTAINS SQL
and
RETURN (SELECT ...)

So, my proposal was
READS SQL DATA
and
RETURN (SELECT ...)
Reply With Quote
  #15 (permalink)  
Old 07-13-11, 14:20
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Thumbs down sqlcode = -214

Quote:
Originally Posted by tonkuma View Post
I thought that
you got SQL0104N by
CONTAINS SQL
and
RETURN SELECT ...

and you got SQL0214N by
CONTAINS SQL
and
RETURN (SELECT ...)

So, my proposal was
READS SQL DATA
and
RETURN (SELECT ...)
Code:
CREATE FUNCTION RandInt(Core Int)
RETURNS integer 
reads SQL data
NO EXTERNAL ACTION 
not DETERMINISTIC 
RETURN 
(Select Integer(RandInt.Core * Rand()) FROM sysibm.sysdummy1)
;
But still no success:
Quote:
SQL0214N An expression in the ORDER BY clause in the following position, or starting with "0" in the "RETURN" clause is not valid. Reason code = "6". SQLSTATE=42822

State:42822,Native:-214,Origin:[IBM][CLI Driver][DB2]
Thanks
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