我在查找数据类型为XMLType的表中的行时遇到问题,我正在寻找名称“ PrimeSub”和值“ Y”。谢谢
private void preparePageFormat(PageFormat pf)
{
Paper ppr = new Paper();
pf.setOrientation(PageFormat.LANDSCAPE);
MediaSizeName msn = MediaSizeName.NA_LEGAL;
MediaSize msz = MediaSize.getMediaSizeForName(msn);
double inch = 72.0;
width = msz.getX(MediaSize.INCH) * inch;
height = msz.getY(MediaSize.INCH) * inch;
ppr.setSize(a4Width, a4Height);
ppr.setImageableArea(0, 0, a4Width, a4Height);
pf.setPaper(ppr);
}
main()
{
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pageFormat = job.defaultPage();
preparePageFormat(pageFormat);
job.setPrintable(previewPanel.getPrintable(), pageFormat);
PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
attributeSet.add(OrientationRequested.LANDSCAPE);
attributeSet.add(MediaSizeName.NA_LEGAL);
if (job.printDialog(attributeSet))
{
attributeSet.add(new MediaPrintableArea((float)pageFormat.getImageableX(),(float)pageFormat.getImageableY(),
(float)pageFormat.getImageableWidth(),(float)pageFormat.getImageableHeight(),MediaPrintableArea.INCH));
job.print(attributeSet);
}
}
答案 0 :(得分:0)
您没有发布表名或结构,因此在这里我使用mytable
作为表名,使用xmlcol
作为xmltype列。顶部的WITH子句仅用于提供测试数据。
with mytable as (select xmltype('<attributes>
<upper_lvl_ver_desc>
<Name>AABB</Name>
<Description>pkListValue</Description>
<Value/>
</upper_lvl_ver_desc>
<upper_lvl_ver_desc>
<Name>GL_PS_ALLOWED</Name>
<Description>pkListValue</Description>
<Value/>
</upper_lvl_ver_desc>
<upper_lvl_ver_desc>
<Name>PrimeSub</Name>
<Description>pkListValue</Description>
<Value>Y</Value>
</upper_lvl_ver_desc>
</attributes>') as xmlcol from dual)
-- query starts here
select xmlcol
from mytable
inner join XMLTable('/attributes/upper_lvl_ver_desc' PASSING mytable.xmlcol
COLUMNS c_name varchar2(50) PATH 'Name',
c_value varchar2(1) PATH 'Value') atts
on c_name = 'PrimeSub' and c_value = 'Y'
;
该方法似乎有点违反直觉,但这是Oracle建议这样做的一种方法。使用XMLTable函数将XML列作为伪表加入,将其转换为可以在SQL中轻松操作的关系数据。 You can read more about it here。