Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We have converted Oracle database to SQL server database. We are facing issue with null vs blank.

Scenario:

In oracle:

Create table Student (Sno int, FName varchar(20) not null, MName varchar(30) null,
Lname varchar(20) not null)

Insert into Student(Sno,Fname,Mname,Lname) values (10,'James' ,'','Clark')

Record Inserting into Oracle as Middle name inserting as null even we passed blank value('')
10,James,null,Clark

Record Inserting into SQL Server as Middle name inserting as blank in SQL server (showing empty space in the table, even we have the default constraint)
10,James,,Clark


we want to handle when blank ('') inserting into SQL table it should be treated as 'null' which is the similar behavior of Oracle database.

What I have tried:

for some existing triggers added condition nullif. but some of the table we don't have triggers and how to handle those tables when insert or update happening.
Posted
Updated 17-Jun-18 1:55am
Comments
[no name] 16-Jun-18 13:22pm    
I would say MSSQL is right. Empty string is _not_ NULL ;)
Insert into Student(Sno,Fname,Mname,Lname) values (10,'James' ,NULL,'Clark') is the correct way

1 solution

It is a known Oracle problem (well that's a point of view, but SQL-92 disagrees with Oracle, but Oracle says he was here first)...
Oracle threat empty string as NULL value (it is an internal conversation).
I would not advise to force SQL to threat empty string as Oracle does for two reasons:
1. ANSI SQL says Oracle wrong
2. It will became a performance with large number of inserts with string variables
However if you can not skip one of these:
1. use triggers
2. wrap insert in SQL
3. change INSERT code in application
 
Share this answer
 
Comments
[no name] 17-Jun-18 10:39am    
Quote: "it is an internal conversation"
conversation/conversion/convention?
Anyway a 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900