PSP 页是嵌入 PL/SQL 脚本的 HTML 页,与 HTML 内容相分离。应用程序逻辑(嵌入的 PL/SQL 脚本)与布局逻辑 (HTML) 的这种分离使 PSP 页的开发和维护变得容易。
...
for c1 in (select id, title, descr, ctxsys.score(1) scr
from docs
where ctxsys.contains(content,v_query,1) > 0
order by ctxsys.score(1) desc)
loop
htp.p('<table cellpadding=0 cellspacing=0 border=0>');
htp.p('<tr>');
htp.p('<td><b>Precision score</b>: ');
htp.p('<font color="#ff0000">'||c1.scr||'%</font>, <b>');
htp.p('</td>');
htp.p('<td>'||c1.id||'</td>');
htp.p('<td>'||c1.title||'</td>');
htp.p('<td>'||c1.descr||'</td>');
htp.p('</tr></table>');
end loop;
...
在以上的示例代码中,开发人员必须使用程序变量作为输出字符串来编写 HTML 输出代码。
在 PSP 中,目的是将逻辑与布局相分离。它是 HTML(页面的静态部分)与 PL/SQL(动态内容部分)的混合体。我们可以在 <% 和 %> 中包含任何 PL/SQL 语句。
有关 PSP 语法的更多信息,请参阅 Oracle8i Application 开发人员指南。
让我们创建一个简单的表。在 sqlplus 中……
create table docs (id number primary key, text varchar2(2000));让我们插入一些值
insert into docs (id,text) values(1,'This is a technical overview of the improvements found in interMedia Text, version 8.1.6. '); insert into docs(id,text) values(2,'This is intended for an audience familiar with version 8.1.5. If you are new to interMedia Text, please start with Oracle8i interMedia Text 8.1.5 - Technical Overview '); insert into docs(id,text) values(3,'The improvements in structured document support include indexing and searching attribute text, nested within for sophisticated queries, doctype-limited tag detection, dynamic add section for existing indexes, and a new AUTO sectioner which requires no section pre-definition '); insert into docs(id,text) values(4,'Multi-lingual databases can now store documents of different languages in a single column, thanks to the new MULTI lexer'); insert into docs(id,text) values(5,'Other interesting features include limited parallel indexing, more flexible stem and fuzzy operators, and in-memory document services ');现在我们创建一个文本索引
create index docs_index on docs(text) indextype is ctxsys.context;
PSP 的文件必须具有扩展名 .psp(在此例中为 sample.psp)。
<%@ plsql parameter="query" default="null" %>
<html>
<head>
<title>PSP Sample</title>
</head>
<body>
<%
If query is null Then
-- This part of the script allows a person
-- to enter data on an HTML form.
%>
<center>
<FORM METHOD=POST ACTION="sample">
<P>Search for <INPUT TYPE=TExt SIZE=50 MAXLENGTH=50 NAME="query">
<INPUT TYPE=SUBMIT VALUE="Search">
</FORM>
<% Else
%>
<h2> PSP Sample</h2>
<p>
<%!
color varchar2(6) := 'ffffff';
%>
<center>
<FORM METHOD=POST ACTION="sample">
<P>Search for
<INPUT TYPE=TExt SIZE=50 MAXLENGTH=30 NAME="query" VALUE=<%= query %>>
<INPUT TYPE=SUBMIT VALUE="Search">
</FORM>
<p>
<table border="1" cellpadding="4" cellspacing="0">
<tr bgcolor="#6699CC">
<th>Doc ID</th>
<th>Text</th>
</tr>
<%
for c in (select id, text
from docs where contains(text,query) >0
) loop
%>
<tr bgcolor="#<%= color %>">
<td> <%= c.id %> </td>
<td> <%= c.text %> </td>
</tr>
<%
if (color = 'ffffff') then
color := 'eeeeee';
else
color := 'ffffff';
end if;
end loop;
%>
</table></center>
<% End if;%>
<hr>
</body>
</html>
loadpsp -replace -user oalonso/oalonso sample.psp在正确编译 PSP 后,可以通过在 web 浏览器中检索 URL 来运行它。例如:
http://mymachine.name/sample还可以指定不同的端口号和 DAD。例如,如果使用 WebDB 监听器:
http://oalonso-sun.us.oracle.com:8080/oalonso2/sample