Solved

Set variable to NULL in Pro-C

Posted on 2001-06-20
6
3,404 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
  • 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Specific format 21 197
mapAB Challlenge 35 144
Device same like our heart 12 85
VbScript to countdown to New Year's Day 6 55
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.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

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