473,545 Members | 1,987 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.Delimit erIndex ( 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(Delimite r, 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.RangeEl ements ( 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.Delimit erIndex(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_RE QUISITION_DETAI L_TEST (
IN
ac_req_number_r ange

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

-- ac_req_number_r ange = 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_r ange
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.TempLis t
(
RecordId varchar(255)
) ;
-- Insert record into tempList using function

insert into session.templis t
select *
from table (LX2P111.RangeE lements (ac_req_number_ range, ','))
;
--Insert elelements of array into separate fields

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

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

--Declare cursor
BEGIN
DECLARE MyCursor CURSOR WITH RETURN FOR
select RQH_REQ_LOCATIO N,
RQH_REQ_NUMBER,
RQH_CREATED,
RQH_REQUESTER,
RQH_DELIVER_TO
from lx2p111.requisi tion_detail rd, session.templis t2 t2
where rd.RQH_REQ_NUMB ER between cast(t2.MinValu e as int)

and cast(t2.MaxValu e as Int)
and rd.RLN_CREATED >= coalesce(adt_be gin, '01/01/1900')
;

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

Apr 28 '06 #1
15 2887
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.Delimit erIndex ( 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(Delimite r, 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.templis t
select *
from table (LX2P111.RangeE lements (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.templis t
select *
from table (LX2P111.RangeE lements (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.templis t
select *
from table (LX2P111.RangeE lements (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.templis t
select *
from table (LX2P111.RangeE lements (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.templis t
select *
from table (LX2P111.RangeE lements (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.templis t
select *
from table (LX2P111.RangeE lements (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(DELIMITE R, 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;F UNCTION
Message: No authorized routine named "RANGEELEME NTS" 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;F UNCTION
Message: No authorized routine named "RANGEELEME NTS" of type
"FUNCTION" having compatible arguments was found.
I keep getting this error message.

Apr 30 '06 #10

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

Similar topics

21
6497
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 Workshop program: hcw.exe that's included with Visual Basic. This exact same file compiled perfectly with no notes, warnings or errors prior to...
9
4386
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 the microsoft HTML workshop utility, lets call it c:\path\help.chm. My question is how do you launch it from the GUI? What logic do I put behind...
2
6400
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
6
4311
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 result in any way. Who can help me, I thank you very very much. list.cpp(main program)...
3
3329
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 numarray, help gives unhelpful responses:
7
5347
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 from clicking on many of the available topics (mostly methods but some properties are also unavailable). This same problem occurs with many, if not...
5
3252
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 using "F1" help within the VB IDE. Is this expectation achievable In trying to test my help file in the IDE, I have a solution with 2 projects:...
8
3208
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 including search the internet for help, but the help is worthless. Any ideas?
1
6114
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 default property of object Label. Click for more:...
0
2854
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 calls MS Excel, so the scenario is that I am supposed to see the Excel Menu bar, FILE EDIT VIEW INSERT ... HELP. I am able to see the menu bar, but in...
0
7479
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7669
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7439
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5987
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5343
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4962
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
722
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.