Oracle Internet Application Server Using mod_plsql Release 1.0.1 A83590-02 |
|
Before you can use mod_plsql, you must install the packages in the PL/SQL Web Toolkit in a common schema called owa_public in your Oracle database. Public synonyms are used to enable users to execute the objects in the common schema. Users execute the objects in the common schema with their own privileges, rather than with the privileges of the common schema.
If multiple instances of the PL/SQL Web Toolkit are installed in the database, it is recommended that you drop earlier packages from the individual schemas.
If you did not install the PL/SQL Web Toolkit when you installed mod_plsql, you can install it using the owaload .sql installation script. See "Installing required packages" for more information.
The PL/SQL Web Toolkit contains the following packages:
The htp and htf packages provide subprograms that enable you to generate HTML tags from your stored procedure. For example, the following commands generate a simple HTML document:
create or replace procedure hello AS BEGIN htp.htmlopen; -- generates <HTML> htp.headopen; -- generates <HEAD> htp.title('Hello'); -- generates <TITLE>Hello</TITLE> htp.headclose; -- generates </HEAD> htp.bodyopen; -- generates <BODY> htp.header(1, 'Hello'); -- generates <H1>Hello</H1> htp.bodyclose; -- generates </BODY> htp.htmlclose; -- generates </HTML> END;
These packages also provide print procedures (such as htp.print), which writes its argument to the current document. You can use these print procedures to generate non-standard HTML, to display the return value of functions, or to pass hard-coded text that appears in the HTML document as-is. The generated text is passed to mod_plsql, which then sends it to the user's browser.
The owa_image package contains subprograms that get the coordinates of where the user clicked on an image. You use this for image maps that invoke mod_plsql. Your procedure would look something like:
create or replace procedure process_image (my_img in owa_image.point) x integer := owa_image.get_x(my_img); y integer := owa_image.get_y(my_img); begin /* process the coordinate */ end
The owa_opt_lock package contains subprograms that enable you to impose database optimistic locking strategies, so as to prevent lost updates. Lost updates can occur if a user selects and then attempts to update a row whose values have been changed in the meantime by another user.
mod_plsql cannot use conventional database locking schemes because HTTP is a stateless protocol. The owa_opt_lock package works around this by giving you two ways of dealing with the lost update problem:
These methods are optimistic. That is, they do not prevent other users from performing updates, but they do reject the current update if an intervening update has occurred.
Note This package is included when you install the Toolkit with OAS. mod_plsql does not use it.
The owa_custom package contains the authorize function and the time zone constants used by cookies. Cookies use expiration dates defined in Greenwich Mean Time (GMT). If you are not on GMT, you can specify your time zone using one of these two constants:
If your time zone is recognized by Oracle, you can specify it directly using dbms_server_timezone. The value for this is a string abbreviation for your time zone. (See Oracle Server SQL Reference for a list of recognized time zones. For example, if your time zone is Pacific Standard Time, you can use the following:
dbms_server_timezone constant varchar2(3) := 'PST'
If your time zone is not recognized by Oracle, use dbms_server_gmtdiff to specify the offset of your time zone from GMT. Specify a positive number if your time zone is ahead of GMT, otherwise use a negative number.
dbms_server_gmtdiff constant number := NULL
After making the appropriate changes, you need to reload the package.
Note This package is included when you install the Toolkit with OAS. mod_plsql does not use it.
The owa_content package contains functions and procedures that let you query the content service repository and manipulate document properties. You can use this package to perform tasks, like:
When compiling PL/SQL procedures and packages that use the owa_content package, you may get the following error message:
PLS-00201 identifier `WEBSYS.OWA_CONTENT' must be declared
To avoid this error, when creating a new DAD that uses a non local database, you must enter the SYS username and corresponding password when prompted for a DBA user. Entering the SYSTEM user will not allows the correct grant and rights to be assigned to the database user. If you have entered SYSTEM as the DBA user then you must explicitly perform the grant privilege option as shown below:
SQL>grant all on WEBSYS.OWA_CONTENT to scott
If you are creating a DAD using an existing database user, you must perform the manual grant privilege shown above before using the OWA_CONTENT package.
The PL/SQL samples use the OWA_CONTENT package; so, these steps must be performed before installing the PL/SQL samples.
In the PL/SQL Web Toolkit, the first letter of the parameter name indicates the data type of the parameter:
First character | Datatype | Example |
---|---|---|
c |
VARCHAR2 |
cname IN VARCHAR2 |
n |
INTEGER |
nsize IN INTEGER |
d |
DATE |
dbuf IN DATE |
Many HTML tags have a large number of optional attributes that, if passed as individual parameters to the hypertext procedures or functions, would make the calls cumbersome. In addition, some browsers support non-standard attributes. Therefore, each hypertext procedure or function that generates an HTML tag has as its last parameter cattributes
, an optional parameter. This parameter enables you to pass the exact text of the desired HTML attributes to the PL/SQL procedure.
For example, the syntax for htp.em is:
htp.em(ctext, cattributes);
A call that uses HTML 3.0 attributes might look like the following:
htp.em('This is an example','ID="SGML_ID" LANG="en"');
which would generate the following:
<EM ID="SGML_ID" LANG="en">This is an example</EM>
When you reference an applet using the APPLET tag in an HTML file, the server looks for the applet class file in the directory containing the HTML file. If the applet class file is in another directory, you use the CODEBASE attribute of the APPLET tag to specify that directory.
When you generate an HTML page from mod_plsql and the page references an applet, you must specify the CODEBASE attribute because mod_plsql does not have a concept of a current directory and does not know where to look for the applet class file.
The following example uses htp.appletopen to generate an APPLET tag. It uses the cattributes
parameter to specify the CODEBASE value.
htp.appletopen('myapplet.class', 100, 200, 'CODEBASE="/applets"')
generates
<APPLET CODE="myapplet.class" height=100 width=200 CODEBASE="/applets">
/applets is a virtual path that contains the myapplet.class file.
Cookies can be used to maintain persistent state variables from the client browser:
http://home.netscape.com/newsref/std/cookie_spec.html http://www.virtual.net/Projects/Cookies/
The owa_cookie package enables you to send and retrieve cookies in HTTP headers. It contains the following subprograms that you can use to set and get cookie values:
If you use values of the LONG data type in procedures/functions such as htp.print, htp.prn, htp.prints, htp.ps, or owa_util.cellsprint, be aware that only the first 32K of the LONG data is used. This reason for this limitation is that the LONG data is bound to a varchar2 data type in the procedure/function.
The htp and htf packages allow you to use customized extensions. Therefore, as the HTML standard changes, you can add new functionality similar to the hypertext procedure and function packages to reflect those changes.
Here is an example of customized packages using non-standard <BLINK> and imaginary <SHOUT>tags:
create package nsf as function blink(cbuf in varchar2) return varchar2; function shout(cbuf in varchar2) return varchar2; end; create package body nsf as function blink(cbuf in varchar2) return varchar2 is begin return ('<BLINK>' || cbuf || '</BLINK>'); end; function shout(cbuf in varchar2) return varchar2 is begin return ('<SHOUT>' || cbuf || '</SHOUT>'); end; end; create package nsp as procedure blink(cbufin varchar2); procedure shout(cbufin varchar2); end; create package body nsp as procedure blink(cbufin varchar2) is begin htp.print(nsf.blink(cbuf)); end; procedure shout(cbufin varchar2) is begin htp.print(nsf.shout(cbuf)); end; end;
Now you can begin to use these procedures and functions in your own procedure.
create procedure nonstandard as begin nsp.blink('Gee this hurts my eyes!'); htp.print('And I might ' || nsf.shout('get mad!')); end;
The owa_pattern package contains procedures and functions that you can use to perform string matching and string manipulation with regular expression functionality. The package provides the following subprograms:
These subprograms are overloaded. That is, there are several versions of each, distinguished by the parameters they take. Specifically, there are six versions of MATCH, and four each of AMATCH and CHANGE. The subprograms use the following parameters:
The regular expression in this function can be either a VARCHAR2 or a
owa_pattern.pattern data type. You can create a owa_pattern.pattern data type from a string using the owa_pattern.getpat procedure.
You can create a multi_line data type from a long string using the
owa_text.stream2multi procedure. If a multi_line is used, the rlist parameter specifies a list of chunks where matches were found.
If the line is a string and not a multi_line, you can add an optional output parameter called backrefs. This parameter is a row_list that holds each string in the target that was matched by a sequence of tokens in the regular expression. Here is an example of the owa_pattern.match function:
boolean foundMatch; foundMatch := owa_pattern.match('KAZOO', 'zoo.*', 'i');
This is how the function works: KAZOO is the target where it is searching for the zoo.*
regular expression. The period indicates any character other than newline, and the asterisk matches 0 or more of the preceding characters. In this case, it matches any character other than the newline.
Therefore, this regular expression specifies that a matching target consists of zoo
, followed by any set of characters neither ending in nor including a newline (which does not match the period). The i is a flag indicating that case is to be ignored in the search. In this case, the function returns TRUE, which indicates that a match had been found.
owa_pattern.change can be a procedure or a function, depending on how it is invoked. As a function, it returns the number of changes made. If the flag `g' is not used, this number can only be 0 or 1. The flag `g' specifies that all matches are to be replaced by the regular expression. Otherwise, only the first match is replaced.
The replacement string can use the token ampersand (&), which indicates that the portion of the target that matched the regular expression is to be included in the expression that replaces it. For example:
owa_pattern.change('Cats in pajamas', 'C.+in', '& red ')
The regular expression matches the substring `Cats in'. It then replaces this string with `& red'. The ampersand character, &, indicates `Cats in', since that's what matched the regular expression. Thus, this procedure replaces the string `Cats in pajamas' with 'Cats in red'. If you called this as a function instead of a procedure, the value it would return would not be `Cats in red' but 1, indicating that a single substitution had been made.
|
![]() Copyright © 2000 Oracle Corporation. All Rights Reserved. |
|