Escolar Documentos
Profissional Documentos
Cultura Documentos
search
ORACLE
(72 members)
forum
polls
members
view profile
SQL Material
Home > Communities > Computers & Internet > ORACLE > Forum > Messages
first | < previous | next > | last showing 21-30 of 65
9 Oct
▐►♥ ఓయ™ ♥◄▌
E_Name
Hansen, Ola
Svendson, Tove
Svendson, Stephen
Pettersen, Kari
Turner, Sally
Kent, Clark
Scott, Stephen
Note: This command cannot be used to list all employees in Norway and USA. In the example
above we have two employees with equal names, and only one of them will be listed. The UNION
command selects only distinct values.
Result
E_Name
Hansen, Ola
Svendson, Tove
Svendson, Stephen
Pettersen, Kari
Turner, Sally
Kent, Clark
Svendson, Stephen
Scott, Stephen
10 Oct
▐►♥ ఓయ™ ♥◄▌
Stored Procedures
A procedure (often called a stored procedure) is a program that can be called to perform
operations that can include both host language statements and SQL statements. Procedures in
SQL provide the same benefits as procedures in a host language.
DB2® SQL for iSeries stored procedure support provides a way for an SQL application to define
and then call a procedure through SQL statements. Stored procedures can be used in both
distributed and non-distributed DB2 SQL for iSeries applications. One of the big advantages in
using stored procedures is that for distributed applications, the execution of one CALL statement
on the application requester, or client, can perform any amount of work on the application server.
You may define a procedure as either an SQL procedure or an external procedure. An external
procedure can be any supported high level language program (except System/36* programs and
procedures) or a REXX procedure. The procedure does not need to contain SQL statements, but
it may contain SQL statements. An SQL procedure is defined entirely in SQL, and can contain
SQL statements that include SQL control statements.
Coding stored procedures requires that the user understand the following:
You may define stored procedures by using the CREATE PROCEDURE statement. The
CREATE PROCEDURE statement adds procedure and parameter definitions to the catalog
tables SYSROUTINES and SYSPARMS. These definitions are then accessible by any SQL CALL
statement on the system.
To create an external procedure or an SQL procedure, you can use the SQL CREATE
PROCEDURE statement.
10 Oct
▐►♥ ఓయ™ ♥◄▌
The following sections describe the SQL statements used to define and call the stored procedure,
information about passing parameters to the stored procedure, and examples of stored procedure
usage.
For a description of stored procedures coded in Java™, see Java SQL Routines in the IBM®
Developer Kit for Java topic.
For information about using stored procedures with DRDA®, see DRDA stored procedure
considerations.
Note:
See Code disclaimer information for information pertaining to code examples.
10 Oct
▐►♥ ఓయ™ ♥◄▌
CREATE PROCEDURE P1
(INOUT PARM1 CHAR(10))
EXTERNAL NAME MYLIB.PROC1
LANGUAGE C
GENERAL WITH NULLS
It is important to note that it is not necessary to define a procedure in order to call it. However, if
no procedure definition is found, either from a prior CREATE PROCEDURE or from a DECLARE
PROCEDURE in this program, certain restrictions and assumptions are made when the
procedure is called on the CALL statement. For example, the NULL indicator argument cannot be
passed. See Using embedded CALL statement where no procedure definition exists for an
example of a CALL statement without a corresponding procedure definition.
10 Oct
▐►♥ ఓయ™ ♥◄▌
The following is a PL/I example of an embedded CALL statement where no procedure definition
exists:
When the CALL statement is issued, DB2® SQL for iSeries attempts to find the program based
on standard SQL naming conventions. For the above example, assume that the naming option of
*SYS (system naming) is used and that a DFTRDBCOL parameter was not specified on the
CRTSQLPLI command. In this case, the library list is searched for a program named P2. Since
the call type is GENERAL, no additional argument is passed to the program for indicator
variables.
Note:
If an indicator variable is specified on the CALL statement and its value is less than zero when
the CALL statement is executed, an error results because there is no way to pass the indicator to
the procedure.
Assuming program P2 is found in the library list, the contents of host variable HV2 are passed in
to the program on the CALL and the argument returned from P2 is mapped back to the host
variable after P2 has completed execution.
Note:
See Code disclaimer for details pertaining to code examples.
10 Oct
▒▓Sravan
10 Oct
▐►♥ ఓయ™ ♥◄▌
Code disclaimer
10 Oct
▐►♥ ఓయ™ ♥◄▌
Consider the following simple example that takes as input an employee number and a rate and
updates the employee's salary:
Instead of a single UPDATE statement, logic can be added to the SQL procedure using SQL
control statements. SQL control statements consist of the following:
* an assignment statement
* a CALL statement
* a CASE statement
* a compound statement
* a FOR statement
* a GET DIAGNOSTICS statement
* a GOTO statement
* an IF statement
* an ITERATE statement
* a LEAVE statement
* a LOOP statement
* a REPEAT statement
* a RESIGNAL statement
* a RETURN statement
* a SIGNAL statement
* a WHILE statement
The following example takes as input the employee number and a rating that was received on the
last evaluation. The procedure uses a CASE statement to determine the appropriate increase and
bonus for the update: