473,404 Members | 2,195 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,404 software developers and data experts.

Function for adding 1 to a hex column

I am trying to create a function that adds 1 to the value in a
hexadecimalcolumn. This function I want to use inside an SQL PL procedure.

I have a table with a column with char(16) for bit data. A 'select hex(col1)
from tab1' may return x'FFF59E344C59684CA17BB105677343BE'. I have tried to
create a function that takes the hexadecimal value (the in parameter is also
char(16) for bit data) and adds 1 to the input value. I have managed to add
1 to the value of the input parameter and get this:
x'FFF59E344C59684CA17BB105677343BF'. And this seems to work for any
hexadecimal value I try. But how do I convert this text string back to a
hexdecimal value so that I am able to update the column i db2? If I return
it as CHAR(35) - as a character string and try to update I get this value in
the column: x'78274646463539453334344335393638' ....

I try to do this from Command Center or a Command Window: update tab1 set
col1 = x'FFF59E344C59684CA17BB105677343BF' then it works. But why will it
not work inside a SQL PL procedure when I do: update tab1 set col1 = var1
(where var1 is CHAR(35) and contains x'FFF59E344C59684CA17BB105677343BF').

Regards

Odd Bjørn Andersen
ErgoGroup AS
Postboks 4364 Nydalen, N-0402 Oslo, Norway
Telefon +4723 14 50 00, Telefaks +4723 14 50 01
Mobilnr +47970 84597
www.ergogroup.no
Feb 20 '08 #1
1 2571
Go through dynamic SQL and let the SQL parser do the conversion:
like:
E.g. in DB2 9.5 you could do something like:

txt = 'SET ? = x''' || hexstring || '''';
PREPARE stmt FROM txt;
EXECUTE stmt INTO myval;

Prior to 9.5 use a dynamic cursor definition with SELECT FROM
SYSIBM.SYSDUMMY1

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 20 '08 #2

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

Similar topics

2
by: KULJEET | last post by:
hi i have a table c_table with two columns no, date it contains records no n_date 1 10-AUG-03 2 21-AUG-03
1
by: Not Me | last post by:
Hi, I'm sure this is a common problem.. to create a single field from a whole column, where each row would be separated by a comma. I can do this for a specified table, and column.. and I've...
10
by: Eric Petruzzelli | last post by:
If I fill my dataset and there is no data. The dataset is still created with zero rows (all columns are there). When I add my first row using the script below, it takes over 2 seconds to add??? If...
5
by: Paul | last post by:
Hi I have a table that currently has 466 columns and about 700,000 records. Adding a new DEFAULT column to this table takes a long time. It it a lot faster to recreate the table with the new...
2
by: Chris Cobb | last post by:
I have a table that currently contains 718000 rows. I wish to add a column to the table. Adding this column anywhere other than the end of the table requires exporting data, a drop and recreate,...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
4
by: Tony Lownds | last post by:
(Note: PEPs in the 3xxx number range are intended for Python 3000) PEP: 3107 Title: Function Annotations Version: $Revision: 53169 $ Last-Modified: $Date: 2006-12-27 20:59:16 -0800 (Wed, 27 Dec...
1
by: kirthika | last post by:
In a function we r finding max value of a column which is hving an id value and then incrementing the column value by adding 1 to the value . now we have to check if max value is zero (ie that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...
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.