473,513 Members | 3,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inline UDF returning a computed string

1 New Member
Hi,

I am new in DB2 8.1 below code works/logic works fine in Oracle, pls find below the inline UDF , the intent of this UDF is to create a string for each child and then return the computed string , following query would be fired and it should give result in the stated format



Query
~~~~~~~~~~~~~

SELECT EQUIP_ID , SCH.RANGE(EQUIP_ID) Description
FROM EQUIPMENT




Description
~~~~~~~~~~~~
1 to 100 Decibles, 1 to 50 N/m


on compiling this function it gives me following error

[DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: WITH;DECLARE CUR CURSOR;<SQL_variable_condition_declaration>
Message: An unexpected token "WITH" was found following "DECLARE CUR CURSOR". Expected tokens may include: "<SQL_variable_condition_declaration>"




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand|Select|Wrap|Line Numbers
  1. CREATE FUNCTION SCH.RANGE( P_EQUIPID INTEGER ) RETURNS VARCHAR(1000)
  2. LANGUAGE SQL
  3. BEGIN ATOMIC   
  4.      DECLARE return_str VARCHAR(1000) DEFAULT ' ';
  5.      DECLARE tmp VARCHAR(1000) DEFAULT ' ';
  6.  
  7.      DECLARE CUR CURSOR FOR
  8.         SELECT CHAR(EM.LOWERLIMIT) || ' to ' || CHAR(EM.UPPERLIMIT) || CD.DESCRIPTION
  9.         FROM    SCH.EQUIPMETRIC EM, SCH.CODES CD
  10.         WHERE   EM.UOMID = CD.ID
  11.         AND     EM.EQUIPID = P_EQUIPID
  12.         FOR     READ ONLY;
  13.  
  14.  
  15.      DECLARE EXIT HANDLER FOR NOT FOUND
  16.        SET return_str = ' ';
  17.  
  18.      BEGIN
  19.          OPEN CUR;
  20.  
  21.          FETCH FROM CUR INTO tmp;
  22.  
  23.          WHILE(SQLSTATE = '00000') DO
  24.         SET return_str = return_str + ', ' + tmp;
  25.         FETCH FROM CUR INTO tmp; 
  26.          END WHILE;
  27.  
  28.          CLOSE CUR;
  29.      END;
  30.  
  31.      RETURN return_str;
  32. END 

Pls help in resolving this issue , I have googled but couldnt get any solution

Thanks
Deven
Mar 6 '08 #1
1 1238
sakumar9
127 Recognized Expert New Member
I got some other error :(

DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "FOR" was found following "DECLARE CUR CURSOR".
Expected tokens may include: "<SQL_variable_condition_declaration>". LINE
NUMBER=9. SQLSTATE=42601

Will find the solution and let you know.

Regards
-- Sanjay
Mar 21 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1532
by: S Austin | last post by:
Discovered recently (duh) that putting inline code in .h files (e.g. in class definitions) is not a good idea when building DLLs and the applications that use those DLLs. The reason being, of...
8
2677
by: yb | last post by:
Hi, Does an inline element become block element once it is positioned absolutely. I couldn't find this explicity mentioned in the spec. (css2)
3
367
by: junky_fellow | last post by:
What is an inline function ? When should we declare a particular function as inline ? If a function is declared to be inline, does that mean that the entire code for that function is subtituted...
1
1908
by: Dave | last post by:
I am relativly new to visual basic, so this may be a no- brainer. I am attempting to use a computed column in a VB dataset defined as followe: ' 'dcCost ' Me.dcCost.ColumnName = "Cost"
7
5759
by: Aamir Mahmood | last post by:
Hi All I have DataTable object. Is there a way that I can know which fields (columns) in the table are computed. Apparantly the DataTable.Columns returns all columns both computed and other....
1
1529
by: DumRat | last post by:
Well, the results arouse curiosity. Check out for yourselves. http://www.thescripts.com/forum/threadnav617160-2-10.html
1
2102
by: devendra.basak | last post by:
Hi, I am new in DB2 8.1 below code works/logic works fine in Oracle, pls find below the inline UDF , the intent of this UDF is to create a string for each child and then return the computed...
0
7254
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
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.