般若是什么意思| 熬夜后吃什么恢复元气| 9d是什么意思| 减肥吃什么瘦得快| 备孕期间要注意什么| 学生近视配什么镜片好| 吃什么对心脏好改善供血不足| 降肌酐吃什么药| 心率过速是什么原因| 怀孕为什么要建档| 北极熊为什么不怕冷| 运动出汗有什么好处| 血糖高会有什么症状| 出库是什么意思| 夹腿是什么| 热结旁流是什么意思| 肚脐眼叫什么穴位| 最坚固的锁怕什么| 笑得什么| 高级护理是干什么的| 白血病是什么原因引起的| 避孕套是什么| 雪貂吃什么| 唾手可得是什么意思| 吃什么可以解决便秘| 尿频吃什么药最好| 病字旁加且念什么| dw手表是什么档次| 子宫囊肿是什么原因引起的| 恩施有什么好玩的| 大体重减肥做什么运动| 国企是什么意思| 脚踏一星是什么命| 寻麻疹涂抹什么药膏| 乙肝表面抗体高是什么意思| 沧州有什么好玩的地方| 蒲公英能治什么病| 安陵容为什么恨甄嬛| 6月16日是什么星座| 猴配什么生肖最好| 机灵的动物是什么生肖| 龙象征着什么| 今年37岁属什么生肖| 肤如凝脂是什么意思| 月经不调挂什么科室| 野餐带什么| 10.14是什么星座| 花甲是什么意思| 1009是什么星座| 石斛有什么作用和功效| 全日制专科是什么意思| 动态密码是什么| 风寒感冒流鼻涕吃什么药| 因小失大是什么生肖| 什么水果维生素含量高| 氯雷他定片什么时候吃| 首长是什么级别| 750是什么意思| 如梦初醒是什么意思| 什么是修养| 宫腔占位什么意思| 甲醛中毒吃什么药| 维他命是什么意思| 胸痛是什么原因导致的| 失落感是什么意思| 尿频繁吃什么药最见效| 多发肿大淋巴结是什么意思| 射频消融术是什么手术| 鲜卑人是现在的什么人| 鼻子一直流血是什么原因| 明天是什么日子| gtp是什么意思| jackie是什么意思| 燕窝什么时候吃好| 受益匪浅的意思是什么| 身上发冷是什么原因| 思钱想厚什么意思| 早泄是什么原因引起的| 排卵期和排卵日有什么区别| 戴朱砂有什么好处| 三无产品指的是什么| 为什么是| 女人性冷淡是什么原因| 阴道细菌感染用什么药| 是什么病| 慢性非萎缩性胃炎什么意思| 遗精是什么症状| 婴儿补铁吃什么铁剂| 黄瓜吃了有什么好处| 很什么很什么| 咳白色泡沫痰是什么病| 华盖星是什么意思| 核磁共振跟ct有什么区别| 十二年义务教育什么时候开始| 脾是干什么用的| 什么是业障| 女人喝胶原蛋白有什么好处| 油漆味对人有什么危害| 全血细胞减少是什么意思| 血糖高会出现什么症状| 湿疹吃什么食物| 蛋蛋疼是什么原因| 孩子流黄鼻涕吃什么药效果好| 彼岸花是什么花| xo是什么酒| 说话不清楚去医院挂什么科| 胎儿窘迫什么意思| 飞水是什么意思| 3月23日是什么星座| 汉卿是什么意思| 为什么北方人比南方人高| 酒店五行属什么| it是什么行业| 印鉴是什么意思| 肚子里面跳动是什么原因| 统筹支付是什么意思| 动脉硬化吃什么| 腺苷是什么| 乙酉日五行属什么| 鸿运当头是什么菜| 一米阳光是什么意思| 女人长胡子是什么原因| 什么叫犹太人| 哈伦裤配什么鞋子好看| superstar是什么意思| 口干口臭是什么原因引起的| 吃什么调理卵巢早衰| 资治通鉴讲的是什么| 心里发慌什么原因| 三下乡是什么| 尐是什么意思| 去三亚需要什么证件| 尿素氮偏高是什么意思| 石榴石五行属什么| 讲师是什么级别| 什么是感统失调| 迪拜为什么那么有钱| 土是念什么| 大便隐血弱阳性是什么意思| 时隔是什么意思| 急性心肌炎有什么症状| 炖鱼放什么调料| 避孕套上的油是什么油| 脸发烫是什么原因| 熬夜到什么程度会猝死| 尾椎骨疼是什么原因| 骑乘是什么意思| 吃饭是什么意思| 神经炎用什么药| 黄毛是什么意思| 交杯酒是什么意思| 息风止痉是什么意思| 早上起来嘴巴发苦是什么原因| youngor是什么牌子| 不举是什么原因造成的| ic50是什么意思| 西瓜禁忌和什么一起吃| 千千阙歌是什么意思| 便民门诊是做什么的| 感冒看什么科| 血压的低压高是什么原因| 小白鼠吃什么| 减脂早餐吃什么| 手机信号不好是什么原因| 宝宝为什么喜欢趴着睡| 郑板桥是什么生肖| gbd是什么意思| 鹭鸶是什么动物| 为什么一直打哈欠| 支气管炎吃什么药效果最好| 九转大肠是什么菜系| 尾巴翘上天是什么意思| 口上长水泡是什么原因| 按摩是什么意思| 三高人群适合吃什么| 艾滋病会有什么症状| 为什么抽血要空腹| 女人左眼角有痣代表什么| 发蜡是什么| 鬼最怕什么颜色| 做头发是什么意思| 儿童热感冒吃什么药| 拉稀吃什么药| 肛周脓肿吃什么药| 过氧化氢一个加号什么意思| 误喝碘伏有什么伤害吗| 什么天山| 3月份什么星座| 抗炎和消炎有什么区别| 为什么做梦| 胃不舒服吃什么水果好| 胃痞病是什么病| 什么水果解酒| 儿童内分泌科检查什么| 冬眠是什么意思| sop是什么意思| 苡字五行属什么| 子宫钙化灶是什么意思| 水浒传什么朝代| 普贤菩萨的坐骑是什么| 红糖水什么时候喝最好| 恐龙生活在什么时代| 左手麻是什么原因| 鹦鹉代表什么生肖| 身上长红疙瘩很痒是什么原因| 送老人什么礼物最好| 六月初七是什么星座| 40min是什么意思| 咽后壁淋巴滤泡增生吃什么药| adh是什么激素| 拉郎配是什么意思| 4月26是什么星座| 频繁小便是什么原因| 来年是什么意思| 慢性子宫颈炎是什么意思| 家里为什么有隐翅虫| 复方药是什么意思| 早上起来口干口苦口臭是什么原因| 无中生有是什么意思| 1025是什么星座| b币有什么用| 长期口臭吃什么药| 最高学历是什么| 验孕棒阴性是什么意思| 摩羯座后面是什么星座| 额头出汗是什么原因| gccg是什么牌子| iphone的i是什么意思| 睾丸小是什么原因| 荨麻疹能吃什么水果| 木瓜是什么季节的| 男生来大姨夫是什么意思| 千卡是什么意思| 黄柏的功效与作用是什么| 69年鸡是什么命| 豆汁是什么做的| 1959年属什么生肖| 英雄难过美人关是什么生肖| 瘦西湖为什么叫瘦西湖| 慢性咽炎吃什么| 很难怀孕是什么原因| 南京为什么叫金陵| 身披枷锁是什么生肖| 肝气不足吃什么中成药| 发好人卡是什么意思| 近视眼底改变什么意思| 月经来了吃什么好| 什么眠什么睡| 卵巢疼是什么原因| 红楼梦是一部什么小说| 肝硬化是什么症状| 安痛定又叫什么名字| 汤姆是什么品种的猫| 为什么广西女孩子好娶| 农历是什么生肖| 吃什么容易瘦| 雪碧喝多了有什么害处| 戴隐形眼镜用什么眼药水| 不负卿是什么意思| 菊花什么时候开放| 5月份是什么星座| 肝囊肿挂什么科| 词讼是什么意思| 遮羞布是什么意思| 百度Jump to content

哈密机场正式开通乌鲁木齐-哈密-济南往返航线

From Wikipedia, the free encyclopedia
百度 二是对桃木神力的武器化应用有关于桃木天生所具有的神力,最具代表性的神话来源即为《淮南子》一书中所记录的羿死于桃棓,其中的桃棓即为桃木棒。

In computer science, a database cursor is a mechanism that enables traversal over the records in a database. Cursors facilitate processing in conjunction with the traversal, such as retrieval, addition and removal of database records. The database cursor characteristic of traversal makes cursors akin to the programming language concept of iterator.

Cursors are used by database programmers to process individual rows returned by database system queries. Cursors enable manipulation of whole result sets at once. In this scenario, a cursor enables the sequential processing of rows in a result set.

In SQL procedures, a cursor makes it possible to define a result set (a set of data rows) and perform complex logic on a row by row basis. By using the same mechanics, a SQL procedure can also define a result set and return it directly to the caller of the SQL procedure or to a client application.

A cursor can be viewed as a pointer to one row in a set of rows. The cursor can only reference one row at a time, but can move to other rows of the result set as needed.

Usage

[edit]

To use cursors in SQL procedures, you need to do the following:

  1. Declare a cursor that defines a result set
  2. Open the cursor to establish the result set
  3. Fetch the data into local variables as needed from the cursor, one row at a time
  4. Close the cursor when done

To work with cursors you must use the following SQL statements

This section introduces the ways the SQL:2003 standard defines how to use cursors in applications in embedded SQL. Not all application bindings for relational database systems adhere to that standard, and some (such as CLI or JDBC) use a different interface.

A programmer makes a cursor known to the DBMS by using a DECLARE ... CURSOR statement and assigning the cursor a (compulsory) name:

 DECLARE cursor_name CURSOR IS SELECT ... FROM ...

Before code can access the data, it must open the cursor with the OPEN statement. Directly following a successful opening, the cursor is positioned before the first row in the result set.

 OPEN cursor_name

Applications position cursors on a specific row in the result set with the FETCH statement. A fetch operation transfers the data of the row into the application.

 FETCH cursor_name INTO ...

Once an application has processed all available rows or the fetch operation is to be positioned on a non-existing row (compare scrollable cursors below), the DBMS returns a SQLSTATE '02000' (usually accompanied by an SQLCODE +100) to indicate the end of the result set.

The final step involves closing the cursor using the CLOSE statement:

 CLOSE cursor_name

After closing a cursor, a program can open it again, which implies that the DBMS re-evaluates the same query or a different query and builds a new result set.

Scrollable cursors

[edit]

Programmers may declare cursors as scrollable or not scrollable. The scrollability indicates the direction in which a cursor can move.

With a non-scrollable (or forward-only) cursor, you can FETCH each row at most once, and the cursor automatically moves to the next row. After you fetch the last row, if you fetch again, you will put the cursor after the last row and get the following code: SQLSTATE 02000 (SQLCODE +100) .

A program may position a scrollable cursor anywhere in the result set using the FETCH SQL statement. The keyword SCROLL must be specified when declaring the cursor. The default is NO SCROLL, although different language bindings like JDBC may apply a different default.

 DECLARE cursor_name sensitivity SCROLL CURSOR FOR SELECT ... FROM ...

The target position for a scrollable cursor can be specified relatively (from the current cursor position) or absolutely (from the beginning of the result set).

 FETCH [ NEXT | PRIOR | FIRST | LAST ] FROM cursor_name
 FETCH ABSOLUTE n FROM cursor_name
 FETCH RELATIVE n FROM cursor_name;

Scrollable cursors can potentially access the same row in the result set multiple times. Thus, data modifications (insert, update, delete operations) from other transactions could affect the result set. A cursor can be SENSITIVE or INSENSITIVE to such data modifications. A sensitive cursor picks up data modifications affecting the result set of the cursor, and an insensitive cursor does not. Additionally, a cursor may be INSENSITIVE, in which case the DBMS tries to apply sensitivity as much as possible.

"WITH HOLD"

[edit]

Cursors are usually closed automatically at the end of a transaction, i.e. when a COMMIT or ROLLBACK (or an implicit termination of the transaction) occurs. That behavior can be changed if the cursor is declared using the WITH HOLD clause (the default is WITHOUT HOLD). A holdable cursor is kept open over COMMIT and closed upon ROLLBACK. (Some DBMS deviate from this standard behavior and also keep holdable cursors open over ROLLBACK.)

 DECLARE  cursor_name CURSOR  WITH HOLD  FOR SELECT .... FROM ....

When a COMMIT occurs, a holdable cursor is positioned before the next row. Thus, a positioned UPDATE or positioned DELETE statement will only succeed after a FETCH operation occurred first in the transaction.

Note that JDBC defines cursors as holdable per default. This is done because JDBC also activates auto-commit per default.

Positioned update/delete statements

[edit]

Cursors can not only be used to fetch data from the DBMS into an application but also to identify a row in a table to be updated or deleted. The SQL:2003 standard defines positioned update and positioned delete SQL statements for that purpose. Such statements do not use a regular WHERE clause with predicates. Instead, a cursor identifies the row. The cursor must be opened and already positioned on a row by means of FETCH statement.

 UPDATE table_name
 SET    ...
 WHERE  CURRENT OF cursor_name
 DELETE
 FROM   table_name
 WHERE  CURRENT OF cursor_name

The cursor must operate on an updatable result set in order to successfully execute a positioned update or delete statement. Otherwise, the DBMS would not know how to apply the data changes to the underlying tables referred to in the cursor.

Cursors in distributed transactions

[edit]

Using cursors in distributed transactions (X/Open XA Environments), which are controlled using a transaction monitor, is no different from cursors in non-distributed transactions.

One has to pay attention when using holdable cursors, however. Connections can be used by different applications. Thus, once a transaction has been ended and committed, a subsequent transaction (running in a different application) could inherit existing holdable cursors. Herefore, an application developer has to be aware of that situation.

Cursors in XQuery

[edit]

The XQuery language allows cursors to be created using the subsequence() function.

The format is:

let $displayed-sequence := subsequence($result, $start, $item-count)

Where $result is the result of the initial XQuery, $start is the item number to start and $item-count is the number of items to return.

Equivalently this can also be done using a predicate:

let $displayed-sequence := $result[$start to $end]

Where $end is the end sequence.

For complete examples see the XQuery/Searching,Paging and Sorting#Paging at Wikibooks.

Disadvantages of cursors

[edit]

The following information may vary depending on the specific database system.

Fetching a row from the cursor may result in a network round trip each time. This uses much more network bandwidth than would ordinarily be needed for the execution of a single SQL statement like DELETE. Repeated network round trips can severely reduce the speed of the operation using the cursor. Some DBMSs try to reduce this effect by using block fetch. Block fetch implies that multiple rows are sent together from the server to the client. The client stores a whole block of rows in a local buffer and retrieves the rows from there until that buffer is exhausted.

Cursors allocate resources on the server, such as locks, packages, processes, and temporary storage. For example, Microsoft SQL Server implements cursors by creating a temporary table and populating it with the query's result set. If a cursor is not properly closed (deallocated), the resources will not be freed until the SQL session (connection) itself is closed. This wasting of resources on the server can lead to performance degradations and failures.

Example

[edit]

EMPLOYEES TABLE

SQL> desc EMPLOYEES_DETAILS;
 Name            Null?     Type
 --------------- --------  ------------
 EMPLOYEE_ID     NOT NULL  NUMBER(6)
 FIRST_NAME                VARCHAR2(20)
 LAST_NAME       NOT NULL  VARCHAR2(25)
 EMAIL           NOT NULL  VARCHAR2(30)
 PHONE_NUMBER              VARCHAR2(20)
 HIRE_DATE       NOT NULL  DATE
 JOB_ID          NOT NULL  VARCHAR2(10)
 SALARY                    NUMBER(8,2)
 COMMISSION_PCT            NUMBER(2,2)
 MANAGER_ID                NUMBER(6)
 DEPARTMENT_ID             NUMBER(4)
SAMPLE CURSOR KNOWN AS EE

CREATE OR REPLACE 
PROCEDURE EE AS
BEGIN

DECLARE
	v_employeeID EMPLOYEES_DETAILS.EMPLOYEE_ID%TYPE;
	v_FirstName EMPLOYEES_DETAILS.FIRST_NAME%TYPE;
	v_LASTName EMPLOYEES_DETAILS.LAST_NAME%TYPE;
	v_JOB_ID EMPLOYEES_DETAILS.JOB_ID%TYPE:= 'IT_PROG';

Cursor c_EMPLOYEES_DETAILS IS
	SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME
	FROM EMPLOYEES_DETAILS
	WHERE JOB_ID ='v_JOB_ID';

BEGIN
	OPEN c_EMPLOYEES_DETAILS;

	LOOP

		FETCH c_EMPLOYEES_DETAILS INTO v_employeeID,v_FirstName,v_LASTName;

		DBMS_OUTPUT.put_line(v_employeeID);
		DBMS_OUTPUT.put_line(v_FirstName);
		DBMS_OUTPUT.put_line(v_LASTName);

		EXIT WHEN c_EMPLOYEES_DETAILS%NOTFOUND;
	END LOOP;

	CLOSE c_EMPLOYEES_DETAILS;
END;

END;

See also

[edit]

References

[edit]
  • Christopher J. Date: Database in Depth, O'Reilly & Associates, ISBN 0-596-10012-4
  • Thomas M. Connolly, Carolyn E. Begg: Database Systems, Addison-Wesley, ISBN 0-321-21025-5
  • Ramiz Elmasri, Shamkant B. Navathe: Fundamentals of Database Systems, Addison-Wesley, ISBN 0-201-54263-3
  • Neil Matthew, Richard Stones: Beginning Databases with PostgreSQL: From Novice to Professional, Apress, ISBN 1-59059-478-9
  • Thomas Kyte: Expert One-On-One: Oracle, Apress, ISBN 1-59059-525-4
  • Kevin Loney: Oracle Database 10g: The Complete Reference, Oracle Press, ISBN 0-07-225351-7
[edit]
等不到天黑烟火不会太完美什么歌 尿蛋白三个加号吃什么药 小孩流鼻涕咳嗽吃什么药 光明会到底是干什么的 梦到自己头发白了是什么意思
怀孕一个星期有什么症状 肌红蛋白偏低说明什么 酸汤鱼用什么鱼 飞龙在天是什么生肖 鸡蛋散黄是什么原因
指模是什么意思 肾宝片有什么副作用吗 kda什么意思 孔子是什么学派的创始人 什么中药能降血压
喝完酒头疼吃什么药 长脸适合什么发型 高血脂吃什么药效果好 吉利丁片是什么 喝茶心慌的人什么体质
网状的蘑菇叫什么hcv8jop0ns2r.cn 看破不说破什么意思hcv8jop4ns6r.cn 小白脸什么意思hcv9jop2ns2r.cn 经常手淫对身体有什么危害hcv8jop8ns6r.cn 吃红薯有什么好处和坏处hcv8jop1ns5r.cn
epc什么意思inbungee.com 泪腺堵塞有什么症状hcv9jop0ns2r.cn 什么津津hcv9jop7ns3r.cn 什么是普拉提hcv8jop9ns8r.cn 入党有什么好处gysmod.com
壮阳是什么意思bfb118.com 前列腺有什么作用weuuu.com 鸦片鱼又叫什么鱼mmeoe.com 胃烧心吃什么食物好hcv7jop9ns1r.cn 牙齿痛吃什么药最管用gangsutong.com
乙肝五项135阳性是什么意思hcv8jop7ns0r.cn 寒风吹起细雨迷离是什么歌0735v.com 9月25日什么星座hcv7jop4ns5r.cn 梅毒什么症状hcv8jop6ns8r.cn 潘多拉魔盒是什么意思hcv8jop5ns8r.cn
百度