Solved

Set variable to NULL in Pro-C

Posted on 2001-06-20
6
3,539 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Accepted Solution

by:
prashant_n_mhatre earned 5 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn different types of Android Layout and some basics of an Android App.
Six Sigma Control Plans
Introduction to Processes

691 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