从这两个线程,
LONG过时且不赞成使用.甲骨文说,
不要创建包含LONG列的表.请改用LOB列(CLOB,NCLOB).仅支持LONG列以实现向后兼容性.
Oracle还建议您将现有的LONG列转换为LOB列.与LONG列相比,LOB列的限制要少得多.此外,LOB功能在每个版本中都得到了增强,而LONG功能在几个版本中都是静态的.
但是,如果没有此处提到的解决方法,您无法从远程数据库中读取CLOB .
我应该更喜欢在表格中存储一些文字?还是有比这两个更好的解决方案?
当我尝试使用clobC#中的输入和输出创建一个oracle存储过程调用时,我收到以下错误:
ORA-01036: illegal variable name/number\n
Run Code Online (Sandbox Code Playgroud)
这是代码本身:
OracleTransaction transaction = connection.BeginTransaction();
OracleCommand command = connection.CreateCommand();
command.Transaction = transaction;
command.CommandText =
@"declare xx clob;
begin dbms_lob.createtemporary(xx, false, 0);
:tempclob := xx; end;";
command.Parameters.Add(new OracleParameter("tempclob", OracleType.Clob))
.Direction = ParameterDirection.Output;
command.ExecuteNonQuery();
OracleLob tempLob = (OracleLob)command.Parameters[0].Value;
//byte[] tempbuff = new byte[10000];
byte[] tempbuff = System.Text.Encoding.Unicode.GetBytes(generateXMLMessage());
tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);
tempLob.Write(tempbuff, 0, tempbuff.Length);
tempLob.EndBatch();
command.Parameters.Clear();
command.CommandText = "InsertMessageAndGetResponseWRP";
command.CommandType = CommandType.StoredProcedure;
//command.Parameters
//.Add(new OracleParameter("ImportDoc", OracleType.Blob)).Value = tempLob;
command.Parameters.Add(new OracleParameter("iSourceSystem", OracleType.VarChar))
.Value = "XXX";
command.Parameters.Add(new OracleParameter("iMessage", OracleType.Clob))
.Value …Run Code Online (Sandbox Code Playgroud) 根据我读过的文件,CLOB或BLOB的默认存储是内联的,这意味着如果它的大小小于约4k,那么它将保存在表中.
但是当我在Oracle(10.2.0.1.0)中的虚拟表上测试它时,Oracle Monitor(由Allround Automations)的性能和响应表明它正在被表格保留.
这是我的测试场景......
create table clobtest ( x int primary key, y clob, z varchar(100) )
;
insert into clobtest
select object_id, object_name, object_name
from all_objects where rownum < 10001
;
select COLUMN_NAME, IN_ROW
from user_lobs
where table_name = 'CLOBTEST'
;
Run Code Online (Sandbox Code Playgroud)
这显示:是(建议Oracle将clob存储在行中)
select x, y from CLOBTEST where ROWNUM < 1001 -- 8.49 seconds
select x, z from CLOBTEST where ROWNUM < 1001 -- 0.298 seconds
Run Code Online (Sandbox Code Playgroud)
因此,在这种情况下,CLOB值的最大长度为30个字符,因此应始终为内联.如果我运行Oracle Monitor,它会显示一个LOB.Length,后面跟着返回的每一行的LOB.Read(),再次表明clob值是用表保存的.
我也试过像这样创建表
create table clobtest
( x int primary key, y …Run Code Online (Sandbox Code Playgroud) 我正在寻找BLOB和CLOB数据的真正好解释.我正在寻找用简单的英语解释的伟大.
我CLOB(2000000)在db2(v10)数据库中有一个字段,我想UPDATE对它运行一个简单的查询,将每个出现的"foo"替换为"baaz".
由于该字段的内容超过32k,我收到以下错误:
"{some char data from field}" is too long.. SQLCODE=-433, SQLSTATE=22001
Run Code Online (Sandbox Code Playgroud)
如何更换值?
更新:查询如下(将UPDATE更改为SELECT以便于测试):
SELECT REPLACE(my_clob_column, 'foo', 'baaz') FROM my_table WHERE id = 10726
Run Code Online (Sandbox Code Playgroud)
更新2
正如mustaccio所指出的那样,REPLACE对CLOB字段不起作用(或者至少没有VARCHAR对输入的数据进行强制转换- 在我的情况下,由于数据大小超过32k而不可能) - 问题是关于找到一种替代方法来REPLACE实现CLOB字段的功能.
谢谢,克里西
目前我有这个代码的查询,to_char(CLOB_COLUM) like %s但以下不适用于非常大的clob.是否有另一种解决方案来检查此列是否包含某些字符串.使用oracle 11.2.0.4.0
在DB2触发器中,我需要比较CLOB字段的值.就像是:
IF OLD_ROW.CLOB_FIELD != UPDATED_ROW.CLOB_FIELD
Run Code Online (Sandbox Code Playgroud)
但"!="不适用于比较CLOB.
比较它的方法是什么?
编辑添加:
如果在更新期间更改了Clob字段,则我的触发器需要执行某些操作.这就是我需要比较触发器代码中的2个CLOB的原因. 我正在寻找有关如何做到这一点的一些详细信息
我有一个包含数据的clob
<?xml version='1.0' encoding='UTF-8'?><root available-locales="en_US" default-locale="en_US"><static-content language-id="en_US"><![CDATA[<script type="text/javascript">
function change_case()
{
alert("here...");
document.form1.type.value=document.form1.type.value.toLowerCase();
}
</script>
<form name=form1 method=post action=''''>
<input type=text name=type value=''Enter USER ID'' onBlur="change_case();">
<input type=submit value=Submit> </form>
</form>]]></static-content></root>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我想用onblur提取线
<input type=text name=type value=''Enter USER ID'' onblur="change_case();">
Run Code Online (Sandbox Code Playgroud) 假设我有一个班级:
class EventTransaction {
.....
private Clob dataXML;
public Clob getDataXML() {
return dataXML;
}
public void setDataXML(Clob dataXML) {
this.dataXML = dataXML;
}
}
Run Code Online (Sandbox Code Playgroud)
和Hibernate映射xml:
<property name="dataXML" type="java.sql.Clob">
<column name="XML" sql-type="CLOB"/>
</property>
Run Code Online (Sandbox Code Playgroud)
在java代码中,如何将String转换为Clob,反之亦然,以保存到数据库中:
Ex: EventTransaction et = new EventTransaction();
String xml = "fdfsafafafa";
et.setDataXML(convertStringToClob(xml));
HibernateTemplate.saveOrUpdate(et);
Run Code Online (Sandbox Code Playgroud)
你能帮忙解决一下如何实现convertStringToClob函数(String data);
谢谢,
我想知道在下面描述的场景中我做错了什么.我为一个项目评估一些SQL Server版本,并在简单的Java设置中使用不同的DB类型.我使用Eclipse,Java 6(1.6u45),驱动程序sqljdbc4.jar,Sql Server 2012(默认安装),Windows 7,我正在尝试从测试数据库/表中编写和读回不同的数据库类型.对于NVARCHAR(n或max)和/或VARCHAR(n或max)类型的列,使用setClob()和setCharacterStream()方法写入DB时没有任何问题.但是,当我尝试回读Clobs时,我只能使用getCharacterStream().由于我无法理解的原因,我不能将getClob()与上面列出的任何一种DB类型一起使用.我得到以下异常堆栈:
com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from varchar to CLOB is unsupported.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
at com.microsoft.sqlserver.jdbc.DataTypes.throwConversionError(DataTypes.java:1117)
at com.microsoft.sqlserver.jdbc.ServerDTVImpl.getValue(dtv.java:2419)
at com.microsoft.sqlserver.jdbc.DTV.getValue(dtv.java:176)
at com.microsoft.sqlserver.jdbc.Column.getValue(Column.java:113)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:1981)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:1966)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getClob(SQLServerResultSet.java:2488)
at main.com.test.Test.main(Test.java:77)
Run Code Online (Sandbox Code Playgroud)
我找不到这个例外的任何参考.MS文档声称NVARCAHR/VARCHAR列支持getClob().代码非常简单,一个插入然后"Select*from table"然后定位resultset.getxxx(position)调用.提前感谢任何建议或想法.