宣布游标

在存储过程中声明光标。

句法

DECLARE cursor_name CURSOR [ WITHOUT HOLD ]
    FOR query_expression [ FOR { UPDATE | READ ONLY } ]

描述

Declare a cursor variable and bind it to a query definition, query_expression. Using cursors allows for fetching and processing query result set, one row at a time.

声明光标实际上并不实际执行查询。打开光标实际上将运行查询并填充光标。看 打开游标.

在此版本的NOODB中,光标尽可能敏感,以插入,更新或删除由其他数据库会话设置的结果集的基础行。

参数

cursor_name

与所声明的游标关联的名称。在存储过程中,此名称必须是唯一的。游标变量上的所有操作都必须引用游标名称。

WITHOUT HOLD

此参数指定光标可维持性:

  • WITHOUT HOLD: The cursor will automatically close while in a fetch loop and either a 犯罪 or 回滚 is issued. This is the default behavior.

query_expression

A valid 选择 statement that returns a result set. (See 选择。)这可以从一个或多个表和/或视图中选择。

FOR { UPDATE | READ ONLY }
  • FOR READ ONLY:仅读取光标,不能用于位置更新或删除。位置更新或删除将导致运行时错误;也就是说,将成功创建存储过程,但在执行时会抛出错误。

  • FOR UPDATE: The cursor can be used for positional updates or deletes while fetching the result set, by using WHERE CURRENT OF cursor_name in the 更新 or 删除 DML 澳门比分网址 statement. For both tables and views, there are restrictions on the query definition that will allow it to be updatable. The only views that can be defined when using FOR UPDATE are updatable views. There are limitations on what views are allowed to be updatable (see 使用可更新的视图)。表也​​受到这些相同的限制。