天真FOO = empty_clob()
抱怨不兼容的类型.我尝试使用谷歌搜索,但(再一次)在寻找甲骨文帮助方面收效甚微.谢谢.
你只是想检查一个没有任何长度的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 --------------------------------------------------------------------------------
如果您尝试在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