OCP-1Z0-051-V9.02-44题

44. View the Exhibit and examine the structure of the ORD table.
Evaluate the following SQL statements that are executed in a user session in the specified order:
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 would be the outcome of the above statements?
A. All the statements would execute successfully and the ORD_NO column would contain the value 2 for
the CUST_ID 101.
B. The CREATE SEQUENCE command would not execute because the minimum value and maximum
value for the sequence have not been specified. 
C. The CREATE SEQUENCE command would not execute because the starting value of the sequence
and the increment value have not been specified. 
D. All the statements would execute successfully and the ORD_NO column would have the value  20 for
the CUST_ID 101 because the default CACHE value is 20. 
Answer: A
答案解析:
使用NEXTVAL和CURRVAL的规则
可以在下列上下文中使用NEXTVAL和CURRVAL:
• 不是子查询一部分的SELECT 语句的SELECT 列表
• INSERT 语句中子查询的SELECT 列表
• INSERT 语句的VALUES 子句
• UPDATE 语句的SET 子句
 

CREATE SEQUENCE时可以省略所有参数,默认起始值为1,步长为1,无上限

此处提一下 CACHE 这个关键字:如果建立序列时不指定 CACHE NOCACHE ,默认值为 20
即一次性从序列里取 20 个数放入内存,如果内存崩溃,则这 20 个数就会丢失,再取值时从第 21 个数开始取值, CACHE 设置的最小值为 2
 
实验验证:
1、创建一个序列,什么选项都不用跟。
sh@TESTDB> CREATE SEQUENCE ord_seq;
 
Sequence created.
 2、使用序列。应用select列表, INSERT 语句的VALUES 子句,UPDATE 语句的SET 子句都可以成功执行。排除BC,而最后经过UPDATE后ORD_NO列值为2,而不是20.
sh@TESTDB> SELECT ord_seq.nextval  FROM dual;
 
   NEXTVAL
----------
         1
 
sh@TESTDB> INSERT INTO ord  VALUES (ord_seq.CURRVAL, '25-jan-2007',101);
 
1 row created.
 
sh@TESTDB> UPDATE ord SET  ord_no= ord_seq.NEXTVAL WHERE cust_id =101;
 
1 row updated.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值