C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
MySQL CursorIn MySQL, Cursor can also be created. Following are the steps for creating a cursor. 1. Declare CursorA cursor is a select statement, defined in the declaration section in MySQL. SyntaxDECLARE cursor_name CURSOR FOR Select statement; Parameter:cursor_name: name of the cursor select_statement: select query associated with the cursor 2. Open CursorAfter declaring the cursor the next step is to open the cursor using open statement. SyntaxOpen cursor_name; Parameter:cursor_name: name of the cursor which is already declared. 3. Fetch CursorAfter declaring and opening the cursor, the next step is to fetch the cursor. It is used to fetch the row or the column. SyntaxFETCH [ NEXT [ FROM ] ] cursor_name INTO variable_list; Parameter:cursor_name: name of the cursor variable_list: variables, comma separated, etc. is stored in a cursor for the result set 4. Close CursorThe final step is to close the cursor. SyntaxClose cursor_name; Parameter:Cursor_name: name of the cursor Example for the cursor:Step 1: Open the database and table. Step 2: Now create the cursor. Query: Step 3: Now call the cursor. Query: SET @name_list =""; CALL list_name(@name_list); SELECT @name_list;
Next TopicMySQL limit
|