一个菜问题,好久没来,兼顾送分!!

zzz1975 2002-11-18 07:31:35
有好几天没来了。。。哈哈!!

下面简单的问题是

DECLARE b_compute1 DYNAMIC CURSOR FOR SQLSA;
PREPARE SQLSA FROM :str1;
OPEN DYNAMIC b_compute1;
fetch b_compute1 into :user_count[30];
close b_compute1; 中

PREPARE SQLSA 起到什么作用?/

能分析一下此功能和讲解一下此语句的用法吗?/帮助里好像没有
谢谢!!
...全文
19 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
冷箫轻笛 2002-11-19
guanzhu
回复
george77 2002-11-18
帮助里查embedded sql
回复
cesar 2002-11-18
我看不太明白英语,就把帮忙粘来了!
------------------------------------------------------------------
PREPARE
The PREPARE statement prepares SQL statement from a character string in the host variable for later execution. It also associates the statement with a symbolic SQL name.

Syntax
PREPARE stmt_name [INTO :sqlda] FROM :hvar

Arguments
stmt_name

Is the statement to a subsequent EXECUTE or OPEN statement, or a previous DECLARE CURSOR statement.

sqlda

Is the output SQLDA data structure to be populated.

hvar

Is the host variable that contains the SQL statement.

Remarks
The PREPARE statement processes dynamic SQL statements. Because singleton SELECT statements (SELECT INTO) are not supported in dynamic SQL statements, they are not supported in PREPARE statements.

The statement name cannot be reused in multiple PREPARE statements within the same program module (source code file). Statement names are global within a program module. PREPARE statements cannot be shared by separately compiled programs linked into a single executable module, or by a program and dynamic-link libraries (DLLs) that execute in a single process.

You can use a PREPARE statement in one of two ways:

You can open a prepared dynamic cursor. (You must declare a dynamic cursor by using the DECLARE CURSOR statement before you prepare a SELECT statement.)


You can execute a prepared statement.
Prepared statement names are limited to use in a single cursor definition. The following statements used together are not valid:

EXEC SQL DECLARE cursor1 CURSOR FOR prep_select_statement;
EXEC SQL DECLARE cursor2 CURSOR FOR prep_select_statement; // invalid

If the PREPARE statement is used by an EXECUTE statement, hvar cannot contain an SQL statement that returns results.

When you use PREPARE, the SQL statement in :hvar cannot contain host variables or comments, but it can contain parameter markers (?). Additionally, the SQL statement cannot contain SQL keywords that pertain exclusively to Embedded SQL keywords.

The following keywords cannot be used in a PREPARE statement:

CLOSE FETCH
COMMIT INCLUDE
DESCRIBE OPEN
END-EXEC PREPARE
EXEC SQL ROLLBACK
EXECUTE WHENEVER


The INTO :sqlda option merges the functionality of the DESCRIBE statement with the functionality of the PREPARE statement. Therefore, the following sample statements are functionally identical:

EXEC SQL PREPARE gumbo INTO :mysqlda FROM :hamhock;

Or

EXEC SQL PREPARE gumbo FROM :hamhock;
EXEC SQL DESCRIBE gumbo INTO :mysqlda;

Note that the SQLDA data structure is populated only for output data. Even then, the application must set the value of each sqldata entry in the SQLDA data structure to the address of the corresponding program variable. (The sqldata field is part of sqlvar.) The SQLDA data structure used for input parameters must be constructed entirely by the application. For more information, see Using the SQLDA Data Structure.

Examples
EXEC SQL BEGIN DECLARE SECTION;
char prep[] = "INSERT INTO mf_table VALUES(?,?,?)";
char name[30];
char car[30];
double num;
EXEC SQL END DECLARE SECTION;

EXEC SQL PREPARE prep_stat FROM :prep;

while (SQLCODE == 0)
{
strcpy(name, "Elaine");
strcpy(car, "Lamborghini");
num = 4.9;
EXEC SQL EXECUTE prep_stat USING :name, :car, :num;
}
回复
奇遇 2002-11-18
在帮组上可以找到
好久没来,兼顾蹭分
回复
xuebuctxy 2002-11-18
游标的使用啊!书上应该有的,去看看书吧
回复
相关推荐
发帖
PowerBuilder
创建于2007-09-28

889

社区成员

PowerBuilder 相关问题讨论
申请成为版主
帖子事件
创建了帖子
2002-11-18 07:31
社区公告
暂无公告