Oracle® Database PL/SQL Packages and Types Reference 11g Release 2 (11.2) Part Number E16760-05 |
|
|
PDF · Mobi · ePub |
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:
Overview
Types
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 data type by the Oracle database.
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;
This data type is used for an array.
TYPE ident_arr IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
This data type is used by the GET_CLIENT_IP Function in the "OWA_SEC" package on .
TYPE ip_address IS TABLE OF INTEGER INDEX BY BINARY_INTEGER;
Table 194-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. |
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.
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;
Table 194-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 |
An integer identifying the opened cursor.
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.
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');
Table 194-3 CALENDARPRINT Procedure Parameters
Parameter | Description |
---|---|
|
A PL/SQL query. |
|
A PL/SQL cursor containing the same format as |
|
If " |
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.
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.
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);
Table 194-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. |
This function generates
<tr><td>QueryResultItem</td><td>QueryResultItem</td></tr>...
This procedure generates three HTML form elements that allow the user to select the day, the month, and the year.
OWA_UTIL.CHOOSE_DATE( p_name IN VARCHAR2, p_date IN DATE DEFAULT SYSDATE);
Table 194-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. |
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 data type.
<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>
This function returns the value of the specified CGI environment variable.
OWA_UTIL.GET_CGI_ENV( param_name IN VARCHAR2) RETURN VARCHAR2;
Table 194-6 GET_CGI_ENV Function Parameters
Parameter | Description |
---|---|
|
The name of the CGI environment variable. It is case-insensitive. |
The value of the specified CGI environment variable. If the variable is not defined, the function returns NULL
.
This function returns the full virtual path of the PL/SQL Gateway that is handling the request.
OWA_UTIL.GET_OWA_SERVICE_PATH RETURN VARCHAR2;
A virtual path of the PL/SQL Gateway that is handling the request.
This function returns the name of the procedure that is being invoked by the PL/SQL Gateway.
OWA_UTIL.GET_PROCEDURE RETURN VARCHAR2;
The name of a procedure, including the package name if the procedure is defined in a package.
This procedure generates a newline character to close the HTTP header.
OWA_UTIL.HTTP_HEADER_CLOSE;
A newline character, which closes the HTTP header.
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
or HTP.PRN
calls.
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.
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);
Table 194-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. |
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 the OPTION
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 the OPTION
tag. If the value is not NULL
, the row is selected.
<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>
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.
OWA_UTIL.MIME_HEADER( ccontent_type IN VARCHAR2 DEFAULT 'text/html', bclose_header IN BOOLEAN DEFAULT TRUE, ccharset IN VARCHAR2 DEFAULT NULL);
Table 194-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. |
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
This procedure generates all the CGI environment variables and their values made available by the PL/SQL Gateway to the stored procedure.
OWA_UTIL.PRINT_CGI_ENV;
This procedure generates a list in the following format:
cgi_env_var_name = value\n
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.
OWA_UTIL.REDIRECT_URL( curl IN VARCHAR2 bclose_header IN BOOLEAN DEFAULT TRUE);
Table 194-9 REDIRECT_URL Function Parameters
Parameter | Description |
---|---|
|
The URL to visit. |
bclose_header |
Whether or not to close the HTTP header. If |
This procedure must come before any HTP procedure or HTF function call.
This procedure generates
Location: <curl>\n\n
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.
OWA_UTIL.SHOWPAGE;
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.
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.
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.
OWA_UTIL.SHOWSOURCE ( cname IN VARCHAR2);
Table 194-10 SHOWSOURCE Procedure Parameters
Parameter | Description |
---|---|
|
The function or procedure whose source you want to show. |
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.
OWA_UTIL.SIGNATURE; OWA_UTIL.SIGNATURE ( cname IN VARCHAR2);
Table 194-11 SIGNATURE Procedure Parameters
Parameter | Description |
---|---|
|
The function or procedure whose source you want to show. |
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
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".
OWA_UTIL.STATUS_LINE( nstatus IN INTEGER, creason IN VARCHAR2 DEFAULT NULL, bclose_header IN BOOLEAN DEFAULT TRUE);
Table 194-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 |
This procedure generates
Status: <nstatus> <creason>\n\n
This function generates either preformatted tables or HTML tables (depending on the capabilities of the user's browser) from database tables.
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;
Table 194-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. |
Returns TRUE
if there are more rows beyond the nrow_max
requested, FALSE
otherwise.
RAW
columns are supported, but LONG
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.
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 |
---|---|---|
10 |
ACCOUNTING |
NEW YORK |
20 |
RESEARCH |
DALLAS |
30 |
SALES |
CHICAGO |
This function converts the DATETYPE Data Type to the standard Oracle DATE
type.
OWA_UTIL.TODATE( p_dateArray IN dateType) RETURN DATE;
This procedure returns information (in the form of output parameters) about the PL/SQL code unit that invoked it.
OWA_UTIL.WHO_CALLED_ME( owner OUT VARCHAR2, name OUT VARCHAR2, lineno OUT NUMBER, caller_t OUT VARCHAR2);
Table 194-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. |