Oracle considers empty strings to be NULL while SQL Server does not - how is this best handled?

前端 未结 11 1906
挽巷
挽巷 2021-01-01 13:35

I have to write a component that re-creates SQL Server tables (structure and data) in an Oracle database. This component also has to take new data entered into the Oracle d

11条回答
  •  清歌不尽
    2021-01-01 14:04

    Its nasty and could have unexpected side effects.. but you could just insert "chr(0)" rather than ''.

    drop table x
    
    drop table x succeeded.
    create table x ( id number, my_varchar varchar2(10))
    
    create table succeeded.
    insert into x values (1, chr(0))
    
    1 rows inserted
    insert into x values (2, null)
    
    1 rows inserted
    select id,length(my_varchar) from x
    
    ID                     LENGTH(MY_VARCHAR)     
    ---------------------- ---------------------- 
    1                      1                      
    2                                             
    
    2 rows selected
    
    select * from x where my_varchar is not null
    
    ID                     MY_VARCHAR 
    ---------------------- ---------- 
    1                      
    

提交回复
热议问题