PL/SQL parser (MDEV-10142)

[MDEV-10582] sql_mode=ORACLE: Explicit cursor attributes %ISOPEN, %ROWCOUNT, %FOUND, %NOTFOUND Created: 2016-08-17  Updated: 2020-08-27  Resolved: 2016-09-27

Status: Closed
Project: MariaDB Server
Component/s: Parser, Stored routines
Affects Version/s: None
Fix Version/s: 10.3.0

Type: Technical task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: Compatibility

Issue Links:
Problem/Incident
causes MDEV-12977 sql_mode=oracle: errors "Undefined CU... Closed
Sprint: 10.2.2-3, 10.2.2-1, 10.2.2-2, 10.2.2-4, 10.1.18

 Description   

Understand explicit cursor attributes when running in sql_mode=ORACLE:

  • cursor_name%ISOPEN
    Return TRUE if cursor_name was already open with OPEN, or FALSE otherwise
  • cursor_name%ROWCOUNT
    Return 0 before the first FETCH, afterwards return the number of rows that were already fetched from cursor_name using FETCH.
  • cursor_name%FOUND
    Return NULL before the first FETCH. Return TRUE if the last FETCH returned a row, or FALSE otherwise.
  • cursor_name%NOTFOUND
    Return NULL before the first FETCH. Return TRUE if the last FETCH returned no rows, or FALSE if the last FETCH returned some rows.

Due to a grammar conflict, this task will remove the modulo operator '%'. One should use MOD in Oracle.

This task will also implement the predefined exception INVALID_CURSOR. If a cursor is not open, referencing it with %FOUND, %NOTFOUND, or %ROWCOUNT raises INVALID_CURSOR.

If a cursor is closed and then opened again, %FOUND and %NOTFOUND are reset to NULL and %ROWCOUNT is reset to 0.

Note, we'll also change behavior of the FETCH statement to raise no conditions (exceptions) if no rows were returned. Instead of catching conditions, in Oracle one should test %FOUND or %NOTFOUND attributes to know if FETCH returned a row.

Example:

  BEGIN
    FETCH cur INTO v1,v2;
    EXIT WHEN cur%NOTFOUND;
    ...
  END; 


Generated at Thu Feb 08 07:43:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.