473,513 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help! inserting records and functions

I am working in a project that I need to parse an arrayt an select
records based upon the values parsed. I used the functions developed by
Knut Stolze in his article 'Parsing Strings'. I am particulary having
problems inserting records using a function.

I am attaching the code for your review. Please, help.
=================================--Function
1--====================================

CREATE FUNCTION lx2p111.DelimiterIndex ( string varchar(8000),
Delimiter char(1) )
RETURNS TABLE ( ordinal INTEGER, index INTEGER )

-- string = any string delimited by a character
-- Delimiter = the delimimeter character i.e. ',', -, *
-- Description This functions returns the begining and end
position for every array.
-- supports RangeElements function

LANGUAGE SQL
DETERMINISTIC
NO EXTERNAL ACTION
CONTAINS SQL
RETURN
WITH t(ordinal, index) AS
( VALUES ( 0, 0 )
UNION ALL
SELECT ordinal+1, COALESCE(NULLIF(
-- find the next delimiter ','
LOCATE(',', string, index+1), 0),
LENGTH(string)+1)
FROM t
WHERE ordinal < 10000 AND
LOCATE(Delimiter, string, index+1) <> 0 )

SELECT ordinal, index
FROM t
UNION ALL
-- add indicator for the end of the string
SELECT MAX(ordinal)+1, LENGTH(string)+1
FROM t

=================================--Function
2--====================================
CREATE FUNCTION LX2P111.RangeElements ( string varchar (8000),
delimiter char (1) )
RETURNS TABLE ( elements varchar(255) )

------------------------------------------------------------------------

-- string = any string delimited by a character
-- Delimiter = the delimimeter character i.e. ',', -, *
-- Description This functions returns every array element in the
list (i.e. ranges)
LANGUAGE SQL
DETERMINISTIC
NO EXTERNAL ACTION
CONTAINS SQL
RETURN
WITH t(ordinal, index) AS
( SELECT ordinal, index
FROM TABLE ( LX2P111.DelimiterIndex(string, Delimiter) )
AS x )
SELECT SUBSTR(string, t1.index+1, t2.index - t1.index - 1)
FROM t AS t1 JOIN t AS t2 ON
( t2.ordinal = t1.ordinal+1 )
=================================--Stored
Proc--====================================

CREATE PROCEDURE LX2P111.LDBS_REQUISITION_DETAIL_TEST (
IN
ac_req_number_range

VARCHAR(8000),
IN adt_begin
DATE
)
DYNAMIC RESULT SETS 1
LANGUAGE SQL

-- ac_req_number_range = Requisition ranges (parse string, for
dsicrete values

min=max)
-- adt_begin = The beginning date range to present
(single

value)
-- Description This procedure will parse the ai_req_number_range
and insert
-- all rows into temp table. It first checks to see
if there

P1: BEGIN
--Create temp table to hold for the parsed array element values

DECLARE GLOBAL TEMPORARY TABLE SESSION.TempList
(
RecordId varchar(255)
) ;
-- Insert record into tempList using function

insert into session.templist
select *
from table (LX2P111.RangeElements (ac_req_number_range, ','))
;
--Insert elelements of array into separate fields

DECLARE GLOBAL TEMPORARY TABLE SESSION.TempList2
(
ParamName Varchar(25),
MinValue varchar(15),
Maxvalue varchar(15)
) ;
insert into session.templist2
select 'ReqNo' ,
left(RecordId, (locate('-', RecordID, 1)-1)) ,
substr (RecordId, (locate('-', RecordId,
1)+1),(length

(RecordId)- (locate('-', RecordId, 1))))
from SESSION.TEMPLIST;

--Declare cursor
BEGIN
DECLARE MyCursor CURSOR WITH RETURN FOR
select RQH_REQ_LOCATION,
RQH_REQ_NUMBER,
RQH_CREATED,
RQH_REQUESTER,
RQH_DELIVER_TO
from lx2p111.requisition_detail rd, session.templist2 t2
where rd.RQH_REQ_NUMBER between cast(t2.MinValue as int)

and cast(t2.MaxValue as Int)
and rd.RLN_CREATED >= coalesce(adt_begin, '01/01/1900')
;

-- Cursor left open for client application
OPEN MyCursor;
END;
END P1

Apr 28 '06 #1
15 2882
Jaraba wrote:
I am working in a project that I need to parse an arrayt an select
records based upon the values parsed. I used the functions developed
by Knut Stolze in his article 'Parsing Strings'. I am particulary
having problems inserting records using a function.

I am attaching the code for your review. Please, help.
What error message are getting? For that matter, are you getting an
error message or are these just not working as you expected?
=================================--Function
1--====================================

CREATE FUNCTION lx2p111.DelimiterIndex ( string varchar(8000),
Delimiter char(1) )
RETURNS TABLE ( ordinal INTEGER, index INTEGER )

-- string = any string delimited by a character
-- Delimiter = the delimimeter character i.e. ',', -, *
-- Description This functions returns the begining and end
position for every array.
-- supports RangeElements function

LANGUAGE SQL
DETERMINISTIC
NO EXTERNAL ACTION
CONTAINS SQL
RETURN
WITH t(ordinal, index) AS
( VALUES ( 0, 0 )
UNION ALL
SELECT ordinal+1, COALESCE(NULLIF(
-- find the next delimiter ','
LOCATE(',', string, index+1), 0),
Well, looks like these are basically the same as the functions Knut
wrote about in his article, although you've added a parameter to make
the delimiter character configurable. Unfortunately, in the line above,
you've still got a constant ',' that needs to be replaced with
DELIMITER.
LENGTH(string)+1)
FROM t
WHERE ordinal < 10000 AND
LOCATE(Delimiter, string, index+1) <> 0 )

SELECT ordinal, index
FROM t
UNION ALL
-- add indicator for the end of the string
SELECT MAX(ordinal)+1, LENGTH(string)+1
FROM t

[snip]
Dave.

--

Apr 29 '06 #2
I am getting an error in the following piece of code, everything else
works well specially the ones yjay Knut wrote.
Thanks

Apr 29 '06 #3

-- Insert record into tempList using function

insert into session.templist
select *
from table (LX2P111.RangeElements (ac_req_number_range, ','))
;
Sorry, forgot to post the code in the previous entry.

Apr 29 '06 #4
Jaraba wrote:

-- Insert record into tempList using function

insert into session.templist
select *
from table (LX2P111.RangeElements (ac_req_number_range, ','))
;
Sorry, forgot to post the code in the previous entry.


.... and the error?
Dave.

--

Apr 29 '06 #5
I am getting an error building the stored procedure. It is expecting
different parameters. maybe the construction of the insert statement
with the function is not properly done

Apr 29 '06 #6
Jaraba wrote:
I am getting an error building the stored procedure. It is expecting
different parameters. maybe the construction of the insert statement
with the function is not properly done


You should run the INSERT statement alone on the command line to test its
proper functioning. Also, please post the exact and complete error message
here. This helps tremendously to understand your problem.

My best guess is that you have not provided a correlation name for the
resulting table. This might work better:

insert into session.templist
select *
from table (LX2P111.RangeElements (ac_req_number_range, ',')) AS t

Note the "AS t" at the end of the FROM clause. This correlation name
(called correlation-clause in the manual http://tinyurl.com/7av8b) is
mandatory.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Apr 29 '06 #7
Jaraba wrote:
I am getting an error building the stored procedure. It is expecting
different parameters. maybe the construction of the insert statement
with the function is not properly done


Could you please post the *error* *message* you are getting?
Honestly... Like trying to get blood out of a stone.

In the absence of any further information, I'll take a wild stab in the
dark (insert Blackadder II quote here ;-)

insert into session.templist
select *
from table (LX2P111.RangeElements (ac_req_number_range, ','));

The above code will fail, but not with an error about parameters. It'll
fail because you're missing a mandatory correlation name from the end:

insert into session.templist
select *
from table (LX2P111.RangeElements (ac_req_number_range, ',')) AS T;

However, that'll fail too because the string literal ',' will be
interpreted as a VARCHAR when your function is expecting a CHAR in that
position. Either change the function to expect a VARCHAR as the second
parameter, or use:

insert into session.templist
select *
from table (LX2P111.RangeElements (ac_req_number_range, CHAR(',')))
AS T;

Not that the second parameter is much use... As mentioned in a prior
post you've got a bug in your altered version of Knut's functions.
Change:

LOCATE(',', string, index+1), 0),

To:

LOCATE(DELIMITER, string, index+1), 0),

Finally, you may run into some problems by having declared the certain
parameters as VARCHAR(8000). I seem to recall a note in the LOCATE
function's documentation that the maximum length it can handle is
VARCHAR(4000) (when passed a VARCHAR that is), like a number of other
functions in the SYSFUN schema.

Finally, and without putting too blunt a point on it (re: Blackadder II
quote earlier ;-), here's a checklist for future use:

* Post the code that's causing the error. Try and reduce the code to a
minimal use case that demonstrates the problem without requiring extra
objects like tables to be defined. If extra objects are necessary, post
the code defining them.
* Format the code in your post so that it doesn't wrap across lines
(especially in the case of comments) allowing people to simply copy and
paste your code if they want to test it.
* Post the *entire* error message including any apparently cryptic
codes. Even if the error message isn't English, the code at the start
of a DB2 error can be used to find the English definition in the Info
Center.
* Include the version, fixpak level, and platform of DB2 that you're
using (e.g. DB2 UDB v8.1 FP11 for LUW), or better still include the
output of db2level on your system.
Dave.
--

Apr 29 '06 #8
DB2 SQL error: SQLCODE: -440, SQLSTATE: 42884, SQLERRMC:
RANGEELEMENTS;FUNCTION
Message: No authorized routine named "RANGEELEMENTS" of type
"FUNCTION" having compatible arguments was found
Is the message that I am getting.

Apr 30 '06 #9
DB2 SQL error: SQLCODE: -440, SQLSTATE: 42884, SQLERRMC:
RANGEELEMENTS;FUNCTION
Message: No authorized routine named "RANGEELEMENTS" of type
"FUNCTION" having compatible arguments was found.
I keep getting this error message.

Apr 30 '06 #10
Jaraba wrote:
DB2 SQL error: SQLCODE: -440, SQLSTATE: 42884, SQLERRMC:
RANGEELEMENTS;FUNCTION
Message: No authorized routine named "RANGEELEMENTS" of type
"FUNCTION" having compatible arguments was found.
I keep getting this error message.

Could it be the second argument is a CHAR(1)?
LX2P111.RangeElements (ac_req_number_range, ',')
',' is a VARCHAR(1) and cannot be promoted to CHAR(1).
Try LX2P111.RangeElements (ac_req_number_range, CHAR(','))

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 30 '06 #11
Thanks. I think that was most of the proble. I adjusted data types and
change few things. Now I am getting a privilege error message as
follows:

DB2 SQL error: SQLCODE: -551, SQLSTATE: 42501, SQLERRMC:
CD2KXG;SELECT;LX2P111.REQUISITION_DETAIL
"CD2KXG" does not have the privilege to perform operation "SELECT" on
object "LX2P111.REQUISITION_DETAIL".
Even thoug i can select records using the id in the command window

May 1 '06 #12
Everything basically works, but when I join the temp table to the
REQUISITION_DETAIL view, that is when I get the above error

May 1 '06 #13
Jaraba wrote:
Everything basically works, but when I join the temp table to the
REQUISITION_DETAIL view, that is when I get the above error

Now we are lacking the query :-)
If you post all the information together chances increase.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
May 1 '06 #14
The query is included in the nody of the stored proc:

BEGIN
DECLARE MyCursor CURSOR WITH RETURN FOR
select RQH_REQ_LOCATION,
RQH_REQ_NUMBER,
RQH_CREATED,
RQH_REQUESTER,
RQH_DELIVER_TO
from lx2p111.requisition_detail rd,
session.templist2 t2
where rd.RQH_REQ_NUMBER between
cast(t2.MinValue as int)

May 1 '06 #15
Jaraba wrote:
The query is included in the nody of the stored proc:

BEGIN
DECLARE MyCursor CURSOR WITH RETURN FOR
select RQH_REQ_LOCATION,
RQH_REQ_NUMBER,
RQH_CREATED,
RQH_REQUESTER,
RQH_DELIVER_TO
from lx2p111.requisition_detail rd,
session.templist2 t2
where rd.RQH_REQ_NUMBER between
cast(t2.MinValue as int)


Well, do what the user response of the SQL0551 error message tells you:
grant the necessary privileges on the lx2p111.requisition_detail table to
the user who wants to create the procedure. There are some cases where
routines don't accept group privileges. I don't remember the details, but
this might be such a case.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
May 2 '06 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
6491
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
4377
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
2
6382
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
6
4305
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
3327
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
5344
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
3250
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
3207
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
1
6112
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
2850
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
7166
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
7543
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7106
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7534
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...
1
5094
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3236
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
3226
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1601
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 ...
0
459
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.