Cursor Is a database query stored on the DBMS server. It is not a SELECT statement, but a result set retrieved by this statement. After the cursor is stored, the application can scroll or browse the data as needed.
Use cursor
To use a cursor:
Before using a
A cursor (cursor) is a database query stored on a DBMS server that is not a SELECT statement, but rather a result set that is retrieved by the statement. After the cursor is stored, the application can scroll or browse the data as needed.
Using cursors
Steps to use cursors:
Before you use a
Tags: User bar implicit conversion first location assignment set size getWhat is a cursor The result set, which is the collection of all row data returned after the select query. Cursors are a mechanism for working with result sets, which can locate a row in the result set, read or write multiple data, or move the cursor to navigate to the rows you want to manipulate the data. Generally complex stored proce
),@pdname nvarchar(Ten),@salemoney decimal( -,2)
--extracts the first record and assigns the extracted variable to the corresponding variable
Fetch Next fromC_ Sales Table _ Date into @pdno,@pdname,@salemoney
--use the global variable @ @fetch_status whether the value is 0 as a loop to determine whether to extract records, such as extracted to the output extracted in the loop body value,
--then continue to extract the data using the FETCH command until the @ @FETCH_STATUS value is not 0
w
Comparison of the Efficiency of three types of cursor loops in pl/SQL mainly compares the following three formats:
1. one open cursor is processed; loop fetch cursor INTO variable; exit when condition; end loop; CLOSE cursor; 2. b
and batch processing.
Recommended reading:
Connect to a remote Oracle database under PL/SQL
PL/SQL ORA-14551: cannot perform DML operations in queries solved
Here, we will briefly test the efficiency of the above three types of cursors, and analyze the trace file to view the nature of the three processing methods.
-- Create a test table
00:09:54 SCOTT @ orcl> cr
Cursor is a method for processing data. To view or process data in a result set, A cursor provides the ability to forward or backward data in a result set by one or more rows. We can use a cursor as a pointer, which can specify any position in the result and then allow users to process the data at the specified position.
1. Composition of the
SQL Server temporary table and cursor usage summary, SQL Server
1. Temporary table
Temporary tables are similar to permanent tables, but temporary tables are stored in tempdb. They are automatically deleted when they are no longer used.Temporary tables can be local or global
I. cursor Recognition
Cursor allows you to access the result set returned by SQL Server row by row.A major reason for using cursor is to convert the set operation into a single record processing method.After retrieving data from a database using
the user-defined type.
Note: It is not possible to mix the sql_92 's cursor rules with that of MS SQL Server. Here we will summarize some of the issues that should be noted when declaring cursors.
If you use scroll or insensitive reserved words before cursor, you cannot use any reserved words between
management system and the line-oriented programming of the two linked together, so that two data processing methods can communicate. 1.2 Cursor Types MS SQL Server supports three types of cursors:transact_sql cursors ,API server
Common Data Types in SQL Server: SQL Server Data Types
To http://www.cnblogs.com/andy_tigger/archive/2011/08/21/2147745.html
Bit integerThe bit data type is an integer, and its value can only be 0, 1, or null. This data type is us
define a cursor:Cursors are divided into cursor types and cursor variables, which, for cursor variables, follow the definition of T-SQL variables (what are the rules defined by T-SQL variables?). Refer to my previous blog post).
1,
Create temporary tableMethod 1:Create Table # temporary table name (Field 1 constraints,Field 2 constraints,.....)Create Table # temporary table name (Field 1 constraints,Field 2 constraints,.....)Method 2:Select * into # temporary table name from your table;Select * into # temporary table name from your table;Note: The above # indicates a local temporary table, and # indicates a global temporary table.
Example: Create Table # tblrefundpaperpassengernames(Refundapplicationid int,Passengername
statement compute, compute by, for browse, and into cannot be used in the selection statement of the cursor declaration. Read only indicates that data modification is not allowed in the cursor result set. The update keyword indicates that the result set of the cursor can be modified. Of column_list indicates the columns that can be modified in the result set. By
a.o_id=b.o_id "Get view.3.?????? Use a dataset to get o_salary=o_salary+a_salary.4.?????? Write the UPDATE statement "update originsalary set o_salary=" adds the value "where o_id=" gets the value "5.?????? Loop 3 times to complete this function.Another way is to write a stored procedure, which I will not list here.I want you to think about this before learning about cursors, and some examples of batch processing. Some people might say, "Can't the database handle data in one row?" Addsalary the
will replace the S lock with X
Lock, but this conversion may take some time, so two transactions may be converted to the X lock, waiting for the other party to release the S lock, resulting in death
Lock. To avoid the problem, it is best to use the U Lock. Only one transaction can obtain the U Lock at a time.Exclusive (X) Exclusive lock to prevent multiple updates from working at the same time, and no other transaction can modify dataIntent (I) Intention lock, used to form the IS, IX, SIX lock,
A SQL Server cursor usesThe use of the/*** cursor speaks to the advantages of this multi-cursor, and now we are personally unveiling the mysterious veil of the cursor. The order in which cursors are used: reputation cursors, open
.
We know that the relational database management system is actually set-oriented. In ms SQL SERVER, there is no way to describe a single record in a table ,, unless you use the where clause to restrict only one record to be selected.
Therefore, we must use a cursor to process a single record. The cursor allows the app
in C language, the cursor is like the file handle you get when you open the file. If the file is successfully opened, the file handle can represent the file. For a cursor, the principle is the same. The visible cursor can process the result set from the basic table in a similar way as the traditional program reads the flat file, so as to present the data in the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.