Difference between revisions of "PREPARE"

From Lianjapedia
Jump to: navigation, search
m (Text replace - "Recital" to "Lianja")
Line 11: Line 11:
 
The PREPARE command is used to set up an SQL statement for subsequent execution.  The EXECUTE command is used to execute the statement.  Variables used as parameters in the SQL statement must be declared before execution.
 
The PREPARE command is used to set up an SQL statement for subsequent execution.  The EXECUTE command is used to execute the statement.  Variables used as parameters in the SQL statement must be declared before execution.
  
{| class="wikitable"
+
{| class="wikitable" width=100%
 
!Keywords||Description
 
!Keywords||Description
 
|-
 
|-
 
|statement||An identifier for the SQL statement.
 
|statement||An identifier for the SQL statement.
 
|-
 
|-
|variable||The name of a variable containing the SQL statement as a string
+
|valign="top"|variable||The name of a variable containing the SQL statement as a string
 
|-
 
|-
 
|}
 
|}

Revision as of 13:51, 21 January 2013

Purpose

Set up an SQL statement for subsequent execution

Syntax

PREPARE <statement> FROM :<variable>

See Also

EXECUTE, EXECUTE IMMEDIATE

Description

The PREPARE command is used to set up an SQL statement for subsequent execution. The EXECUTE command is used to execute the statement. Variables used as parameters in the SQL statement must be declared before execution.

Keywords Description
statement An identifier for the SQL statement.
variable The name of a variable containing the SQL statement as a string

Example

stmtbuf = 'SELECT * FROM customers WHERE contactnam = ?'
prepare mystmt from :stmtbuf
 
gcAuthor = 'Ann Devon'
execute mystmt using :gcAuthor
 
gcAuthor = 'Yang Wang'
execute mystmt using :gcAuthor
 
stmtbuf = 'INSERT INTO customers (customerid, companynam, contactnam) VALUES (?,?,?)'
prepare mystmt from :stmtbuf
 
buf1 = '00101'
buf2 = 'Lianja'
buf3 = 'US'
execute mystmt using :buf1, :buf2, :buf3