Sam Mike
Sam Mike

Reputation: 11

"P1: begin" and "P2: begin" in a DB2 Stored Procedure

Can anyone explain to me or point me to some documentation on why the stored procedures are tagged into different parts using "P1: begin" and "P2: begin" ? Thanks, Mike

Upvotes: 0

Views: 1197

Answers (1)

CRPence
CRPence

Reputation: 1259

An SQL Procedure is defined by the routine-body. The routine-body is defined by\as one SQL Statement, which for a SQL Procedure is typically defined by one compound-statement, yet a compound-statement may be nested within another. Each label:Begin establishes the beginning of a new compound statement; one defined within another would be a nested compound statement. The following is a doc link that may satisfy as an answer to the question; a doc snippet is included which describes the primary purpose as scoping, and I added emphasis on each entity that is scoped:

http://www.ibm.com/support/knowledgecenter/ssw_ibm_i_71/db2/rbafzsummaryscope.htm

Summary of ′name′ scoping in nested compound statements

Nested compound statements can be used within an SQL routine to define the scope of SQL variable declarations, cursors, condition names, and condition handlers.

Additionally, labels have a defined scope in the context of nested compound statements. However the rules for name space, and how non-unique names can be referenced, differs depending on the type of name. The following table summarizes these differences. [...]

Upvotes: 1

Related Questions