PL/SQL Packages and Types Reference 10g Release 1 (10.1) Part Number B10802-01 |
|
|
View PDF |
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.
This chapter contains the following topics:
The OWA_UTIL
package contains three types of utility subprograms.
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.
TYPE ip_address IS TABLE OF INTEGER INDEX BY BINARY_INTEGER;
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;
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.
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');
Design your query as follows:
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:
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);
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);
Parameter | Description |
---|---|
|
The name of the form elements. |
|
The initial date that is selected when the HTML page is displayed. |
<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;
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.
bclose_header
parameter in calls such as MIME_HEADER Procedure, REDIRECT_URL Procedure, or STATUS_LINE ProcedureHTP.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.
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);
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:
VALUE
attribute of the OPTION
tag.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);
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);
This procedure must come before any HTP or HTF procedure or 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;
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);
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);
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);
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;
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'.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:
----------------------------------------------------------------- | 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:
------------------------------------- | 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 |
---|---|---|
|
|
|
|
|
|
|
|
|
This function converts the DATETYPE Data Type to the standard Oracle DATE
type.
OWA_UTIL.TODATE( p_dateArray IN dateType) RETURN DATE;
Parameter | Description |
---|---|
|
The value to convert. |
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);