Skip Headers

Oracle9i Application Server mod_plsql User's Guide
Release 2 (9.0.2)

Part Number A90855-01
Go To Documentation Library
Go To Product List
Solution Area
Go To Table Of Contents
Go To Index

Go to previous page Go to next page

mod_plsql Overview

Oracle9i Application Server consolidates Oracle's middle-tier products into a single solution for the deployment of Web applications. Mod_plsql provides support for building PL/SQL-based applications on the Web. PL/SQL stored procedures retrieve data from a database and generate HTTP responses containing data and code to display in a Web browser. Mod_plsql also supports other Oracle products such as Oracle Portal.

2.1 Processing Client Requests

Mod_plsql is an Apache plug-in that communicates with the database. It maps browser requests into database stored procedure calls over a SQL*Net connection. It is generally indicated by a /pls virtual path.

The following scenario provides an overview of what steps occur when a server receives a client request:

Text description of overview.jpg follows.

Text description of the illustration overview.jpg

  1. The Oracle HTTP Server receives a PL/SQL Server Page request from a client browser.

  2. The Oracle HTTP Server routes the request to mod_plsql.

  3. The request is forwarded by mod_plsql to the Oracle Database. By using the configuration information stored in your DAD, mod_plsql connects to the database.

  4. Mod_plsql prepares the call parameters, and invokes the PL/SQL procedure in the application.

  5. The PL/SQL procedure generates an HTML page using data and the PL/SQL Web Toolkit accessed from the database.

  6. The response is returned to mod_plsql.

  7. The Oracle HTTP Server sends the response to the client browser.

The procedure that mod_plsql invokes returns the HTTP response to the client. To simplify this task, mod_plsql includes the PL/SQL Web Toolkit, which contains a set of packages called the owa packages. Use these packages in your stored procedure to get information about the request, construct HTML tags, and return header information to the client. Install the toolkit in a common schema so that all users can access it.

2.2 Database Access Descriptors

Each mod_plsql request is associated with a Database Access Descriptor (DAD), a set of configuration values used for database access. A DAD specifies information such as:

You can also specify a username and password information in a DAD. If they are not specified, the user is prompted to enter a username and password when the URL is invoked.

2.3 Invoking mod_plsql

To invoke mod_plsql in a Web browser, input the URL in the following format:

protocol://hostname[:port]/DAD location/[[!][schema.][package.]proc_
Table 2-1 Invoking mod_plsql Parameters
Parameter Description


Either http or https. For SSL, use https.


The machine where the Web server is running.


The port at which the application server is listening. If omitted, port 80 is assumed.

DAD location

A virtual path to handle PL/SQL requests that you have configured in the WEb server.

! character

Indicates to use the flexible parameter passing scheme. See"Flexible Parameter Passing" for more information.


The database schema name. If omitted, name resolution for package.proc_name occurs based on the database user that the URL request is processed as.


The package that contains the PL/SQL stored procedure. If omitted, the procedure is stand-alone.


The PL/SQL stored procedure to run. This must be a procedure and not a function. It can accept only IN arguments.



The parameters for the stored procedure. The string follows the format of the GET method. For example:

  • Multiple parameters are separated with the & character. Space characters in the values to be passed in are replaced with the + character.

  • If you use HTML forms to generate the string (as opposed to generating the string yourself), the formatting is done automatically.

  • The HTTP request may also choose the HTTP POST method to post data to mod_plsql. See "POST, GET and HEAD Methods" for more information.

Example 1: A Web server is configured with pls/mydad as a DAD location and the browser sends the following URL:

The Web server running on and listening at port 9000 handles the request. When the Web server receives the request, it passes the request to
mod_plsql. This is because the pls/mydad indicates that the Web server is configured to invoke mod_plsql. It then uses the DAD associated with mydad and runs the myproc procedure stored in mypackage.

Example 2: Specify a URL without a DAD, schema, or stored procedure name.

Then the default home page for the mydad DAD (as specified on the DAD Configuration pages) displays.

2.3.1 POST, GET and HEAD Methods

The POST, GET and HEAD methods in the HTTP protocol instruct browsers on how to pass parameter data (usually in the form of name-value pairs) to applications. The parameter data is generated by HTML forms.

mod_plsql applications can use any of the methods. Each method is as secure as the underlying transport protocol (http or https).

2.4 Transaction Mode

After processing a URL request for a procedure invocation, mod_plsql performs a rollback if there were any errors. Otherwise, it performs a commit. This mechanism does not allow a transaction to span across multiple HTTP requests. In this stateless model, applications typically maintain state using HTTP cookies or database tables.

2.5 Parameter passing

mod_plsql supports:

2.5.1 Parameter Passing by Name (Overloaded parameters)

Overloading allows multiple subprograms (procedures or functions) to have the same name, but differ in the number, order, or the datatype family of the parameters. When you call an overloaded subprogram, the PL/SQL compiler determines which subprogram to call based on the data types passed.

PL/SQL allows you to overload local or packaged subprograms. Stand-alone subprograms cannot be overloaded. See the PL/SQL User's Guide in the Oracle Server documentation for more information on PL/SQL overloading.

You must give parameters different names for overloaded subprograms that have the same number of parameters. Because HTML data is not associated with datatypes, mod_plsql does not know which version of the subprogram to call.

For example, although PL/SQL allows you to define two procedures using the same parameter names for the procedures, an error occurs if you use this with mod_plsql.

-- legal PL/SQL, but not for mod_plsql
  PROCEDURE my_proc (val IN VARCHAR2);
  PROCEDURE my_proc (val IN NUMBER);
END my_pkg;

To avoid the error, name the parameters differently. For example:

-- legal PL/SQL and also works for mod_plsql
  PROCEDURE my_proc (valvc2 IN VARCHAR2);
  PROCEDURE my_proc (valnum IN NUMBER);
END my_pkg;

The URL to invoke the first version of the procedure looks similar to:

The URL to invoke the second version of the procedure looks similar to: Overloading and PL/SQL Arrays

If you have overloaded PL/SQL procedures where the parameter names are identical, but the data type is owa_util.ident_arr (a table of varchar2) for one procedure and a scalar type for another procedure, mod_plsql can still distinguish between the two procedures. For example, if you have the following procedures:

  PROCEDURE my_proc (val IN VARCHAR2); -- scalar data type
  PROCEDURE my_proc (val IN owa_util.ident_arr); -- array data type
END my_pkg;

Each of these procedures has a single parameter of the same name, val.

When mod_plsql gets a request that has only one value for the val parameter, it invokes the procedure with the scalar data type.

Example 1: Send the following URL to execute the scalar version of the procedure:

When mod_plsql gets a request with more than one value for the val parameter, it then invokes the procedure with the array data type.

Example 2: Send the following URL to execute the array version of the procedure:

To ensure that the array version executes, use hidden form elements on your HTML page to send dummy values that are checked and discarded in your procedure.

2.5.2 Flexible Parameter Passing

mod_plsql supports flexible parameter passing to handle HTML forms where users can select any number of elements. To use flexible parameter passing for a URL-based procedure invocation, prefix the procedure with an exclamation mark (!) in the URL. You can use two or four parameters. The two parameter interface provides improved performance with mod_plsql. The four parameter interface is supported for compatibility. Two parameter interface

procedure [proc_name] is 
		  	     name_array  IN  [array_type], 
	       value_array IN  [array_type],
Table 2-2 Two Parameter Interface Parameters
Parameter Description


The name of the PL/SQL procedure that you are invoking.


The names from the query string (indexed from 1) in the order submitted.


The values from the query string (indexed from 1) in the order submitted.


The values from the query string (indexed from 1) in the order submitted.

Example: If you send the following URL:!scott.my_proc?x=john&y=10&z=doe

The exclamation mark prefix (!) instructs mod_plsql to use flexible parameter passing. It invokes procedure scott.myproc and passes it the following two arguments:

name_array ==> (`x', `y', `z')
values_array ==> ('john', '10', 'doe') Four parameter interface

The four parameter interface is supported for compatibility.

procedure [proc_name] is
         (num_entires IN NUMBER,
          name_array  IN  [array_type],
          value_array IN  [array_type],
          reserved in [array_type]);
Table 2-3 Four Parameter Interface Parameters
Parameter Description


The name of the PL/SQL procedure that you are invoking.


The number of name_value pairs in the query string


The names from the query string (indexed from 1) in the order submitted.


The values from the query string (indexed from 1) in the order submitted.


Not used. It is reserved for future use.


Any PL/SQL index-by table of varchar2 type (e.g., owa.vc_arr).

Example: If you send the following URL, where the query_string has duplicate occurrences of the name "x":!scott.my_pkg.my_proc?x=a&y=b&x=c

The exclamation mark prefix (!) instructs mod_plsql to use flexible parameter passing. It invokes procedure scott.my_pkg.myproc and passes it the following arguments:

num_entries ==> 3
name_array ==> (`x', `y', `x');
values_array ==> (`a', `b', `c')
reserved ==> ()

2.5.3 Large Parameter Passing

The values passed as scalar arguments and the values passed as elements to the index-by table of varchar2 arguments can be up to 32K in size.

For example, when using flexible parameter passing (described in "Flexible Parameter Passing"), each name or value in the query_string portion of the URL gets passed as an element of the name_array or value_array argument to the procedure being invoked. These names or values can be up to 32KB in size.

2.6 File Upload and Download

mod_plsql allows you to:

2.6.1 Document Table Definition

You can specify the document storage table on a per DAD basis. The document storage table must have the following definition:

CREATE TABLE [table_name] (
[content_column_name] [content_column_type]
[ , [content_column_name] [content_column_type]]

Users can choose the table_name. The content_column_type type must be either LONG RAW or BLOB.

The content_column_name depends on the corresponding content_column_type:

An example of legal document table definition is:

  NAME               VARCHAR(128)   UNIQUE NOT NULL,
  MIME_TYPE          VARCHAR(128),
  DOC_SIZE           NUMBER,
  DAD_CHARSET        VARCHAR(128),
  CONTENT            LONG RAW,
  BLOB_CONTENT       BLOB ; Semantics of the CONTENT column

The contents of the table are stored in a content column. There can be more than one content column in a document table. However, for each row in the document table, only one of the content columns is used. The other content columns are set to NULL. Semantics of the CONTENT_TYPE column

The content_type column tracks in which content column the document is stored. When a document is uploaded, mod_plsql sets the value of this column to the type name.

For example, if a document was uploaded into the BLOB_CONTENT column, then the CONTENT_TYPE column for the document is set to the string `BLOB'. Semantics of the LAST_UPDATED column

The LAST_UPDATED column reflects a document's creation or last modified time. When a document is uploaded, mod_plsql sets the LAST_UPDATED column for the document to the database server time.

If an application then modifies the contents or attributes of the document, it must also update the LAST_UPDATED time.

mod_plsql uses the LAST_UPDATED column to check and indicate to the HTTP client (browser) if the browser can use a previously cached version of the document. This reduces network traffic and improves server performance. Semantics of the DAD_CHARSET column

The DAD_CHARSET column keeps track of the character set setting at the time of the file upload. This column is reserved for future use.

2.6.2 Old Style Document Table Definition

For backward capability with the document model used by older releases of WebDB 2.x, mod_plsql also supports the following old definition of the document storage table where the CONTENT_TYPE, DAD_CHARSET and LAST_UPDATED columns are not present.

/* older style document table definition (DEPRECATED) */
CREATE TABLE [table_name]
NAME         VARCHAR2(128),

2.6.3 Parameters for Document Upload/Downloading

For each DAD, the following configuration parameters are relevant for file upload or download.


The PlsqlDocumentTablename parameter specifies the table for storing documents when file uploads are performed via this DAD.


PlsqlDocumentTablename  [document_table_name]


PlsqlDocumentTablename  my_documents


PlsqlDocumentTablename  scott.my_document_table PlsqlDocumentPath (Document Access Path)

The PlsqlDocumentPath parameter specifies the path element to access a document. The PlsqlDocumentPath parameter follows the DAD name in the URL. For example, if the document access path is docs, then the URL would look similar to:


The mydad is the DAD name and myfile.htm is the file name.


PlsqlDocumentPath  [document_access_path_name] PlsqlDocumentProcedure (Document Access Procedure):

The PlsqlDocumentProcedure procedure is an application-specified procedure. It has no parameters and processes a URL request with the document access path. The document access procedure calls wpg_docload.download_file(filename) to download a file. It knows the filename based on the URL specification. For example, an application can use this to implement file-level access controls and versioning. An example of this is in "File Download".


PlsqlDocumentProcedure  [document_access_procedure_name]


PlsqlDocumentProcedure  my_access_procedure


PlsqlDocumentProcedure  scott.my_pkg.my_access_procedure PlsqlUploadAsLongRaw

The DAD parameter, PlsqlUploadAsLongRaw, configures file uploads based on their file extensions. The value of an PlsqlUploadAsLongRaw DAD parameter is a one entry per line list of file extensions. Files with these extensions are uploaded by mod_plsql into the content column of long_raw type in the document table. Files with other extensions are uploaded into the BLOB content column.

The file extensions can be text literals (jpeg, gif, etc.) or an asterisk (*) matches any file whose extension has not been listed in the PlsqlUploadAsLongRaw setting.


PlsqlUploadAsLongRaw  [file_extension]
PlsqlUploadAsLongRaw *

[file_extension] is an extension for a file (with or without the `.' character, e.g., `txt' or `.txt') or the wildcard character *.


PlsqlUploadAsLongRaw  html
PlsqlUploadAsLongRaw  txt
PlsqlUploadAsLongRaw  *

2.6.4 File Upload

To send files from a client machine to a database, create an HTML page that contains:

When a user clicks Submit, the following events occur:

  1. The browser uploads the file specified by the user as well as other form data to the server.

  2. mod_plsql stores the file contents in the database in the document storage table. The table name is derived from the PlsqlDocumentTablename DAD setting.

  3. The action procedure specified in the action attribute of the FORM is run (similar to invoking a mod_plsql procedure without file upload).

    The following example shows an HTML form that lets a user select a file from the file system to upload. The form contains other fields to provide information about the file.

    <title>test upload</title>
     <FORM 	enctype="multipart/form-data"
    <p>Author's Name:<INPUT type="text" name="who">
    <p>Description:<INPUT type="text" name="description"><br>
    <p>File to upload:<INPUT type="file" name="file"><br>
    <p><INPUT type="submit">

    When a user clicks Submit on the form:

    1. The browser uploads the file listed in the INPUT type="file" element.

    2. The write_info procedure then runs.

    3. The procedure writes information from the form fields to a table in the database and returns a page to the user.

      procedure write_info (
      who         in varchar2,
      description in varchar2,
      file        in varchar2) as
      insert into myTable values (who, description, file);
      htp.title('File Uploaded');
      htp.header(1, 'Upload Status');
      htp.print('Uploaded ' || file || ' successfully');

The filename obtained from the browser is prefixed with a generated directory name to reduce the possibility of name conflicts. The "action procedure" specified in the form renames this name. So, for example, when /private/minutes.txt is uploaded, the name stored in the table by the mod_plsql is F9080/private/minutes.txt. The application can rename this in the called stored procedure. For example, the application can rename it to scott/minutes.txt.

2.6.5 Specifying Attributes (Mime Types) of Uploaded Files

In addition to renaming the uploaded file, the stored procedure can alter other file attributes. For example, the form in the example from "File Upload" could display a field for allowing the user to input the uploaded document's Multipurpose Internet Mail Extension (MIME) type.

The MIME type can be received as a parameter in write_info. The document table would then store the mime type for the document instead of the default mime type that is parsed from the multipart form by mod_plsql when uploading the file.

2.6.6 Uploading Multiple Files

To send multiple files in a single submit, the upload form must include multiple <INPUT type="file" name="file"> elements. If more than one file INPUT element defines name to be of the same name, then the action procedure must declare that parameter name to be of type owa.vc_arr. The names defined in the file INPUT elements could also be unique, in which case, the action procedure must declare each of them to be of varchar2. For example, if a form contained the following elements:

<INPUT type="file" name="textfiles">
<INPUT type="file" name="textfiles">
<INPUT type="file" name="binaryfile">

As a result, the action procedure must contain the following parameters:

procedure handle_text_and_binary_files(textfiles IN owa.vc_arr,
                                       binaryfile IN varchar2).

2.6.7 File Download

After you have sent files to the database, you can download them, delete them from the database, and read and write their attributes.

To download a file, create a stored procedure without parameters that calls
wpg_docload.download_file (file_name) to initiate the download.

The HTML page presented to the user simply has a link to a URL which includes the Document Access Path and specifies the file to be downloaded.

For example, if the DAD specifies that the Document Access Path is docs and the Document Access Procedure is mydad.process_download, then the mydad.process_download procedure is called when the user clicks on the URL:


An example implementation of process_download is:

procedure process_download is
	v_filename varchar2(255);
  -- getfilepath() uses the SCRIPT_NAME and PATH_INFO cgi
  -- environment variables to construct the full pathname of
-- the file URL, and then returns the part of the pathname -- following `/docs/' v_filename := getfilepath; select name into v_filename from plsql_gateway_doc where UPPER(name) = UPPER(v_filename); -- now we call docload.download_file to initiate -- the download. wpg_docload.download_file(v_filename); exception when others then v_filename := null; end process_download;

Any time you call wpg_docload.download_file(filename) from a procedure running in mod_plsql, a download of the file filename is initiated. However, when a file download begins, no other HTML (produced via HTP interfaces) generated by the procedure, is passed back to the browser.

mod_plsql looks for the filename in the document table. There must be a unique row in the document table whose NAME column matches the filename. mod_plsql generates the HTTP response headers based on the information in the MIME_TYPE column of the document table. The content_type column's value determines which content columns the document's content comes from. The contents of the document are sent as the body of the HTTP response.

2.6.8 Direct BLOB Download

You can also download contents stored as Binary Large Object (BLOB) data type.

  1. Create a stored procedure that calls wpg_docload.download_file(blob) where blob is of data type BLOB. Since mod_plsql has no information about the contents in the BLOB, you must supply them.

  2. Setup the Content-Type and other headers.

    Example: The following procedure uses the name from the argument to select a BLOB from a table and initiates the Direct BLOB download:

    procedure download_blob(varchar2 name) is
    myblob blob;
    1. Select the BLOB out of mytable using the name argument

      select blob_data into myblob from mytable where blob_name = name;
    2. Setup headers which describes the content

      owa_util.mime_header('text/html', FALSE);
      htp.p('Content-Length: ' || dbms_lob.get_length(myblob));
    3. Initiate Direct BLOB download


      The structure of the mytable table:

      create table mytable
      blob_name varchar2(128),
      blob_data blob
  3. The HTML page presented to the user has a link to a URL that calls this stored procedure with the correct argument(s).

  4. When a Direct BLOB download is initiated, no other HTML (produced via the HTP interface) generated by the procedure is passed back to the browser.

2.7 Path Aliasing (Direct Access URLs)

Path Aliasing enables applications using mod_plsql to provide direct reference to its objects using simple URLs. This lets you directly access documents within an application using the document access path and a document access procedure. For example, the docs keyword in the URL below tells mod_plsql that this request is for document access.

protocol://hostname[:port]/DAD Location/docs/<FolderName/Document>

The above assumes that the Document Access Path is docs.

Path Aliasing provides the equivalent function by allowing means of direct access to application objects other than documents. Two fields in Database Access Descriptor's configuration information support path aliasing:

If mod_plsql encounters an incoming URL with the keyword entered in the Path Alias field, it invokes the procedure entered in the Path Alias Procedure field.

For example, if the URL below is the incoming URL and the Path Alias is set to myalias, mod_plsql invokes the Path Alias Procedure. This passes everything after the keyword myalias to the invoked procedure.

Applications that use path aliasing must implement the Path Alias Procedure. The procedure receives the rest of the URL (foo/bar/foobar) after the keyword, myalias, as a single parameter. It is responsible for dereferencing the object from the URL.

Although there is no restriction on the name and location for this procedure, it can accept only a single parameter, p_path, with the datatype varchar2.

2.8 Common Gateway Interface (CGI) Environment Variables

The OWA_UTIL package provides an API to get the values of CGI environment variables. The variables provide context to the procedure being executed through mod_plsql. Although mod_plsql is not operated through CGI, the PL/SQL application invoked from mod_plsql can access these CGI environment variables. The following are the available CGI Environment Variables:

Table 2-4 CGI Environment Variables










REQUEST_CHARSET (refer to "REQUEST_CHARSET CGI environment variable")

















A PL/SQL application can get the value of a CGI environment variable using the owa_util.get_cgi_env interface.


owa_util.get_cgi_env(param_name in varchar2) return varchar2;

param_name is the name of the CGI environment variable. param_name is case-insensitive.

2.8.1 Adding and Overiding CGI Environment Variables

The PlsqlCGIEnvironmentList DAD parameter is a one-entry per line list of name and value pairs which can override any environment variables or add new ones. If the name is one of the original environment variables (as listed in "Common Gateway Interface (CGI) Environment Variables"), that environment variable is overridden with the given value. If the name is not in the original list, a new environment variable is added into the list with that same name and value given in the parameter.


Refer to the Oracle HTTP Server Administration Guide for information about the mod_plsql Configuration Files.

If no value is specified for the parameter, then the value is obtained from the Oracle HTTP Server. With Apache, you can pass the DOCUMENT_ROOT CGI Environment variable by specifying:

PlsqlCGIEnvironmentList DOCUMENT_ROOT

New environment variables passed in through this configuration parameter are available to the PL/SQL application via the owa_util.get_cgi_env interface.

Example 1:


PlsqlCGIEnvironmentList REMOTE_USER=testuser

This example overrides the SERVER_NAME and the REMOTE_USER CGI environment variables with the given values since they are part of the original list.

Example 2:

PlsqlCGIEnvironmentList MYENV_VAR=testing

PlsqlCGIEnvironmentList SERVER_NAME=,

PlsqlCGIEnvironmentList REMOTE_USER=user2

This example overrides the SERVER_NAME and the REMOTE_USER variables. The SERVER_NAME variable is deleted since there is no value given to it. A new environment variable called MYENV_VAR is added since it is not part of the original list. It is assigned the value of "testing".

2.8.2 PlsqlNLSLanguage

For mod_plsql, the National Language Support variable (PlsqlNLSLanguage) can be set either as an environment variable or at the DAD level. The following restrictions apply: REQUEST_CHARSET CGI environment variable

Every request to mod_plsql is associated with a DAD. The CGI environment variable REQUEST_CHARSET is set as follows:

The PL/SQL application can access this information via a function call of the form:

	owa_util.get_cgi_env(`REQUEST_CHARSET'); REQUEST_IANA_CHARSET CGI environment variable

This is the IANA (Internet Assigned Number Authority) equivalent of the
REQUEST_CHARSET CGI environment variable. IANA is an authority that globally coordinates the standards for charsets on the Internet.

2.9 Restrictions in mod_plsql

The following restrictions exist in mod_plsql:

Go to previous page Go to next page
Copyright © 2002 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Go To Product List
Solution Area
Go To Table Of Contents
Go To Index