Oracle treating empty string as NULL problem for a Java / JPA programmer

后端 未结 6 2317
失恋的感觉
失恋的感觉 2021-02-19 17:22

How do you handle this situation where Oracle stores the empty string as a null in the database ?

I would like it to be stored as an empty string as it is not as NULL, s

6条回答
  •  故里飘歌
    2021-02-19 17:56

    Beleive Oracle is optimizing the database by converting the empty string as NULL. First an empty string still may be need to be stored explicitly in the database storage at data block level (*1). Storing as NULL may reduce data storage footprint. Second if any indexes were defined on the column then the NULL values are not included in index thereby reducing index storage footprint. (*2)

    From a design and development standpoint unless the empty space really changes the semantics of the data from a business perspective storing as NULL should be fine.

    Adding code at framework level ( or parent class ) as suggested above would eliminate the need to type it out at all children classes & objects - that is what Object Oriented and even basic programming strive to do.

    If my code is performing best because my database storage is optimized, then I should be happy. It sucks if my code performance tanks in production just because I wanted to save a little typing or failed to do masterful design / development?

    I would be happy that Oracle is optimizing it for me under the covers.

    All about Oracle NULL:

    NULL is a special value. NULL does not equate to anything including itself i.e NULL is not equal to NULL

提交回复
热议问题