1.对于以下代码,我没有得到任何输出。 DBMS输出窗口在执行此代码后不显示任何内容。可能是什么问题呢? 2.我试图通过引用属性[@id =" 1"]来获取一个名称,是否可以获得所有名称?
declare
x varchar(100);
c1 sys_refcursor;
xml clob:=
'<?xml version="1.0"?>
<Com>
<Employee id="1">
<Name>John</Name>
<Age>21</Age>
<Phone>111111111</Phone>
</Employee>
<Employee id="2">
<Name>Adam</Name>
<Age>22</Age>
<Phone>22222222</Phone>
</Employee>
<Employee id="3">
<Name>David</Name>
<Age>22</Age>
<Phone>333333333</Phone>
</Employee>
<Employee id="4">
<Name>Roy</Name>
<Age>22</Age>
<Phone>44444444</Phone>
</Employee>
</Com>';
xsl clob:=
'<?xml version="1.0"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
<xsl:template match="/">
<xsl:for-each select="Com/Employee[@id=''1'']">
<![CDATA[<Com>]]>
<xsl:value-of select="Name"/>
<![CDATA[</Com>]]>
</xsl:for-each>
</xsl:template>
</xsl:transform>';
function fun1 return sys_refcursor
as
c2 sys_refcursor;
begin
open c2 for select Names_List from XMLTABLE('/Com/Employee'
PASSING XMLTYPE(XMLTRANSFORM(xmltype(xml),xmltype(xsl)).GetClobVal())
columns Names_List varchar(100) path 'Name');
return c2;
end;
begin
c1:=fun1;
loop
fetch c1 into x;
exit when c1%notfound;
dbms_output.put_line('Names : '|| x);
end loop;
end;
答案 0 :(得分:0)
用这个改变OPEN C2 ...:
"AWT-EventQueue-0 2016.2.1#WS-162.1447.27 WebStorm, eap:false, os:Linux 4.4.0-34-generic, java-version:JetBrains s.r.o 1.8.0_76-release-b216" prio=0 tid=0x0 nid=0x0 waiting on condition
java.lang.Thread.State: WAITING
on java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@2e970c27
at sun.misc.Unsafe.park(Native Method)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at sun.awt.SunToolkit.awtLockWait(SunToolkit.java:267)
at sun.awt.X11.XToolkit.getCurrentServerTime(XToolkit.java:1462)
at sun.awt.X11.XClipboard.setContentsNative(XClipboard.java:93)
at sun.awt.datatransfer.SunClipboard.setContents(SunClipboard.java:106)
at com.intellij.openapi.editor.impl.CaretImpl.f(CaretImpl.java:1249)
at com.intellij.openapi.editor.impl.CaretImpl.a(CaretImpl.java:1239)
at com.intellij.openapi.editor.impl.CaretImpl$$Lambda$370/774284532.run(Unknown Source)
at com.intellij.openapi.editor.impl.CaretModelImpl.doWithCaretMerging(CaretModelImpl.java:437)
at com.intellij.openapi.editor.impl.CaretImpl.a(CaretImpl.java:1147)
at com.intellij.openapi.editor.impl.CaretImpl.setSelection(CaretImpl.java:1137)
at com.intellij.openapi.editor.impl.CaretImpl.setSelection(CaretImpl.java:1129)
at com.intellij.openapi.editor.impl.SelectionModelImpl.setSelection(SelectionModelImpl.java:149)
at com.intellij.openapi.editor.impl.EditorImpl.a(EditorImpl.java:4636)
at com.intellij.openapi.editor.impl.EditorImpl.e(EditorImpl.java:4548)
at com.intellij.openapi.editor.impl.EditorImpl.a(EditorImpl.java:4394)
at com.intellij.openapi.editor.impl.EditorImpl$$Lambda$852/372658132.run(Unknown Source)
at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:129)
at com.intellij.openapi.editor.impl.EditorImpl.k(EditorImpl.java:4394)
at com.intellij.openapi.editor.impl.EditorImpl.access$13000(EditorImpl.java:125)
at com.intellij.openapi.editor.impl.EditorImpl$MyMouseMotionListener.mouseDragged(EditorImpl.java:6193)
at java.awt.Component.processMouseMotionEvent(Component.java:6581)
at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:3342)
at java.awt.Component.processEvent(Component.java:6302)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4542)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at com.intellij.ide.IdeEventQueue.e(IdeEventQueue.java:863)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:695)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:385)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
"ApplicationImpl pooled thread 33" prio=0 tid=0x0 nid=0x0 runnable
java.lang.Thread.State: RUNNABLE
"ApplicationImpl pooled thread 30" prio=0 tid=0x0 nid=0x0 runnable
java.lang.Thread.State: RUNNABLE
at sun.management.ThreadImpl.dumpThreads0(Native Method)
at sun.management.ThreadImpl.dumpAllThreads(ThreadImpl.java:454)
at com.intellij.diagnostic.ThreadDumper.dumpThreadsToFile(ThreadDumper.java:58)
at com.intellij.diagnostic.ThreadDumper.getThreadDumpInfo(ThreadDumper.java:48)
at com.intellij.diagnostic.PerformanceWatcher.dumpThreads(PerformanceWatcher.java:273)
at com.intellij.diagnostic.PerformanceWatcher.b(PerformanceWatcher.java:230)
at com.intellij.diagnostic.PerformanceWatcher.c(PerformanceWatcher.java:210)
at com.intellij.diagnostic.PerformanceWatcher.access$000(PerformanceWatcher.java:58)
at com.intellij.diagnostic.PerformanceWatcher$1.run(PerformanceWatcher.java:101)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:229)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"process reaper" prio=0 tid=0x0 nid=0x0 runnable
java.lang.Thread.State: RUNNABLE
(in native)
at java.lang.UNIXProcess.waitForProcessExit(Native Method)
at java.lang.UNIXProcess.lambda$initStreams$3(UNIXProcess.java:290)
at java.lang.UNIXProcess$$Lambda$20/966209523.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
当您收到错误时,请逐步进行操作。在XMLTRANSFORM之后你有:
OPEN c2 FOR SELECT Names_List FROM XMLTABLE('/Com' PASSING XMLTRANSFORM(xmltype(xml),xmltype(xsl)) columns Names_List varchar(100) path '/Com');
没有员工标记。比XMLTRANSFORM返回XMLType。您将从XMLType获取CLOB并将其转换为XMLType。为什么呢?