LASTVAL | Syntax: | LASTVAL(Sequence) | Return value: | INTEGER | Function type: | Sequence function | |
|
|
The function LASTVAL() returns the last value in a current connection after a NEXTVAL in a SEQUENCE. Synonym for "PREVIOUS VALUE FOR sequence". Available from MariaDB version 10.3. |
Example 1: NEXT VALUE FOR and PEVIOUS VALUE FOR one after the other in a current connection |
|
select next VALUE FOR `my_sequence` as result;
select Previous VALUE FOR `my_sequence` as result;
|
|
|
Example 2: NEXTVAL() and LASTVAL() one after the other in a current connection |
|
select nextval(`my_sequence`) as result;
select lastval(`my_sequence`) as result;
|
|
|
Example 3: LASTVAL() without NEXTVAL() in a current connection |
|
select lastval(`my_sequence`) as result;
|
|
|
The examples were created with the MyWAY SQL manager: |
How to use the LASTVAL() function in MariaDB databases |
The LASTVAL() function in MariaDB is used to retrieve the last generated value from a sequence. This function is used in conjunction with a sequence object. LASTVAL() can only be used after the sequence has been accessed with the NEXTVAL() function in the same session. |
|
Further MySQL und MariaDB SQL Sequence functions |
|