Which one represents null? undef or empty string

☆樱花仙子☆ 提交于 2019-12-10 12:57:51

问题


I want to insert null in a column in a table.

Which one represents null? undef or empty string ''.

Which one should be used and Why? I know about defined and that I can check it.

But I am looking more from perspective of database.

Which one represents null more properly?

Update: I am using DBI module.


回答1:


DBI uses undef to represent a SQL NULL. The empty string represents an empty string.

However, some databases don't make a distinction between NULL and the empty string. Oracle is a particular offender here. DBI can't do anything about that.




回答2:


Assuming Perl DBI, undef represents a SQL NULL.

An empty string in Perl represents exactly the same (i.e. an empty string) in SQL.




回答3:


Assuming you are using the DBI module, and are using bound arguments (since if you were constructing the SQL by hand, you would use NULL in the string):

Undefined values, or undef, are used to indicate NULL values.

See the perldoc for DBI

If you aren't using DBI directly (e.g. you are using DBIx::Class or some other ORM) then you will probably find that it inherits the behaviour of DBI for this.



来源:https://stackoverflow.com/questions/12708633/which-one-represents-null-undef-or-empty-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!