473,791 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6000
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...sho uld fly through this if your keys have a high cardinality.

JCE
"Chris" <ct********@yah oo.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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
2629
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 programs within it?) We have hundreds of COBOL programs. Thank you.
4
1894
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 pointers you all can provide would be appreciated. Thank You.
12
5195
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 data structure? I'm hoping C# has a way to define a data structure that I can read the lines into so that they can be easily manipulated. Any advice would be greatly appreciated.
1
1202
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 that outlines what needs to be distrib/installed to get that to work correctly on a non-server OS? MMTIA, wardeaux
2
11417
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, OpenProcessToken, LookupPrivilegeValue, AdjustTokenPrivilegese, ExitWindowsEx. I am trying to avoid using any API calls if possible and to use managed code instead. I couldn't find any easy way of doing this but searching the Internet with...
1
1059
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 application, warm regards. shaik jaffar ali
1
1031
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 application, warm regards. shaik jaffar ali
0
2723
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 * * the removal_eligibility_link table for all persons * * in all stages associated with the victim who has * * has had a specific legal status change * EXEC SQL EXECUTE
2
1256
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
9669
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10207
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10154
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9993
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5430
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2913
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.