31.Evaluate the following SQL commands:

31.Evaluate the following SQL commands:
SQL>CREATE SEQUENCE ord_seq
INCREMENT BY 10
START WITH 120
MAXVALUE 9999
NOCYCLE;

SQL>CREATE TABLE ord_items(
            ord_no NUMBER(4) DEFAULT ord_seq.NEXTVAL NOT NULL
            ,item_no NUMBER(3)
            ,qty NUMBER(3) CHECK (qty BETWEEN 100 AND 200)
            ,expiry_date date CHECK (expiry_date > SYSDATE)
            ,CONSTRAINT it_pk PRIMARY KEY (ord_no,item_no)
            ,CONSTRAINT ord_fk FOREIGN KEY(ord_no) REFERENCES orders(ord_no)
);


The command to create a table fails. Identify the reason for the SQL statement failure? (Choose all that apply.)
A.You cannot use SYSDATE in the condition of a CHECK constraint.
B.You cannot use the BETWEEN clause in the condition of a CHECK constraint.
C.You cannot use the NEXTVAL sequence value as a DEFAULT value for a column.
D.You cannot use ORD_NO and ITEM_NO columns as a composite primary key because ORD_NO is also the FOREIGN KEY.
答案:AC
A:正确, 参考30题
B:错误, 参考30题
C:正确,提示ORA-00984 column not allowed here 错误

那如果想让序列作为一个表的自增长列怎么处理哪?

SQL> create table test (a int );
Table created

SQL> create trigger test_sequence
  2  before insert on test
  3  for each row 
  4      when (new.a is null)
  5  begin
  6      select ord_seq.nextval into :new.a from dual;
  7  end;
  8  /
Trigger created

SQL> insert into test values(null);
1 row inserted

SQL> insert into test values(null);
1 row inserted

SQL> select * from test;
                                      A
---------------------------------------
                                    120
                                    130

SQL> 

这里注意new伪记录的使用方法,在when中不需要使用:,其他地方都需要使用:
--那序列是否可以用于check约束?

SQL> create table test (a int ,constraints ck_a check(a<ord_seq.nextval));
create table test (a int ,constraints ck_a check(a<ord_seq.nextval))
ORA-00904: "ORD_SEQ"."NEXTVAL": 标识符无效
--因此:序列不能用于默认值和check约束,通过30题知道sysdate可以用于默认值,但是不能用于check约束
D:错误, 参考30题

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
sts报错,报错信息如下,如何确认问题:06-09 14:59:32 I/ModuleListener: [1/1] EQ5T45G66XCAAQMN com.android.compatibility.common.tradefed.testtype.JarHostTest android.security.sts.Bug_258188673#testPocBug_258188673 FAILURE: java.lang.AssertionError: PoC exited with bad exit code.. Actual: 113 at org.junit.Assert.fail(Assert.java:89) at org.junit.Assert.failEquals(Assert.java:187) at org.junit.Assert.assertNotEquals(Assert.java:201) at com.android.sts.common.NativePocStatusAsserter$1.checkCmdResult(NativePocStatusAsserter.java:32) at com.android.sts.common.NativePoc.runPocAndAssert(NativePoc.java:264) at com.android.sts.common.NativePoc.run(NativePoc.java:224) at android.security.sts.Bug_258188673.testPocBug_258188673(Bug_258188673.java:38) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:61) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61) at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61) at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61) at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
最新发布
06-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值