OCP-1Z0-051 第44题 SEQUENCE的缺省值

本文详细解析了在SQL语句中创建序列、获取序列值并更新数据库表中特定字段的过程,通过具体示例展示了如何在用户会话中执行一系列SQL语句,包括创建序列、查询序列值、插入数据及更新数据,最终实现对特定记录的自动编号功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、原题
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.

答案:A

二、题目翻译
查看ORD表结构
按顺序执行下面的SQL语句:
上面语句执行后的结果是什么?
A. 所有语句执行成功,对于CUST_ID为101的ORD_NO列的值为2。
B. CREATE SEQUENCE命令不能执行,因为没有指定最大值和最小值。
C. CREATE SEQUENCE命令不能执行,因为起始值和步长值没有指定。
D. 所有语句执行成功,对于CUST_ID为101的ORD_NO列的值为20,因为CACHE默认为20。

三、题目解析
CREATE SEQUENCE时可以省略所有参数,默认起始值为1,步长为1,无上限。
关于D选项,CACHE关键字:
如果建立序列时不指定CACHE和NOCACHE,默认值为CACHE 20,即一次性从序列里取20个数放入内存,如果内存崩溃,则这20个数就会丢失,再取值时从第21个数开始取值,CACHE设置的最小值为2。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值