Oracle SQL Python的空值
我有一个clob数据点,必须使用Oracle SQL Python的空值,python,sql,oracle,python-2.7,Python,Sql,Oracle,Python 2.7,我有一个clob数据点,必须使用.read()将其添加到列表中,但是,有时此列为空,因此在使用.read()属性之前需要先进行检查 我已经分离出了相关的部分。如果我只打印数据,空字段打印为无。Is not null似乎是错误的代码,但我不确定该使用什么 for currentrow in data: if currentrow[8] is not null: Product = currentrow[8].read() else: Product
.read()
将其添加到列表中,但是,有时此列为空,因此在使用.read()
属性之前需要先进行检查
我已经分离出了相关的部分。如果我只打印数据,空字段打印为无。Is not null似乎是错误的代码,但我不确定该使用什么
for currentrow in data:
if currentrow[8] is not null:
Product = currentrow[8].read()
else:
Product = currentrow[8]
data = tuple([currentrow[0], currentrow[1], currentrow[2], currentrow[3], currentrow[4], currentrow[5], currentrow[6], currentrow[7], Product])
print data
Python使用
None
singleton值作为null<将数据库中的code>NULLs转换为该对象:
if currentrow[8] is not None:
您可以将该行折叠为两行:
for currentrow in data:
product = currentrow[8] and currentrow[8].read()
data = currentrow[:8] + (product,)
由于Python的
和
运算符短路,并且无
在布尔上下文中为false。除非设置行工厂,cx\u Oracle
游标为每行生成元组,您可以切片以仅选择前8个元素,然后追加第9个元素以从这两个元素中创建新元组。Python使用None
单例值作为空值<将数据库中的code>NULLs转换为该对象:
if currentrow[8] is not None:
您可以将该行折叠为两行:
for currentrow in data:
product = currentrow[8] and currentrow[8].read()
data = currentrow[:8] + (product,)
由于Python的和
运算符短路,并且无
在布尔上下文中为false。除非设置行工厂,cx\u Oracle
游标为每行生成元组,您可以切片以仅选择前8个元素,然后追加第9个元素以从这两个元素中创建新元组。
types.NoneType的唯一值。“无”经常用于表示
缺少值,如未将默认参数传递给
功能
所以你可以试试这个:
for currentrow in data:
if currentrow[8] is not None: <-- Change this from null to None
Product = currentrow[8].read()
else:
Product = currentrow[8]
data = tuple([currentrow[0], currentrow[1], currentrow[2], currentrow[3], currentrow[4], currentrow[5], currentrow[6], currentrow[7], Product])
print data
对于数据中的currentrow:
如果currentrow[8]不是None:来自:
types.NoneType的唯一值。“无”经常用于表示
缺少值,如未将默认参数传递给
功能
所以你可以试试这个:
for currentrow in data:
if currentrow[8] is not None: <-- Change this from null to None
Product = currentrow[8].read()
else:
Product = currentrow[8]
data = tuple([currentrow[0], currentrow[1], currentrow[2], currentrow[3], currentrow[4], currentrow[5], currentrow[6], currentrow[7], Product])
print data
对于数据中的currentrow:
如果currentrow[8]不是无: