Skip to content

Commit 30dc7c8

Browse files
Merge pull request onecompiler#303 from sahiljawale54/master
Adding cursor topic in mysql.md
2 parents da74555 + 5e37d3c commit 30dc7c8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

my-sql.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,34 @@ SELECT * FROM TABLE1 RIGHT JOIN TABLE2 ON condition;
246246
SELECT select_list from TABLE1 CROSS JOIN TABLE2;
247247
```
248248

249+
250+
## Cursors
251+
252+
When an MYSQL statement is processed, a memory area is created known as context area. A cursor is a pointer to this context area.
253+
254+
### There are two types of cursor
255+
#### 1. Implict cursor
256+
#### 2. Explict cursor
257+
258+
259+
### Explict Cursor
260+
Explict cursors are used when you are exceuting a SELECT statement query that will return more than one row.
261+
262+
### The cursor works in four stages
263+
264+
### 1. Declaration of cursor:-
265+
```sql
266+
DECLARE cursor_name CURSOR FOR SELECT_statement;
267+
```
268+
### 2. Open Cusor
269+
```sql
270+
OPEN cursor_name;
271+
```
272+
### 3. Fetch the cursor
273+
```sql
274+
FETCH cursor_name INTO variables list;
275+
```
276+
### 4. Close the cursor
277+
```sql
278+
CLOSE cursor_name;
279+
```

0 commit comments

Comments
 (0)