473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Converting Informix SP to DB2

Hello,
I'm fairly new to DB2. I am having some difficulty converting some
stored procedres from Informix that use default input parameters.
Specifically, the Informix procedures I need to convert use the '*'
character as a default input parameter to be used with the 'MATCHES'
condition if the input value is null. For example:

CREATE PROCEDURE "informix".stored_proc(input1 DECIMAL(18,8), input2
CHAR(20) DEFAULT '*')

SELECT table1.column1,table1.column2,table1.column3
FROM table1
WHERE table1.column4 = input1 AND
table1.column5 MATCHES input2;

END PROCEDURE;

If the input2 parameter is passed, a single record will be matched
with column5; otherwise, the query uses the syntax <MATCHES '*'> to
return all entries where column5 is not null.

Since DB2 does not allow default values to be declared for input
parameters and does not use the MATCHES condition, I figured I could
use the LIKE condition instead and use logic to default the INPUT2
value to '%' if it is NULL. For example:

CREATE PROCEDURE "DB2".STORED_PROC( IN INPUT1 (DEC(18,8), IN INPUT2
CHAR (20) )
SPECIFIC STORED_PROC
DYNAMIC RESULT SETS 1
LANGUAGE SQL
P1: BEGIN
SET INPUT2 = COALESCE(INPUT2, '%');
BEGIN
DECLARE CURSOR1 CURSOR WITH RETURN FOR
SELECT TABLE1.COLUMN1,TABLE1.COLUMN2,TABLE1.COLUMN3
FROM TABLE1
WHERE TABLE1.COLUMN4 = INPUT1 AND
TABLE1.COLUMN5 LIKE INPUT2;
OPEN CURSOR1;
END;
END P1

However, when INPUT2 is NULL the procedure does not return any rows to
the result set. I tested running the query manually using the syntax
<LIKE '%'>, and it *does* return the same results as <MATCHES '*'>.
Any idea why it doesn't work in the stored procedure? Is there any
more efficient way to go about this?
I also tried using a dynamically constructed SQL with no luck.

Thomas Bean
Nov 12 '05 #1
2 4059
tb***@cpicorp.com (Thomas Bean) wrote in message news:<81**************************@posting.google. com>...
Since DB2 does not allow default values to be declared for input
parameters and does not use the MATCHES condition, I figured I could
use the LIKE condition instead and use logic to default the INPUT2
value to '%' if it is NULL. For example:

CREATE PROCEDURE "DB2".STORED_PROC( IN INPUT1 (DEC(18,8), IN INPUT2
CHAR (20) )
SPECIFIC STORED_PROC
DYNAMIC RESULT SETS 1
LANGUAGE SQL
P1: BEGIN
SET INPUT2 = COALESCE(INPUT2, '%');
BEGIN
DECLARE CURSOR1 CURSOR WITH RETURN FOR
SELECT TABLE1.COLUMN1,TABLE1.COLUMN2,TABLE1.COLUMN3
FROM TABLE1
WHERE TABLE1.COLUMN4 = INPUT1 AND
TABLE1.COLUMN5 LIKE INPUT2;
OPEN CURSOR1;
END;
END P1

However, when INPUT2 is NULL the procedure does not return any rows to
the result set. I tested running the query manually using the syntax
<LIKE '%'>, and it *does* return the same results as <MATCHES '*'>.
Any idea why it doesn't work in the stored procedure?


The problem is that you've defined INPUT2 as CHAR(20) instead of
VARCHAR(20). Therefore you are saying COLUMN4 LIKE '%
' instead of COLUMN4 LIKE '%'
Jeremy Rickard
Nov 12 '05 #2
Jeremy,
That was indeed the problem, thanks for pointing it out.

--Thomas

jr******@unisystems.biz (Jeremy Rickard) wrote in message news:<d3**************************@posting.google. com>...
tb***@cpicorp.com (Thomas Bean) wrote in message news:<81**************************@posting.google. com>...
Since DB2 does not allow default values to be declared for input
parameters and does not use the MATCHES condition, I figured I could
use the LIKE condition instead and use logic to default the INPUT2
value to '%' if it is NULL. For example:

CREATE PROCEDURE "DB2".STORED_PROC( IN INPUT1 (DEC(18,8), IN INPUT2
CHAR (20) )
SPECIFIC STORED_PROC
DYNAMIC RESULT SETS 1
LANGUAGE SQL
P1: BEGIN
SET INPUT2 = COALESCE(INPUT2, '%');
BEGIN
DECLARE CURSOR1 CURSOR WITH RETURN FOR
SELECT TABLE1.COLUMN1,TABLE1.COLUMN2,TABLE1.COLUMN3
FROM TABLE1
WHERE TABLE1.COLUMN4 = INPUT1 AND
TABLE1.COLUMN5 LIKE INPUT2;
OPEN CURSOR1;
END;
END P1

However, when INPUT2 is NULL the procedure does not return any rows to
the result set. I tested running the query manually using the syntax
<LIKE '%'>, and it *does* return the same results as <MATCHES '*'>.
Any idea why it doesn't work in the stored procedure?


The problem is that you've defined INPUT2 as CHAR(20) instead of
VARCHAR(20). Therefore you are saying COLUMN4 LIKE '%
' instead of COLUMN4 LIKE '%'
Jeremy Rickard

Nov 12 '05 #3

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

Similar topics

3
by: Christian Eriksson | last post by:
Hi! I'm programming Perl DBI accessing Informix databases. I have a problem on a Solaris machine to use my installed Informix driver (DBD::Informix). I get the following error message: ...
3
by: Lee | last post by:
Hi, I'm developing a socket program to connect to Informix database through the ODBC. In here i called my socket program as "tap" . My tap will listen for data from unix through port 1070. After...
10
by: Joachim Banzhaf | last post by:
Hi, Creating the federated datasource library for informix fails for me. The db2 server is version 8.1 WSE on AIX 4.3. The informix client on this server is version CSDK 2.81/ESQL 9.53 UC2....
5
by: Gustavo Randich | last post by:
Hello, I'm writing an automatic SQL parser and translator from Informix to DB2. Now I'm faced with one of the most difficult things to translate, the "foreach execute procedure" functionality...
0
by: vishalp79 | last post by:
Hi, I am trying to install DBD::Informix module on perl on hpux 11.23 machine. but i get this weird error ...... Set up gcc environment - 4.1.1 *** ExtUtils::AutoInstall version 0.61 ***...
0
by: Lester Knutsen | last post by:
A two-day IBM Informix and DB2 User Group Technical Conference - Friday and Saturday, December 8-9, 2006 We are very please to announce our Keynote Speakers...
14
by: Khan | last post by:
Hello, I want to connect my intranet server (with php/apache) to the other informix database server, But I didnt it. I dont know how i can do it? Can i use php_informix extensions for example...
1
by: suess | last post by:
I'm a newb to Informix and trying to convert the following statement to SQL Server (2005). The problem is the join. From what I've been able to find, it appears that Informix outer joins are left...
4
by: --CELKO-- | last post by:
I need to convert a bunch of DB2 triggers to Oracle. Is there any kind of tools for this?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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
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
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,...

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.