在ASA数据库中,output, input子句并不能直接用于SQL语句中,只能用于isql交互命令行里。因此要在存储过程或者程序里生成html格式的结果,还需要自己实现,但也不难。
如:
select * from t
得到结果:
id,col2
1,'中国'
2,'spring'
输出为html格式:
select * from t ;
output to "a.html" format HTML;
执行时间: 0.016 秒
正在将数据导出到 "D:\asa120\BIN32\a.html"
2 行已写入 "D:\asa120\BIN32\a.html"a.html内容为:
id | col2 |
---|---|
1 | 中国 |
2 | spring |
我们可以用SQL语句为之生成这样的结果:
select xmlelement(name "html",
(xmlelement (name "body",
xmlelement(name "thead",
xmlelement(name "tr",
xmlelement(name "th", 'id'),
xmlelement(name "th", 'col2')
)
),
xmlelement(name "tbody",
xmlagg( xmlelement (name "tr",
xmlelement(name "td", id),
xmlelement(name "td", col2)
)))))
) from t;
结果是这样的:
idcol21中国2spring这个结果并没有输出html文件的head, META等信息,下边是一个完整的sql:select xmlelement(name "html",
xmlelement (name "head",
xmlelement(name "title", 't表转换'),
xmlelement(name "META", xmlattributes('Content-Type' as "http-equiv" , 'text/html;charset=GBK' as "content"))
),
(xmlelement (name "body",
xmlelement(name "thead",
xmlelement(name "tr",
xmlelement(name "th", 'id'),
xmlelement(name "th", 'col2')
)
),
xmlelement(name "tbody",
xmlagg( xmlelement (name "tr",
xmlelement(name "td", id),
xmlelement(name "td", col2)
)))))
) from t;
得到的html内容如下:
t表转换content="text/html;charset=GBK" />
idcol2
1中国2spring仔细一看,上边的结果少了
加上xmlelement(name "table", xmlattributes('1' as "border")),即可
完整的sql如下:
select xmlelement(name "html",
xmlelement (name "head",
xmlelement(name "title", 't表转换'),
xmlelement(name "META", xmlattributes('Content-Type' as "http-equiv" , 'text/html;charset=GBK' as "content"))
),
(xmlelement (name "body",
xmlelement(name "table", xmlattributes('1' as "border"),
xmlelement(name "thead",
xmlelement(name "tr",
xmlelement(name "th", 'id'),
xmlelement(name "th", 'col2')
)
),
xmlelement(name "tbody",
xmlagg( xmlelement (name "tr",
xmlelement(name "td", id),
xmlelement(name "td", col2)
)
)
)
)
)
)
) from t;
最终得到的结果如下:
t表转换content="text/html;charset=GBK" />
idcol2
1中国2spring