QuestionQ248

VerifiedCreating Other Schema Objects

Refer to the exhibit and examine the structure of the ORD table:

Exhibit:

Question Image

Evaluate these SQL statements, which execute in the specified order within a user session:

CREATE SEQUENCE ord_seq;  
  
SELECT ord_seq.nextval  
FROM dual;  
  
INSERT INTO ord  
VALUES (ord_seq.CURRVAL, 25-jan-2007, 101);  
  
UPDATE ord  
SET ord_no = ord_seq.NEXTVAL  
WHERE cust_id = 101;  

What is the outcome of the preceding statements?

Explanation

Oracle supplies default sequence attributes when they are omitted, including a starting value of 1 and an increment of 1 for an ascending sequence. Once NEXTVAL has been referenced, CURRVAL is available in that session and has the same value, 1. The subsequent NEXTVAL returns 2, so the update sets ORD_NO to 2 for CUST_ID 101. The default cache size affects preallocation, not the next value returned.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!