Postgresql 中文操作指南
DECLARE STATEMENT
DECLARE STATEMENT — 声明 SQL 语句标识符
DECLARE STATEMENT — declare SQL statement identifier
Description
DECLARE STATEMENT 声明一个 SQL 语句标识符。SQL 语句标识符可与已连接关联。当动态 SQL 语句使用标识符时,将使用关联的已连接执行语句。声明的命名空间是预编译单元,并且不允许向同一 SQL 语句标识符进行多次声明。请注意,如果预编译器以 Informix 兼容模式运行且声明了一些 SQL 语句,“数据库”不能用作游标名称。
DECLARE STATEMENT declares an SQL statement identifier. SQL statement identifier can be associated with the connection. When the identifier is used by dynamic SQL statements, the statements are executed using the associated connection. The namespace of the declaration is the precompile unit, and multiple declarations to the same SQL statement identifier are not allowed. Note that if the precompiler runs in Informix compatibility mode and some SQL statement is declared, "database" can not be used as a cursor name.
Notes
只有当声明实际放在动态语句之上时,此关联才有效。
This association is valid only if the declaration is physically placed on top of a dynamic statement.
Examples
EXEC SQL CONNECT TO postgres AS con1;
EXEC SQL AT con1 DECLARE sql_stmt STATEMENT;
EXEC SQL DECLARE cursor_name CURSOR FOR sql_stmt;
EXEC SQL PREPARE sql_stmt FROM :dyn_string;
EXEC SQL OPEN cursor_name;
EXEC SQL FETCH cursor_name INTO :column1;
EXEC SQL CLOSE cursor_name;