473,395 Members | 1,335 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,395 software developers and data experts.

Pro*COBOL and (possible) NULL host variabe in WHERE condition

I have tableA, defined as:

field1 varchar2(10),
field2 varchar2(10),
field3 varchar2(10)

I have host variables defined as:

v1 pic x(10) varying
v2 pic x(10) varying
v3 pic x(10) varying

If insert the following record:

v1-len=5 v1-arr=Hello
v2-len=0 v2-arr=<spaces>
v3-len=5 v3-arr=World

I end up with this in the database:

field1=Hello
field2=<null>
field3=World

However, if I set the host variables exactly the same and try this:

select
'I found it'
from
tableA
where
field1 = :v1
and
field2 = :v2
and
field3 = :v3

I am getting a 1403 SQLCODE returned.

I know that I cannot use indicator variables in WHERE conditions to
search for NULLs, so what is the fix? I can't create a separate WHERE
condition for each "NULL possibility" - in this small example alone I
woul dneed 8 different possible SELECT statements.

I know it must be something fairly obvious, but its not jumping out at
me right now and my eyes hurt from trying to wade through the Oracle
docs.

As always, any thoughts/suggestion/solutions are most appreciated.
Thanks,
Chris

Jul 19 '05 #1
2 5962
Chris wrote:
I have tableA, defined as:

field1 varchar2(10),
field2 varchar2(10),
field3 varchar2(10)

I have host variables defined as:

v1 pic x(10) varying
v2 pic x(10) varying
v3 pic x(10) varying

If insert the following record:

v1-len=5 v1-arr=Hello
v2-len=0 v2-arr=<spaces>
v3-len=5 v3-arr=World

I end up with this in the database:

field1=Hello
field2=<null>
field3=World

However, if I set the host variables exactly the same and try this:

select
'I found it'
from
tableA
where
field1 = :v1
and
field2 = :v2
and
field3 = :v3

I am getting a 1403 SQLCODE returned.

I know that I cannot use indicator variables in WHERE conditions to
search for NULLs, so what is the fix? I can't create a separate WHERE
condition for each "NULL possibility" - in this small example alone I
woul dneed 8 different possible SELECT statements.

I know it must be something fairly obvious, but its not jumping out at me right now and my eyes hurt from trying to wade through the Oracle
docs.

As always, any thoughts/suggestion/solutions are most appreciated.
Thanks,
Chris

I knew that I would find something as soon as I posted this message.

One solution (as documented in Oracle's 9i documentation for Pro*COBOL)
is a combination of host indicator variable and NULL condition
checking. For example:

isnull pic s9(4) comp value -1.
select
'I found it'
from
tableA
where
( field1 = :v1 or ( field1 is null and :v1:isnull is null ) )
and
( field2 = :v2 or ( field2 is null and :v2:isnull is null ) )
and
( field3 = :v3 or ( field3 is null and :v3:isnull is null ) )

This solution does in fact work, but it seems rather clumsy to me, and
honestly I'm concerned with optimizing the performance on this query.
Especially if my only existing index is: field1, field2, field3 (and
there are a few million records in the table).

Does anyone know of a better/cleaner/more efficient way to do this? I
imagine there has to be one - and I'd be extremely grateful to see one.

Jul 19 '05 #2
jce
Make sure your table is not defaulting to NULLS, and insert spaces is one
option - no benefit, and defeats purpose of varchar. So no value.

I didn't know you could index on a varchar - this seems strange to me as for
most sorting/indexing algorithms [that I know of and I'm not familliar with
Oracle] the data would be expanded to the full size internally and at 10
characters you are only saving 8 bytes a record...hardly worth it in the
first place.

The host isnull variables are more important on the select. A lot of shops
will check that null indicator =-1 to determine if the select returns a null
which is not actually right as the value is set on the insert statement (and
defaulted if not). You just need to make sure that you set the null
indicator for each of the fields prior to calling the select - this is not a
big deal.

If you are worried about the performance have the DBA run some kind of
explain on it and check the execution path etc. Like I said, I've never
seen a VARCHAR as a key field before.

The only other option is to dynamically build the SQL - depending on how you
do this the performance drop off is negligible as the statements are access
plan are cached. So you could build the where clause. I would have done
it the way you did most likely - but I wouldn't have varchars.

So, I don't see anything wrong with this at all. You have a full key select
statement...should fly through this if your keys have a high cardinality.

JCE
"Chris" <ct********@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Chris wrote:
I have tableA, defined as:

field1 varchar2(10),
field2 varchar2(10),
field3 varchar2(10)

I have host variables defined as:

v1 pic x(10) varying
v2 pic x(10) varying
v3 pic x(10) varying

If insert the following record:

v1-len=5 v1-arr=Hello
v2-len=0 v2-arr=<spaces>
v3-len=5 v3-arr=World

I end up with this in the database:

field1=Hello
field2=<null>
field3=World

However, if I set the host variables exactly the same and try this:

select
'I found it'
from
tableA
where
field1 = :v1
and
field2 = :v2
and
field3 = :v3

I am getting a 1403 SQLCODE returned.

I know that I cannot use indicator variables in WHERE conditions to
search for NULLs, so what is the fix? I can't create a separate WHERE
condition for each "NULL possibility" - in this small example alone I
woul dneed 8 different possible SELECT statements.

I know it must be something fairly obvious, but its not jumping out

at
me right now and my eyes hurt from trying to wade through the Oracle
docs.

As always, any thoughts/suggestion/solutions are most appreciated.
Thanks,
Chris

I knew that I would find something as soon as I posted this message.

One solution (as documented in Oracle's 9i documentation for Pro*COBOL)
is a combination of host indicator variable and NULL condition
checking. For example:

isnull pic s9(4) comp value -1.

select
'I found it'
from
tableA
where
( field1 = :v1 or ( field1 is null and :v1:isnull is null ) )
and
( field2 = :v2 or ( field2 is null and :v2:isnull is null ) )
and
( field3 = :v3 or ( field3 is null and :v3:isnull is null ) )

This solution does in fact work, but it seems rather clumsy to me, and
honestly I'm concerned with optimizing the performance on this query.
Especially if my only existing index is: field1, field2, field3 (and
there are a few million records in the table).

Does anyone know of a better/cleaner/more efficient way to do this? I
imagine there has to be one - and I'd be extremely grateful to see one.

Jul 19 '05 #3

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

Similar topics

0
by: VictorReinhart | last post by:
Hi, For Oracle 9i, the sample make file for the Oracle Pro*COBOL precompiler has a hard-coded list of programs in it. Has anyone created a generic make file (ie, without a hardcoded list of...
4
by: Kalpesh Parikh | last post by:
We have 'C' routine calls Pro COBOL routine...... Data passed back to the C program is shifted by 4 bytes. We are trying to understand and fix this. p.s. COBOL to COBOL is working fine! Any...
12
by: J. G. | last post by:
I'm looking at rewriting some stand-alone Pro*COBOL applications that read flat files and spit out some reports. Is there any way to mimic COBOL's ability to read lines from a flat file into a...
1
by: Wardeaux | last post by:
ok....... this may seem like a simple question, but I'm seeing several articles that "hint" you can run ASP.NET apps on Win2k Pro and WinXP Pro. Is this true? If so where is there an article/info...
2
by: Brian Worth | last post by:
I have just upgraded from VB 4.0 to VB .NET 2002. One program under VB 4.0 was able to shut down or restart the (windows XP) machine using a series of API calls. (Getlasterror, GetCurrentProcess,...
1
by: jaffar | last post by:
hai all, I am developing a vb.net windows application , is there any possible to run the vb.net application in visual Studio 6 Pro, if possible what are the ,minimum, requirments to run the...
1
by: jaffar | last post by:
hai all, I am developing a vb.net windows application , is there any possible to run the vb.net application in visual Studio 6 Pro, if possible what are the ,minimum, requirments to run the...
0
by: tickle | last post by:
Need to convert this PL/SQL script to Dynamic SQL Method 2 * copybook - celg02u3.sql SIR 24265 * * updates dt_deny for all rows in * * ...
2
by: Chris | last post by:
I have tableA, defined as: field1 varchar2(10), field2 varchar2(10), field3 varchar2(10) I have host variables defined as: v1 pic x(10) varying v2 pic x(10) varying
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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
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...

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.