sql-如何查询中的CLOB列
我正在尝试运行具有几列的查询,这些列是CLOB数据类型。 如果我像平常一样运行查询,则所有这些字段的值都将为DBMS_LOB.substr(column。
我尝试使用DBMS_LOB.substr(column),但出现错误
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
如何查询CLOB列?
8个解决方案
69 votes
这有效
select DBMS_LOB.substr(myColumn, 3000) from myTable
Chris answered 2020-07-28T18:35:57Z
41 votes
当获取CLOB列的子字符串并使用具有大小/缓冲区限制的查询工具时,有时您需要将BUFFER设置为更大的大小。 例如,在使用SQL Plus时,请使用DBMS_LOB.substr将其设置为10000,默认值为4000。
运行DBMS_LOB.substr命令,您还可以指定要返回的字符数和偏移量。 因此,使用DBMS_LOB.substr(column, 3000)可能会将其限制为足够小的缓冲区空间。
有关substr命令的更多信息,请参见oracle文档。
DBMS_LOB.SUBSTR (
lob_loc IN CLOB CHARACTER SET ANY_CS,
amount IN INTEGER := 32767,
offset IN INTEGER := 1)
RETURN VARCHAR2 CHARACTER SET lob_loc%CHARSET;
mrjohn answered 2020-07-28T18:35:37Z
8 votes
我的Oracle数据库中的HugeClob确实遇到了另一种情况。 select仅在函数中允许使用值4000,例如:
dbms_lob.substr(column,4000,1)
因此对于更大的HughClob,我不得不在select中使用两个调用:
select dbms_lob.substr(column,4000,1) part1,
dbms_lob.substr(column,4000,4001) part2 from .....
我是从Java应用程序调用的,所以我只是将part1和part2连接起来并作为电子邮件发送。
Cliff Bender answered 2020-07-28T18:36:26Z
1 votes
对于较大的CLOB选择,也可以使用:
SELECT dbms_lob.substr( column_name, dbms_lob.getlength(column_name), 1) FROM foo
Kapitula Alexey answered 2020-07-28T18:36:46Z
1 votes
如果它是CLOB,为什么我们不能to_char该列,然后正常搜索?
建立表格
CREATE TABLE MY_TABLE(Id integer PRIMARY KEY, Name varchar2(20), message clob);
在此表中创建一些记录
INSERT INTO MY_TABLE VALUES(1,'Tom','Hi This is Row one');
INSERT INTO MY_TABLE VALUES(2,'Lucy', 'Hi This is Row two');
INSERT INTO MY_TABLE VALUES(3,'Frank', 'Hi This is Row three');
INSERT INTO MY_TABLE VALUES(4,'Jane', 'Hi This is Row four');
INSERT INTO MY_TABLE VALUES(5,'Robert', 'Hi This is Row five');
COMMIT;
在Clob列中搜索
SELECT * FROM MY_TABLE where to_char(message) like '%e%';
结果
ID NAME MESSAGE
===============================
1 Tom Hi This is Row one
3 Frank Hi This is Row three
5 Robert Hi This is Row five
Raj answered 2020-07-28T18:37:23Z
0 votes
另一种选择是创建一个函数并在每次需要选择clob列时调用该函数。
create or replace function clob_to_char_func
(clob_column in CLOB,
for_how_many_bytes in NUMBER,
from_which_byte in NUMBER)
return VARCHAR2
is
begin
Return substrb(dbms_lob.substr(clob_column
,for_how_many_bytes
,from_which_byte)
,1
,for_how_many_bytes);
end;
然后将该函数称为;
SELECT tocharvalue, clob_to_char_func(tocharvalue, 1, 9999)
FROM (SELECT clob_column AS tocharvalue FROM table_name);
Mustafa answered 2020-07-28T18:37:47Z
-1 votes
添加到答案。
declare
v_result clob;
begin
---- some operation on v_result
dbms_lob.substr( v_result, 4000 ,length(v_result) - 3999 );
end;
/
在Third parameter
Third parameter是您要提取的clob。
Third parameter是您要提取多少个Clob。
Third parameter是您要从哪个单词中提取的。
在上面的示例中,我知道我的Clob大小大于50000,所以我想要最后4000个字符。
Himanshu sharma answered 2020-07-28T18:38:29Z
-2 votes
如果您使用的是SQL * Plus,请尝试以下操作...
set long 8000
select ...
Scott answered 2020-07-28T18:38:49Z