天真FOO = empty_clob()
抱怨不兼容的类型。我尝试使用谷歌搜索,但(再一次)在寻找甲骨文帮助方面收效甚微。感谢。
答案 0 :(得分:16)
您是否只想检查没有任何长度的CLOB?虽然不完全是你的要求,但它基本上是一回事吗?
select *
from bar
where dbms_lob.getlength(foo) = 0;
这是完整的测试:
SQL> create table bar (foo clob);
Table created.
SQL> insert into bar values (empty_clob());
1 row created.
SQL> select *
2 from bar
3 where dbms_lob.getlength(foo) = 0;
FOO
--------------------------------------------------------------------------------
答案 1 :(得分:13)
如果您尝试在PL / SQL中进行比较,您可以像Igor的解决方案那样测试相等性
SQL> ed
Wrote file afiedt.buf
1 DECLARE
2 dummy clob;
3 BEGIN
4 dummy := empty_clob();
5 IF dummy = empty_clob() THEN
6 dbms_output.put_line( 'Dummy is empty' );
7 ELSE
8 dbms_output.put_line( 'Dummy is not empty' );
9 END IF;
10* END;
SQL> /
Dummy is empty
PL/SQL procedure successfully completed.
如果您尝试在SQL中执行此操作,那么您需要使用DBMS_LOB.COMPARE函数。表中的LOB列实际上是一个LOB定位器(即指针),因此您真正关心的是LOB指向的值与EMPTY_CLOB()函数返回的LOB定位符指向的值相当。
SQL> desc bar
Name Null? Type
----------------------------------------- -------- ------------------------
FOO CLOB
SQL> insert into bar values ('123');
1 row created.
SQL> insert into bar values( empty_clob() );
1 row created.
SQL> insert into bar values( empty_clob() );
1 row created.
SQL> ed
Wrote file afiedt.buf
1 select count(*)
2 from bar
3* where dbms_lob.compare( foo, empty_clob() ) = 0
SQL> /
COUNT(*)
----------
2
SQL> ed
Wrote file afiedt.buf
1 select count(*)
2 from bar
3* where dbms_lob.compare( foo, empty_clob() ) != 0
SQL> /
COUNT(*)
----------
1
答案 2 :(得分:3)
这样的东西应该适用于初始化:
DECLARE
dummy clob;
dummy2 clob;
BEGIN
dummy := empty_clob();
IF dummy = empty_clob() THEN
dummy2 := dummy;
END IF;
END;
答案 3 :(得分:1)
在SQLplus中测试空clobs的一种简单方法是在执行测试之前将所有CLOBS转换为varchar2(使用TO_CHAR函数):
SELECT *
FROM table1
WHERE TO_CHAR(table1.column1) IS NULL
答案 4 :(得分:0)
DECLARE
dummy CLOB := 'fxsgf';
dummy1 CLOB;
BEGIN
IF dummy1 = EMPTY_CLOB ()
THEN
DBMS_OUTPUT.put_line ('Dummy1 is empty');
ELSE
DBMS_OUTPUT.put_line ('Dummy1 is not empty');
END IF;
IF dummy = EMPTY_CLOB ()
THEN
DBMS_OUTPUT.put_line ('Dummy is empty');
ELSE
DBMS_OUTPUT.put_line ('Dummy is not empty');
END IF;
END;