Stored Procedures2
Stored Procedures2
To use a stored procedure, you need to write two programs: the stored
procedure, which runs on a database server, and a client application, which runs
on a client workstation or a middleware server (such as a Web server). The client
application calls the stored procedure by using one of the available API methods.
A stored procedure follows certain conventions for exchanging data with a client
application.
A stored procedure does not connect to the database, but relies on the database
connection already established by the client. The call across the network
includes parameters that are required by the stored procedure. The stored
procedure uses the parameters to complete its logic when it runs. It can return a
set of values, rows, or modified parameters to the calling client application.
The Development Center is designed to give you a full development environment
for working with stored procedures, from creating to deploying.
Related tasks
Building routines
Exporting routines
Importing routines
Editing source code
Filtering in the Server View
Dropping routines or objects from a database
Removing routines or objects from a project
Related information
Creating stored procedures
Running routines
Debugging
Deploying routines
Applications that execute SQL statements one at a time typically cross the
network twice for each SQL statement. A stored procedure can group SQL
statements together, making it necessary to only cross the network twice
for each group of SQL statements. The more SQL statements that you
group together in a stored procedure, the more you reduce network usage
and the time that database locks are held. Reducing network usage and
the length of database locks improves overall network performance and
reduces lock contention problems.
Related concepts
Languages for stored procedures
SQL stored procedures
Java stored procedures
SQL provides procedural constructs for writing stored procedures. Writing stored procedures with the
SQL procedure language has the following advantages:
• You can support database modules that are written completely in an SQL language.
• You can quickly learn to write stored procedures with the SQL procedure language. This ease
of learning is especially true if you have experience with other database languages.
• SQL stored procedures are fast because the SQL routines run as compiled routines.
• You can debug SQL stored procedures on Windows, AIX, Sun, and Linux on DB2 Universal
Database servers and on DB2 for z/OS Version 8 server.
• With SQL stored procedures, you can call other SQL procedures, nesting calls up to 16 layers.
SQL stored procedures have size and parameter limitations, depending on the version of DB2 that you
are running:
• For DB2 for OS/390 and z/OS versions 6 and 7, the maximum size for SQL stored procedures
is 32 KB.
• For DB2 for z/OS version 8, the maximum size for SQL stored procedures is 2MB
• For DB2 for Windows and UNIX versions 7 and 8.1, the maximum size for SQL stored
procedures in is 64 KB.
• For DB2 version 8.2, the maximum size for SQL stored procedures is 2 MB
Related concepts
Benefits of using stored procedures
SQL stored procedures
Java stored procedures
Related reference
Name lengths and restrictions for identifiers and parameters
END P1
Line Description
1 The SQL stored procedure name is SCHEMA.Procedure6. The InOut parameter has data type varchar(9).
4 Begins the body of the SQL stored procedure. All SQL stored procedure bodies consist of one or more statements nested within
a BEGIN and an END keyword.
Line Description
7 Begins the body of the SQL stored procedure. All SQL stored procedure bodies consist of one or more statements nested within
a BEGIN and an END keyword.
Related concepts
Benefits of using stored procedures
Languages for stored procedures
Java stored procedures
Related reference
SQL stored procedure
Java stored procedures can access DB2 data using either Java Database
Connectivity (JDBC) API calls or SQLJ statements. The Development Center can
create Java stored procedures that use either format.
The Development Center defines Java stored procedures in the catalog table
with LANGUAGE JAVA and PARAMETER STYLE JAVA.
Restriction: For iSeries version 5 release 3, the following are not supported for
Java stored procedures:
• PARAMETER STYLE DB2GENERAL
• BINARY and VARBINARY built-in data types
Related concepts
Benefits of using stored procedures
Languages for stored procedures
SQL stored procedures
Related reference
Java stored procedure with dynamic SQL using JDBC database access
Java stored procedure with static SQL using SQLJ database access