Solved

Set variable to NULL in Pro-C

Posted on 2001-06-20
6
3,311 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
Comment Utility
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
Comment Utility
and the simplest way is to use INDICATOR variables.
0
 

Author Comment

by:ezree
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 4

Accepted Solution

by:
prashant_n_mhatre earned 5 total points
Comment Utility
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
Comment Utility
ezree,

Still facing any problem?
0
 
LVL 24

Expert Comment

by:SunBow
Comment Utility
done?
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
seriesUp challenge 7 106
Modbus - whats the maximum I can store in one register? 4 74
triangle challenge 4 75
countX 22 69
This is an explanation of a simple data model to help parse a JSON feed
A short article about problems I had with the new location API and permissions in Marshmallow
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…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now