Solved

Set variable to NULL in Pro-C

Posted on 2001-06-20
6
3,477 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Export Table to CSV - Access to CSV - using python 18 226
maven disable workspace resolution 1 43
Bot application - advice 3 64
Java Inheritance super keyword use 8 40
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

730 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