![]() We must use SQL statements to fully implement cursor functionality because simply declaring a cursor is not enough to extract data from a SQL database. But there is a general agreement on how the cursor should be written. Note that, different SQL implementations support the use of cursors in a different way. A name is given, there are statements to open the cursor, retrieve the query result, and finally close the cursor. Declaring a CursorĬursors are declared much like a variable. Other rows are extracted subsequently, in sequence until the cursor is closed. The cursor then is opened much like a file and extract single row from the query result. As a result, cursor is declared as an embedded SQL statement within the application programming language. The result may contain many rows, but the host application language can deal with one row at a time. The query result from the above statement returns employee details of all those employees whose birth date falls on the current day of a particular month. WHERE MONTH(birth_date) = MONTH(CURRENT_DATE) Consider the following SQL query: SELECT emp_no, first_name, last_name, birth_date A cursor can traverse through all rows of a query result focusing on one row at a time. The cursor, therefore, serves as a pointer that enables programming language to process query result one record at a time. The cursor acts like an iterator variable to loop over tuples returned by the SQL query and extract individual values within each tuple which then can be mapped to appropriate type of program variables. The mechanism of looping over tuples is necessary to iterate over tuples and their attribute values. Therefore, it is essential that SQL query result maps with the data structure supported by the programming language. Host programming languages typically works on individual data values of tuple returned by the query.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |