在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内容为:
-
<html>
-
<head>
-
<META content="text/html;charset=GBK">
-
head>
-
<body>
-
<table border>
-
<tr><th>idth><th>col2th>tr>
-
<tr><td>1td><td>中国td>tr>
-
-
<tr><td>2td><td>springtd>tr>
-
-
table>
-
body>
-
html>
我们可以用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;
结果是这样的:
-
<html><body><thead><tr><th>idth><th>col2th>tr>thead><tbody><tr><td>1td><td>中国td>tr><tr><td>2td><td>springtd>tr>tbody>body>html>
这个结果并没有输出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内容如下:
-
<html>
-
<head>
-
<title>t表转换title>
-
<META http-equiv="Content-Type"
-
content="text/html;charset=GBK" />
-
head>
-
<body>
-
<thead>
-
<tr>
-
<th>idth>
-
<th>col2th>
-
tr>
-
thead>
-
<tbody>
-
<tr>
-
<td>1td>
-
<td>中国td>
-
tr>
-
<tr>
-
<td>2td>
-
<td>springtd>
-
tr>
-
tbody>
-
body>
-
html>
阅读(4936) | 评论(1) | 转发(0) |