DB2 Version 9.7 for Linux, UNIX, and Windows

GRANT (package privileges) statement

This form of the GRANT statement grants privileges on a package.

Invocation

This statement can be embedded in an application program or issued through the use of dynamic SQL statements. It is an executable statement that can be dynamically prepared only if DYNAMICRULES run behavior is in effect for the package (SQLSTATE 42509).

Authorization

The privileges held by the authorization ID of the statement must include at least one of the following:
  • CONTROL privilege on the referenced package
  • The WITH GRANT OPTION for each identified privilege on package-name
  • ACCESSCTRL or SECADM authority

ACCESSCTRL or SECADM authority is required to grant the CONTROL privilege.

Syntax

Read syntax diagramSkip visual syntax diagram
          .-,---------------.                                  
          V                 |              (2)                 
>>-GRANT----+-BIND--------+-+--ON--PACKAGE------package-name---->
            +-CONTROL-----+                                    
            |         (1) |                                    
            '-EXECUTE-----'                                    

       .-,---------------------------------.   
       V                                   |   
>--TO----+-+-------+--authorization-name-+-+-------------------->
         | +-USER--+                     |     
         | +-GROUP-+                     |     
         | '-ROLE--'                     |     
         '-PUBLIC------------------------'     

>--+-------------------+---------------------------------------><
   '-WITH GRANT OPTION-'   

Notes:
  1. RUN can be used as a synonym for EXECUTE.
  2. PROGRAM can be used as a synonym for PACKAGE.

Description

BIND
Grants the privilege to bind a package. The BIND privilege allows a user to re-issue the BIND command against that package, or to issue the REBIND command. It also allows a user to create a new version of an existing package.

In addition to the BIND privilege, a user must hold the necessary privileges on each table referenced by static DML statements contained in a program. This is necessary, because authorization on static DML statements is checked at bind time.

CONTROL
Grants the privilege to rebind, drop, or execute the package, and extend package privileges to other users. The CONTROL privilege for packages is automatically granted to creators of packages. A package owner is the package binder, or the ID specified with the OWNER option at bind/precompile time.

BIND and EXECUTE are automatically granted to an authorization-name that is granted CONTROL privilege.

CONTROL grants the ability to grant the above privileges (except for CONTROL) to others.

EXECUTE
Grants the privilege to execute the package.
Start of changeON PACKAGE package-nameEnd of change
Start of changeSpecifies the name of the package on which privileges are to be granted. The granting of a package privilege applies to all versions of the package (that is, to all packages that share the same package name and package schema).End of change
TO
Specifies to whom the privileges are granted.
USER
Specifies that the authorization-name identifies a user.
GROUP
Specifies that the authorization-name identifies a group name.
ROLE
Specifies that the authorization-name identifies a role name. The role name must exist at the current server (SQLSTATE 42704).
authorization-name,...
Lists the authorization IDs of one or more users, groups, or roles.

The list of authorization IDs cannot include the authorization ID of the user issuing the statement (SQLSTATE 42502).

PUBLIC
Grants the privileges to a set of users (authorization IDs). For more information, see "Authorization, privileges and object ownership".
WITH GRANT OPTION
Allows the specified authorization-name to GRANT the privileges to others.

If the specified privileges include CONTROL, the WITH GRANT OPTION applies to all of the applicable privileges except for CONTROL (SQLSTATE 01516).

Rules

Notes

Examples

Example 1:  Grant the EXECUTE privilege on PACKAGE CORPDATA.PKGA to PUBLIC.
   GRANT EXECUTE
     ON PACKAGE CORPDATA.PKGA
     TO PUBLIC
Example 2:  GRANT EXECUTE privilege on package CORPDATA.PKGA to a user named EMPLOYEE. There is neither a group nor a user called EMPLOYEE.
   GRANT EXECUTE ON PACKAGE
     CORPDATA.PKGA TO EMPLOYEE
or
   GRANT EXECUTE ON PACKAGE
     CORPDATA.PKGA TO USER EMPLOYEE