gpt4 book ai didi

groovy - 如何使用 Groovy 将 clob 转换为字符串?

转载 作者:行者123 更新时间:2023-12-04 22:30:47 25 4
gpt4 key购买 nike

我想从数据类型为clob的表中选择数据。
所以结果就像 oracle.sql.CLOB@12fe54d
我想将数据显示为表格中出现的字符串。

在 groovy 我试过这个:

rowTest = sql.firstRow("select name from table where id=10")
clobTest = (oracle.sql.CLOB)rowTest[0]

byte_stream_test = clobTest.getBinaryStream()
if( byte_stream_test == null ) { println "Test: Received null stream!" }

byte[] byte_array_test = new byte[10]
int bytes_read_test = byte_stream_test.read(byte_array_test)

print "Read $bytes_read_test bytes from the clob!"

sql.connection.close()

我有以下错误:
---- A working test of writing and then reading a blob into an Oracle DB ---
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: oracle.sql.CLOB.getBinaryStream() is applicable for argument types: () values: []
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:56)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at Test2.run(Test2.groovy:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1207)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)
at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:901)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:884)
at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:406)
at org.codehaus.groovy.runtime.InvokerHelper$runScript.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at Test2.main(Test2.groovy)

你能帮我解决这个问题吗,谢谢

最佳答案

试试下面的代码:

  rowTest = sql.firstRow("select name from table where id=10")
clobTest = (oracle.sql.CLOB)rowTest[0]
bodyText = clobTest?.asciiStream.text
println bodyText

关于groovy - 如何使用 Groovy 将 clob 转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27070403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com