Sample Exam Questions

From the objective of OSS-DB Exam Silver
S3.1 SQL commands (Sequence)

Sample Question

3.57

Choose the correct result for the currval command at the end of the following set of commands.

+--------------------------------------------------+
| Session 1 =# CREATE SEQUENCE test_seq;  |
| Session 1 =# SELECT nextval ('test_seq');   |
|  nextval                                                     |
| ---------                                                    |
|        1                                                       |
|  (1 row)                                                    |
| Session 2 =# SELECT currval ('test_seq');     |
+--------------------------------------------------+
  1. The result is 0.

  2. The result is 1.

  3. The result is 2.

  4. An error is output.

※This sample exam is different from those that appear in the actual OSS-DB Exam.
2024/05/10

Answer and Explanation

The nextval command advances the sequence to the next value and returns that value. If multiple sessions execute nextval concurrently, each sequence safely returns a different sequence value.
The currval command returns the value obtained by the last nextval in the current session.
However, if nextval has not been executed in the current session, an error is output.

Therefore, the correct answer is D.