简体   繁体   中英

Sequence in create table?

So I failed in exam with score 60% which needed 3% for pass, and I want to know about sequence in create table statement, in question given us that => in the database "exist" sequence for example SEQ_001 and used in for example=>

SQL>create table ( id number default seq_001.nextval ); or
    create table ( id number default seq_001.currval );

And in the topic of 1z0 071 written that =>

This exam was validated against 11g Release 2 version 11.2.0.1.0 and up to 19c

And I know that sequence is possible in create table from 12c but not in previous versions, so how I can know that which version is for this questions and how to check that the exist sequence is used with nextval, exists not means that it is used( I am about nextval after creating, if no currval can give error ). In this type questions I confused.

Regarding the question of Oracle versions for taking the 1z0-071 exam I would say that although there are differences between 11g up to 19c, most of the questions should be based on concepts that are standard between these versions.

More specifically for the Sequence part of the question, although it is possible to create a table with a default value pointing to currval, it would seldom be useful. Using the example of ID above, imagine using this sequence to create user IDs. We would expect different users to have different IDs, and with currval there is a strong possibility that different users would have the same ID making the column essentially useless.

Although not specified in your question, I would assume that most examples of using a sequence default would be for a surrogate primary key, which would need to be unique. Nextval would ensure that these would be unique assuming that rows are not entered with values greater than the existing sequence currval by an outside user.

The following statement

create table t23 ( id number default seq_001.nextval ); 

succeeds on Oracle 18c (demo on db<>fiddle) .

but fails on Oracle 11gR2 with this error:

ORA-00984: column not allowed here

db<>fiddle uses XE editions, but I don't think that's the explanation. So it seems the exam was not "was validated against 11g Release 2 version 11.2.0.1.0" with full rigour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM