228 OWA_UTIL
The OWA_UTIL
package contains utility subprograms for performing operations such as getting the value of CGI environment variables, printing the data that is returned to the client, and printing the results of a query in an HTML table.
See Also:
For more information about implementation of this package:
This chapter contains the following topics:
228.1 OWA_UTIL Overview
The OWA_UTIL
package contains three types of utility subprograms.
-
Dynamic SQL Utilities enable you to produce pages with dynamically generated SQL code.
-
HTML utilities enable you to retrieve the values of CGI environment variables and perform URL redirects.
-
Date utilities enable correct date-handling. Date values are simple strings in HTML, but are treated as a datatype by the Oracle database.
228.2 OWA_UTIL Types
OWA_UTIL
uses Types to specify creating information.
228.2.1 DATETYPE Datatype
The TODATE Function converts an item of this type to the type DATE
, which is understood and properly handled as data by the database. The procedure CHOOSE_DATE Procedure enables the user to select the desired date.
TYPE dateType IS TABLE OF VARCHAR2(10) INDEX BY BINARY_INTEGER;
Related Topics
228.2.2 IDENT_ARR Datatype
This datatype is used for an array.
TYPE ident_arr IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
228.3 Summary of OWA_UTIL Subprograms
This table lists the OWA_UTIL
subprograms and briefly describes them.
Table 228-1 OWA_UTIL Package Subprograms
Subprogram | Description |
---|---|
Prepares a SQL query and binds variables to it |
|
Prints a calendar |
|
Prints the contents of a query in an HTML table |
|
Generates HTML form elements that allow the user to select a date |
|
Returns the value of the specified CGI environment variable |
|
Returns the full virtual path for the PL/SQL Gateway |
|
Returns the name of the procedure that is invoked by the PL/SQL Gateway |
|
Closes the HTTP header |
|
Generates a HTML form element that contains data from a query |
|
Generates the Content-type line in the HTTP header |
|
Generates a list of all CGI environment variables and their values |
|
Generates the Location line in the HTTP header |
|
Prints a page generated by the HTP and HTF packages in SQL*Plus |
|
Prints the source for the specified subprogram |
|
Prints a line that says that the page is generated by the PL/SQL Agent |
|
Generates the Status line in the HTTP header |
|
Prints the data from a table in the database as an HTML table |
|
Converts dateType data to the standard PL/SQL date type |
|
Returns information on the caller of the procedure. |
228.3.1 BIND_VARIABLES Function
This function prepares a SQL query by binding variables to it, and stores the output in an opened cursor. Use this function as a parameter to a procedure sending a dynamically generated query. Specify up to 25 bind variables.
Syntax
OWA_UTIL.BIND_VARIABLES( theQuery IN VARCHAR2 DEFAULT NULL, bv1Name IN VARCHAR2 DEFAULT NULL, bv1Value IN VARCHAR2 DEFAULT NULL, bv2Name IN VARCHAR2 DEFAULT NULL, bv2Value IN VARCHAR2 DEFAULT NULL, bv3Name IN VARCHAR2 DEFAULT NULL, bv3Value IN VARCHAR2 DEFAULT NULL, ... bv25Name IN VARCHAR2 DEFAULT NULL, bv25Value IN VARCHAR2 DEFAULT NULL) RETURN INTEGER;
Parameters
Table 228-2 BIND_VARIABLES Function Parameters
Parameter | Description |
---|---|
|
The SQL query statement which must be a SELECT statement |
|
The name of the variable |
|
The value of the variable |
Return Values
An integer identifying the opened cursor.
228.3.2 CALENDARPRINT Procedures
These procedures creates a calendar in HTML with a visible border. Each date in the calendar can contain any number of hypertext links.
This procedure has 2 versions.
-
Version 1 uses a hard-coded query stored in a varchar2 string.
-
Version 2 uses a dynamic query prepared with the BIND_VARIABLES Function.
Syntax
OWA_UTIL.CALENDARPRINT( p_query IN VARCHAR2, p_mf_only IN VARCHAR2 DEFAULT 'N'); OWA_UTIL.CALENDARPRINT( p_cursor IN INTEGER, p_mf_only IN VARCHAR2 DEFAULT 'N');
Parameters
Table 228-3 CALENDARPRINT Procedure Parameters
Parameter | Description |
---|---|
|
A PL/SQL query. |
|
A PL/SQL cursor containing the same format as |
|
If " |
Usage Notes
Design your query as follows:
-
The first column is a DATE. This correlates the information produced by the query with the calendar output generated by the procedure.
-
The query output must be sorted on this column using ORDER BY.
-
The second column contains the text, if any, that you want printed for that date.
-
The third column contains the destination for generated links. Each item in the second column becomes a hypertext link to the destination given in this column. If this column is omitted, the items in the second column are simple text, not links.
228.3.3 CELLSPRINT Procedures
This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
There are nine versions of this procedure:
-
The first version passes the results of a query into an index table. Perform the query and CELLSPRINT does the formatting. To have more control in generating an HTML table from the output of an SQL query, use the FORMAT_CELL Function in the " HTF" package.
-
The second and third versions display rows (up to the specified maximum) returned by the query or cursor.
-
The fourth and fifth versions exclude a specified number of rows from the HTML table. Use the fourth and fifth versions to scroll through result sets by saving the last row seen in a hidden form element.
-
The sixth through ninth versions are the same as the first four versions, except that they return a row count output parameter.
Syntax
OWA_UTIL.CELLSPRINT( p_colCnt IN INTEGER, p_resultTbl IN vc_arr,
p_format_numbers IN VARCHAR2 DEFAULT NULL);
OWA_UTIL.CELLSPRINT( p_theQuery IN VARCHAR2, p_max_rows IN NUMBER DEFAULT 100, p_format_numbers IN VARCHAR2 DEFAULT NULL); OWA_UTIL.CELLSPRINT( p_theCursor IN INTEGER, p_max_rows IN NUMBER DEFAULT 100, p_format_numbers iN VARCHAR2 DEFAULT NULL); OWA_UTIL.CELLSPRINT( p_theQuery IN VARCHAR2, p_max_rows IN NUMBER DEFAULT 100, p_format_numbers IN VARCHAR2 DEFAULT NULL, p_skip_rec IN NUMBER DEFAULT 0, p_more_data OUT BOOLEAN); OWA_UTIL.CELLSPRINT( p_theCursor IN INTEGER, p_max_rows IN NUMBER DEFAULT 100, p_format_numbers IN VARCHAR2 DEFAULT NULL, p_skip_rec IN NUMBER DEFAULT 0, p_more_data OUT BOOLEAN); OWA_UTIL.CELLSPRINT( p_theQuery IN VARCHAR2, p_max_rows IN NUMBER DEFAULT 100, p_format_numbers IN VARCHAR2 DEFAULT NULL, p_reccnt OUT NUMBER); OWA_UTIL.CELLSPRINT( p_theCursor IN INTEGER, p_max_rows IN NUMBER DEFAULT 100, p_format_numbers IN VARCHAR2 DEFAULT NULL, p_reccnt OUT NUMBER); OWA_UTIL.CELLSPRINT( p_theQuery IN VARCHAR2, p_max_rows IN NUMBER DEFAULT 100, p_format_numbers IN VARCHAR2 DEFAULT NULL, p_skip_rec IN NUMBER DEFAULT 0, p_more_data OUT BOOLEAN p_reccnt OUT NUMBER); OWA_UTIL.CELLSPRINT( p_theCursor IN INTEGER, p_max_rows IN NUMBER DEFAULT 100, p_format_numbers IN VARCHAR2 DEFAULT NULL, p_skip_rec IN NUMBER DEFAULT 0, p_more_data OUT BOOLEAN, p_reccnt OUT NUMBER);
Parameters
Table 228-4 CELLSPRINT Procedure Parameters
Parameter | Description |
---|---|
|
A PL/SQL query. |
|
The number of columns in the table. |
|
A SQL |
|
A cursor ID. This can be the return value from the BIND_VARIABLES Function. |
|
The maximum number of rows to print. |
|
If the value of this parameter is not |
|
The number of rows to exclude from the HTML table. |
|
|
|
The number of rows that have been returned by the query. This value does not include skipped rows (if any). |
|
The index table which will contain the result of the query. Each entry in the query will correspond to one column value. |
Examples
This procedure generates
<tr><td>QueryResultItem</td><td>QueryResultItem</td></tr>...
228.3.4 CHOOSE_DATE Procedure
This procedure generates three HTML form elements that allow the user to select the day, the month, and the year.
Syntax
OWA_UTIL.CHOOSE_DATE( p_name IN VARCHAR2, p_date IN DATE DEFAULT SYSDATE);
Parameters
Table 228-5 CHOOSE_DATE Procedure Parameters
Parameter | Description |
---|---|
|
The name of the form elements. |
|
The initial date that is selected when the HTML page is displayed. |
Usage Notes
-
The parameter in the procedure that receives the data from these elements must be a GET_CGI_ENV Function.
-
Use the TODATE Function to convert the GET_CGI_ENV Function value to the standard Oracle DATE datatype.
Examples
<SELECT NAME="p_name" SIZE="1"> <OPTION value="01">1 ... <OPTION value="31">31 </SELECT> - <SELECT NAME="p_name" SIZE="1"> <OPTION value="01">JAN ... <OPTION value="12">DEC </SELECT> - <SELECT NAME="p_name" SIZE="1"> <OPTION value="1992">1992 ... <OPTION value="2002">2002 </SELECT>
228.3.5 GET_CGI_ENV Function
This function returns the value of the specified CGI environment variable.
Syntax
OWA_UTIL.GET_CGI_ENV( param_name IN VARCHAR2) RETURN VARCHAR2;
Parameters
Table 228-6 GET_CGI_ENV Function Parameters
Parameter | Description |
---|---|
|
The name of the CGI environment variable. It is case-insensitive. |
Return Values
The value of the specified CGI environment variable. If the variable is not defined, the function returns NULL
.
228.3.6 GET_OWA_SERVICE_PATH Function
This function returns the full virtual path of the PL/SQL Gateway that is handling the request.
Syntax
OWA_UTIL.GET_OWA_SERVICE_PATH RETURN VARCHAR2;
Return Values
A virtual path of the PL/SQL Gateway that is handling the request.
228.3.7 GET_PROCEDURE Function
This function returns the name of the procedure that is being invoked by the PL/SQL Gateway.
Syntax
OWA_UTIL.GET_PROCEDURE RETURN VARCHAR2;
Return Values
The name of a procedure, including the package name if the procedure is defined in a package.
228.3.8 HTTP_HEADER_CLOSE Procedure
This procedure generates a newline character to close the HTTP header.
Syntax
OWA_UTIL.HTTP_HEADER_CLOSE;
Return Values
A newline character, which closes the HTTP header.
Usage Notes
-
Use this procedure if you have not closed the header by using the
bclose_header
parameter in calls such as MIME_HEADER Procedure, REDIRECT_URL Procedure, or STATUS_LINE Procedure -
The HTTP header must be closed before any
HTP.PRINT
orHTP.PRN
calls.
228.3.9 LISTPRINT Procedure
This procedure generates an HTML selection list form element from the output of a SQL query.
There are two versions of this procedure.
-
The first version contains a hard-coded SQL query.
-
The second version uses a dynamic query prepared with the BIND_VARIABLES Function.
Syntax
OWA_UTIL.LISTPRINT( p_theQuery IN VARCHAR2, p_cname IN VARCHAR2, p_nsize IN NUMBER, p_multiple IN BOOLEAN DEFAULT FALSE); OWA_UTIL.LISTPRINT( p_theCursor IN INTEGER, p_cname IN VARCHAR2, p_nsize IN NUMBER, p_multiple IN BOOLEAN DEFAULT FALSE);
Parameters
Table 228-7 LISTPRINT Procedure Parameters
Parameter | Description |
---|---|
|
The SQL query. |
|
The cursor ID. This can be the return value from the BIND_VARIABLES Function. |
|
The name of the HTML form element. |
|
The size of the form element (this controls how many items the user can see without scrolling). |
|
Whether multiple selection is permitted. |
Usage Notes
The columns in the output of the query are handled in the following manner:
-
The first column specifies the values that are sent back. These values are for the
VALUE
attribute of theOPTION
tag. -
The second column specifies the values that the user sees.
-
The third column specifies whether or not the row is marked as
SELECTED
in theOPTION
tag. If the value is notNULL
, the row is selected.
Examples
<SELECT NAME="p_cname" SIZE="p_nsize"> <OPTION SELECTED value='value_from_the_first_column'>value_from_the_second_column <OPTION SELECTED value='value_from_the_first_column'>value_from_the_second_column ... </SELECT>
228.3.10 MIME_HEADER Procedure
This procedure changes the default MIME header that the script returns. This procedure must come before any HTP.PRIN
T or HTP.PRN
calls to direct the script not to use the default MIME header.
Syntax
OWA_UTIL.MIME_HEADER( ccontent_type IN VARCHAR2 DEFAULT 'text/html', bclose_header IN BOOLEAN DEFAULT TRUE, ccharset IN VARCHAR2 DEFAULT NULL);
Parameters
Table 228-8 MIME_HEADER Procedure Parameters
Parameter | Description |
---|---|
|
The MIME type to generate |
bclose_header |
Whether or not to close the HTTP header. If |
ccharset |
The character set to use.The character set only makes sense if the MIME type is of type 'text'. Therefore, the character set is only tagged on to the Content-Type header only if the MIME type passed in is of type 'text'. Any other MIME type, such as 'image', will not have any character set tagged on. |
Examples
Content-type: <ccontent_type>; charset=<ccharset>
so that
owa_util.mime_header('text/plain', false, 'ISO-8859-4')
generates
Content-type: text/plain; charset=ISO-8859-4\n
228.3.11 PRINT_CGI_ENV Procedure
This procedure generates all the CGI environment variables and their values made available by the PL/SQL Gateway to the stored procedure.
Syntax
OWA_UTIL.PRINT_CGI_ENV;
Examples
This procedure generates a list in the following format:
cgi_env_var_name = value\n
228.3.12 REDIRECT_URL Procedure
This procedure specifies that the application server is to visit the specified URL. The URL may specify either a Web page to return or a program to execute.
Syntax
OWA_UTIL.REDIRECT_URL( curl IN VARCHAR2 bclose_header IN BOOLEAN DEFAULT TRUE);
Parameters
Table 228-9 REDIRECT_URL Procedure Parameters
Parameter | Description |
---|---|
|
The URL to visit. |
bclose_header |
Whether or not to close the HTTP header. If |
Usage Notes
This procedure must come before any HTP procedure or HTF function call.
Examples
This procedure generates
Location: <curl>\n\n
228.3.13 SHOWPAGE Procedure
This procedure prints out the HTML output of a procedure in SQL*Plus.
The procedure must use the HTP or HTF packages to generate the HTML page, and this procedure must be issued after the HTP or HTF page-generating subprogram has been called and before any other HTP or HTF subprograms are directly or indirectly called.
Syntax
OWA_UTIL.SHOWPAGE;
Usage Notes
-
This method is useful for generating pages filled with static data.
-
This procedure uses the DBMS_OUTPUT package and is limited to 32767 characters for each line and an overall buffer size of 1,000,000 bytes.
Examples
The output of htp procedure is displayed in SQL*Plus, SQL*DBA, or Oracle Server Manager. For example:
SQL> set serveroutput on SQL> spool gretzky.html SQL> execute hockey.pass("Gretzky") SQL> execute owa_util.showpage SQL> exit
This would generate an HTML page that could be accessed from Web browsers.
228.3.14 SHOWSOURCE Procedure
This procedure prints the source of the specified procedure, function, or package. If a procedure or function which belongs to a package is specified, then the entire package is displayed.
Syntax
OWA_UTIL.SHOWSOURCE ( cname IN VARCHAR2);
Parameters
Table 228-10 SHOWSOURCE Procedure Parameters
Parameter | Description |
---|---|
|
The function or procedure whose source you want to show. |
228.3.15 SIGNATURE procedure
This procedure generates an HTML line followed by a signature line on the HTML document.
If a parameter is specified, the procedure also generates a hypertext link to view the PL/SQL source for that procedure. The link calls the SHOWSOURCE Procedure.
Syntax
OWA_UTIL.SIGNATURE; OWA_UTIL.SIGNATURE ( cname IN VARCHAR2);
Parameters
Table 228-11 SIGNATURE Procedure Parameters
Parameter | Description |
---|---|
|
The function or procedure whose source you want to show. |
Examples
Without a parameter, the procedure generates a line that looks like the following:
This page was produced by the PL/SQL Agent on August 9, 2001 09:30.
With a parameter, the procedure generates a signature line in the HTML document that looks like the following:
This page was produced by the PL/SQL Agent on 8/09/01 09:30
View PL/SQL Source
228.3.16 STATUS_LINE Procedure
This procedure sends a standard HTTP status code to the client.
This procedure must come before any htp.print
or htp.prn
calls so that the status code is returned as part of the header, rather than as "content data".
Syntax
OWA_UTIL.STATUS_LINE( nstatus IN INTEGER, creason IN VARCHAR2 DEFAULT NULL, bclose_header IN BOOLEAN DEFAULT TRUE);
Parameters
Table 228-12 STATUS_LINE Procedure Parameters
Parameter | Description |
---|---|
|
The status code. |
|
The string for the status code. |
|
Whether or not to close the HTTP header. If |
Examples
This procedure generates
Status: <nstatus> <creason>\n\n
228.3.17 TABLEPRINT Function
This function generates either preformatted tables or HTML tables (depending on the capabilities of the user's browser) from database tables.
Syntax
OWA_UTIL.TABLEPRINT( ctable IN VARCHAR2, cattributes IN VARCHAR2 DEFAULT NULL, ntable_type IN INTEGER DEFAULT HTML_TABLE, ccolumns IN VARCHAR2 DEFAULT '*', cclauses IN VARCHAR2 DEFAULT NULL, ccol_aliases IN VARCHAR2 DEFAULT NULL, nrow_min IN NUMBER DEFAULT 0, nrow_max IN NUMBER DEFAULT NULL) RETURN BOOLEAN;
Parameters
Table 228-13 TABLEPRINT Function Parameters
Parameter | Description |
---|---|
|
The database table. |
|
Other attributes to be included as-is in the tag. |
|
How to generate the table. Specify
|
|
A comma-delimited list of columns from |
|
|
|
A comma-delimited list of headings for the generated table. |
|
The first row, of those retrieved, to display. |
|
The last row, of those retrieved, to display. |
Return Values
Returns TRUE
if there are more rows beyond the nrow_max
requested, FALSE
otherwise.
Usage Notes
-
RAW
columns are supported, butLONG
RAW
columns are not. References to LONG RAW columns will print the result 'Not Printable'. -
Note that in this function,
cattributes
is the second rather than the last parameter.
Examples
For browsers that do not support HTML tables, create the following procedure:
CREATE OR REPLACE PROCEDURE showemps IS ignore_more BOOLEAN; BEGIN ignore_more := OWA_UTIL.TABLEPRINT('emp', 'BORDER', OWA_UTIL.PRE_TABLE); END;
Requesting a URL such as
http://myhost:7777/pls/hr/showemps
returns to the following to the client:
<PRE> ----------------------------------------------------------------- | EMPNO |ENAME |JOB |MGR |HIREDATE | SAL | COMM | DEPTNO | ----------------------------------------------------------------- | 7369| SMITH | CLERK | 7902 | 17-DEC-80 | 800 | | 20 | | 7499| ALLEN | SALESMAN| 7698 | 20-FEB-81 | 1600 | 300 | 30 | | 7521| WARD | SALESMAN| 7698 | 22-FEB-81 | 1250 | 500 | 30 | | 7566| JONES | MANAGER | 7839 | 02-APR-81 | 2975 | | 20 | | 7654| MARTIN | SALESMAN| 7698 | 28-SEP-81 | 1250 | 1400| 30 | | 7698| BLAKE | MANAGER | 7839 | 01-MAY-81 | 2850 | | 30 | | 7782| CLARK | MANAGER | 7839 | 09-JUN-81 | 2450 | | 10 | | 7788| SCOTT | ANALYST | 7566 | 09-DEC-82 | 3000 | | 20 | | 7839| KING | PRESIDENT | | 17-NOV-81 | 5000 | | 10 | | 7844| TURNER | SALESMAN| 7698 | 08-SEP-81 | 1500 | 0 | 30 | | 7876| ADAMS | CLERK | 7788 | 12-JAN-83 | 1100 | | 20 | | 7900| JAMES | CLERK | 7698 | 03-DEC-81 | 950 | | 30 | | 7902| FORD | ANALYST | 7566 | 03-DEC-81 | 3000 | | 20 | | 7934| MILLER | CLERK | 7782 | 23-JAN-82 | 1300 | | 10 | ------------------------------------------------------------------- </PRE>
To view the employees in department 10, and only their employee ids, names, and salaries, create the following procedure:
CREATE OR REPLACE PROCEDURE showemps_10 IS ignore_more BOOLEAN; begin ignore_more := OWA_UTIL.TABLEPRINT ('EMP', 'BORDER', OWA_UTIL.PRE_TABLE, 'empno, ename, sal', 'WHERE deptno=10 ORDER BY empno', 'Employee Number, Name, Salary'); END;
A request for a URL like
http://myhost:7777/pls/hr/showemps_10
would return the following to the client:
<PRE> ------------------------------------- | Employee Number |Name | Salary | ------------------------------------- | 7782 | CLARK | 2450 | | 7839 | KING | 5000 | | 7934 | MILLER | 1300 | ------------------------------------- </PRE>
For browsers that support HTML tables, to view the department table in an HTML table, create the following procedure:
CREATE OR REPLACE PROCEDURE showdept IS ignore_more BOOLEAN; BEGIN ignore_more := oWA_UTIL.TABLEPRINT('dept', 'BORDER'); END;
A request for a URL like
http://myhost:7777/pls/hr/showdept
would return the following to the client:
<TABLE BORDER> <TR> <TH>DEPTNO</TH> <TH>DNAME</TH> <TH>LOC</TH> </TR> <TR> <TD ALIGN="LEFT">10</TD> <TD ALIGN="LEFT">ACCOUNTING</TD> <TD ALIGN="LEFT">NEW YORK</TD> </TR> <TR> <TD ALIGN="LEFT">20</TD> <TD ALIGN="LEFT">RESEARCH</TD> <TD ALIGN="LEFT">DALLAS</TD> </TR> <TR> <TD ALIGN="LEFT">30</TD> <TD ALIGN="LEFT">SALES</TD> <TD ALIGN="LEFT">CHICAGO</TD> </TR> <TR> <TD ALIGN="LEFT">40</TD> <TD ALIGN="LEFT">OPERATIONS</TD> <TD ALIGN="LEFT">BOSTON</TD> </TR> </TABLE>
A Web browser would format this to look like the following table:
DEPTNO | DNAME | LOC |
---|---|---|
|
|
|
|
|
|
|
|
|
228.3.18 TODATE Function
This function converts the DATETYPE Datatype to the standard Oracle DATE
type.
Syntax
OWA_UTIL.TODATE( p_dateArray IN dateType) RETURN DATE;
Parameters
Table 228-14 TODATE Function Parameters
Parameter | Description |
---|---|
|
The value to convert. |
Related Topics
228.3.19 WHO_CALLED_ME Procedure
This procedure returns information (in the form of output parameters) about the PL/SQL code unit that invoked it.
Syntax
OWA_UTIL.WHO_CALLED_ME( owner OUT VARCHAR2, name OUT VARCHAR2, lineno OUT NUMBER, caller_t OUT VARCHAR2);
Parameters
Table 228-15 WHO_CALLED_ME Procedure Parameters
Parameter | Description |
---|---|
|
The owner of the program unit. |
|
The name of the program unit. This is the name of the package, if the calling program unit is wrapped in a package, or the name of the procedure or function if the calling program unit is a standalone procedure or function. If the calling program unit is part of an anonymous block, this is |
|
The line number within the program unit where the call was made. |
|
The type of program unit that made the call. The possibilities are: package body, anonymous block, procedure, and function. Procedure and function are only for standalone procedures and functions. |