Solved

can we save null in numeric feild in SQL

Posted on 2009-05-04
11
416 Views
Last Modified: 2013-12-07
HI,

can we save a null instead of zero in numeric feild in SQL ...i mean is there any predefined function in SQL which save the null if the value is zero and save regularly if that value is not zero..

insert into x value y

i need to insert null if y is zero and regular value where y is not zero..

where y is declared as long in c++.

y=0 then x = null
if y !=0 then x=y;

 If their is no predefined function can i have a snnipet code which does that
0
Comment
Question by:mannn
[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
  • 3
  • 3
  • +1
11 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24299585
>can we save a null instead of zero in numeric feild in SQL ...
yes

insert into x values (case when y = 0 then NULL else y end)

Open in new window

0
 
LVL 74

Expert Comment

by:sdstuber
ID: 24299640
insert into your_table (your_number) (nullif(y,0))
0
 

Author Comment

by:mannn
ID: 24299756
thanks angelIII ,

but i need to use that SQL code in C++..i.e iam using pro*c language..

so

so i used the query as update Z set x = :(case when y = 0 then NULL else y end)
and insert into Z(x) values :(case when y = 0 then NULL else y end)

where Z is the table name

iam getting compile error when tried to use that query


PCC-S-02201, Encountered the symbol "when" when expecting one of the following:

   ; , : ( [ * + - / . | ++ -- -> indicator, where,
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24299780

update Z set x = (case when :y = 0 then NULL else :y end)

resp:


update Z set x = nullif(:y,0 )
0
 

Author Comment

by:mannn
ID: 24299851
Thanks angelIII

atill getting following errors


PCC-S-02201, Encountered the symbol "when" when expecting one of the following:

   ( ) * + - / . @ |

Syntax error at line 16298, column 66,


 Encountered the symbol "then" when expecting one of the following:

   ; , = ( [ * ? | & < > + - / % . ^ *= /= %= += -= <<= >>= &&=
   ||= ^= | & == != <= >= << >> ++ -- ->

Syntax error at line 0, column 0,

PCC-S-02201, Encountered the symbol "<eof>" when expecting one of the following:

   ; : an identifier, end-exec, random_terminal

Error at line 0, column 0 in
0
 

Author Comment

by:mannn
ID: 24299866
if i usee the nullif iam getting the following error


PLS-S-00201, identifier 'NULLIF' must be declared
Error at line 16297, column 5 in file crs_crsres.i
    EXEC SQL UPDATE GWYDB.CRS_RES SET
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24299883
what version of oracle are you connecting to?
update Z set x = DECODE(:y, 0, NULL , :y ); 

Open in new window

0
 
LVL 40

Expert Comment

by:evilrix
ID: 24302026
Just an observation (it's been a while since I did any SQLing) but as I recall you can only set a field to be NULL if the schema for the table allows it. This being the case you might want to check this.
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 24303476
the error above appears to be a parsing limitation of pro*c, so using decode is probably the best replacement for the builtin nullif.

If you have happen to have dynamic sql then you should be able to use nullif since pro*c won't have to parse it, but rather the database itself.
0
 

Author Comment

by:mannn
ID: 24308189
Hi all,


i were using
update Z set x = DECODE(:y, 0, NULL , :y );  and

 insert in to Z y values DECODE(:y, 0, NULL , :y );


no compile errors but still saving y as Zero(for insert statement)....

right now iam testing insert statement..
iam not getting what going wroung...;-)
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 24309797
can you post the a more complete code snippet of your *.pc file?  the insert/update decode should work
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create a worker thread ( servicing thread) using the Message queue 3 50
replicate in oracle 13 45
update based on the value on another table 8 40
Oracle Date add 9 35
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

751 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