Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
32
Добавлен:
16.04.2013
Размер:
4.96 Mб
Скачать

Embedding PL/SQL Code in Web Pages (PL/SQL Server Pages)

<TH>Price</TH>

<TH>Picture</TH>

</TR>

<%

for item in (select * from catalog order by price desc) loop if item.price > minprice then

color := ’#CCCCFF’; else

color := ’#CCCCCC’; end if;

%>

<TR BGCOLOR="<%= color %>">

<TD><A HREF="<%= item.url %>"><%= item.product %></A></TD> <TD><BIG><%= item.price %></BIG></TD>

<TD><IMG SRC="<%= item.picture %>"></TD> </TR>

<% end loop; %> </TABLE> </BODY> </HTML>

Sample HTML Form to Call a PL/SQL Server Page

Here is a bare-bones HTML form that allows someone to enter a price, and then calls the SHOW_CATALOG_PARTIAL stored procedure passing the entered value as the MINPRICE parameter.

To avoid coding the entire URL of the stored procedure in the ACTION= attribute of the form, we can make the form a PSP file so that it goes in the same directory as the PSP file it calls. Even though this HTML file has no PL/SQL code, we can give it a

.psp extension and load it as a stored procedure into the database. When the stored procedure is run, it just displays the HTML exactly as it appears in the file.

<html>

<body>

<form method="POST" action="show_catalog_partial"> <p>Enter the minimum price you want to pay: <input type="text" name="minprice">

<input type="submit" value="Submit"> </form>

</body>

</html>

Developing Web Applications with PL/SQL 13-35

Embedding PL/SQL Code in Web Pages (PL/SQL Server Pages)

Note: An HTML form is different from other forms you might produce with tools and programming languages. It is part of an HTML file, delimited by <FORM> and </FORM> tags, where someone can make choices and enter data, then transmit those choices to a server-side program using the CGI protocol.

To produce a complete application using PSP, you might need to learn the syntax of <INPUT>, <SELECT>, and other HTML tags related to forms.

Including JavaScript in a PSP File

To produce an elaborate HTML file, perhaps including dynamic content such as JavaScript, you can simplify the source code by implementing it as a PSP. This technique avoids having to deal with nested quotation marks, escape characters, concatenated literals and variables, and indentation of the embedded content.

For example, here is how an HTML file containing JavaScript might be generated using a PSP:

<%@ page language="PL/SQL" %> <%@ plsql procedure="graph" %> <%!

-- Begin with a date that does not exist in the audit table last_timestamp date := sysdate + 1;

%>

<html>

<head>

<title>Usage Statistics</title> <script language="JavaScript"> <!--

d=document

//Draw a horizontal graph line using a graphic that is stretched

//by a scaling factor.

function graph(howmuch)

{

preamble = "<img src='/images/graph_line.gif' height='8' width='" climax = howmuch * 4;

denouement = "'> (" + howmuch + ")\n" d.write( preamble + climax + denouement )

}

13-36 Oracle Database Application Developer's Guide - Fundamentals

Embedding PL/SQL Code in Web Pages (PL/SQL Server Pages)

// --> </script> </head>

<body text="#000000" bgcolor="#FFFFFF"> <h1>Usage Statistics</h1>

<table border=1>

<%

--For each day, count how many times each procedure was called. for item in (select trunc(time_stamp) t, count(*) n, procname p

from audit_table group by trunc(time_stamp), procname order by trunc(time_stamp) desc, procname)

loop

--At the start of each day's data, print the date.

if item.t != last_timestamp then htp.print('<tr><td colspan=2><font size="+2">'); htp.print(htf.bold(item.t)); htp.print('</font></td></tr>');

last_timestamp := item.t; end if;

%>

<tr><td><%= item.p %></a>: <td>

<!-- Render an image of variable width to represent the data value. --> <script language="JavaScript">

<!--

graph(<%= item.n %>) // -->

</script>

</td>

</tr>

<% end loop; %>

</table>

</body>

</html>

Developing Web Applications with PL/SQL 13-37

Тут вы можете оставить комментарий к выбранному абзацу или сообщить об ошибке.

Мы не исправляем ошибки в тексте (почему?), но будем благодарны, если вы все же напишите об ошибках.

Соседние файлы в папке Oracle 10g