在一些语句中,在准备语句时参数还未知,因为每次执行该语句时可插入不同的值。在这些语句中,在当执行语句时必须提供参数的地方,您可使用问号(?)占位符。
EXEC SQL prepare s3 from 'select * from customer where state matches ?'; EXEC SQL prepare in1 from 'insert into manufact values (?,?,?)'; sprintf(up_query, "%s %s", "update customer set zipcode = ?" "where current of zip_cursor"); EXEC SQL prepare update2 from :up_query; EXEC SQL prepare exfunc from 'execute function func1 (?, ?)';
对于表达式,但不对于 SQL 标识符,您可使用占位符来延缓计算值,直到运行时为止,除了在 以 SQL 标识符准备语句 中注明之外。
EXEC SQL BEGIN DECLARE SECTION; char queryvalue [6]; char demoquery [80]; EXEC SQL END DECLARE SECTION; EXEC SQL connect to 'stores_demo'; sprintf(demoquery, "%s %s", "select fname, lname from customer ", "where lname > ? "); EXEC SQL prepare quid from :demoquery; EXEC SQL declare democursor cursor for quid; stcopy("C", queryvalue); EXEC SQL open democursor using :queryvalue;
在与游标以及 EXECUTE 语句(所有其他的准备好的语句)关联的两个 OPEN 语句中,USING 子句都可用。
您可使用问号(?)占位符来表示 GBase 8s ESQL/C 或 SPL 集合变量的名称。