?
Solved

Set variable to NULL in Pro-C

Posted on 2001-06-20
6
Medium Priority
?
3,614 Views
Last Modified: 2008-02-01
Hi all,
   I'm having difficulty to set up my Pro-C variable to
NULL values.Is there any specific command/syntax just to
NULL the variable values?

Below is the sample codes I've extracted from my program.
I've tried to use the memset command to clear the variable (hoping to make it NULL), when I insert
the value into a table it seems to insert a blank space.

1) Declaration :
EXEC  SQL BEGIN DECLARE SECTION;
    varchar         hs_ppj[6];                  
    etc.
EXEC  SQL END DECLARE SECTION;        

2) Setting var. to NULL if condition true :
  if {strncmp ((char *)hs_vot.arr,"B",1) == 0)}
     memset((char *)hs_ppj.arr,0,sizeof(pBASPR->sz_ppj));
--This is the part where I set the NULL value (hope so)--

3) Insert into table :
  EXEC SQL INSERT INTO LFEP_BAS2SPKB(ppj)
             VALUES(:hs_ppj);

ps : I'm using Oracle 8.1.6, AIX 4.3.3, ANSI C Compiler for AIX

Does anyone have any ideas?

Thanks in advance..


Ezree
0
Comment
Question by:ezree
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 4

Expert Comment

by:prashant_n_mhatre
ID: 6214417
If you set the length of a VARCHAR variable to zero before performing an UPDATE or INSERT statement, the column value is set to NULL. If the column has a NOT NULL constraint, Oracle returns an error.
0
 
LVL 4

Expert Comment

by:prashant_n_mhatre
ID: 6215056
and the simplest way is to use INDICATOR variables.
0
 

Author Comment

by:ezree
ID: 6217968
pras thank you for your answer, but what do you mean by using INDICATOR variable? Is it like a flag to control
the other NULL variable?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Accepted Solution

by:
prashant_n_mhatre earned 15 total points
ID: 6218173
Indicator variables are essentially "NULL flags" attached to host variables. You can associate every host variable with an optional indicator variable. An indicator variable must be defined as a 2-byte integer (using the type short) and, in SQL statements, must be prefixed by a colon and immediately follow its host variable. Or, you may use the keyword INDICATOR in between the host variable and indicator variable. Here is an example:

    short indicator_var;
    EXEC SQL SELECT xyz INTO :host_var:indicator_var
        FROM ...;
    /* ... */
    EXEC SQL INSERT INTO R
        VALUES(:host_var INDICATOR :indicator_var, ...);

You can use indicator variables in the INTO clause of a SELECT statement to detect NULL's or truncated values in the output host variables. The values Oracle can assign to an indicator variable have the following meanings:

-1 The column value is NULL, so the value of the host variable is indeterminate.
0 Oracle assigned an intact column value to the host variable.
>0 Oracle assigned a truncated column value to the host variable. The integer returned by the indicator variable is the original length of the column value.
-2 Oracle assigned a truncated column variable to the host variable, but the original column value could not be determined.

-------------------------------------------------
You can also use indicator variables in the VALUES and SET clause of an INSERT or UPDATE  statement to assign NULL's to input host variables. The values your program can assign to an indicator variable have the following meanings:
 
-1 Oracle will assign a NULL to the column, ignoring the value of the host variable.

>=0 Oracle will assign the value of the host variable to the column.

-------------------------------------------------
0
 
LVL 4

Expert Comment

by:prashant_n_mhatre
ID: 6225083
ezree,

Still facing any problem?
0
 
LVL 24

Expert Comment

by:SunBow
ID: 6227921
done?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question