In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1.Sequence+Trigger implements self-increment of Oracle columns
CREATE SEQUENCE sequence name
[INCREMENT BY n]
[START WITH n]
[{MAXVALUE/MINVALUE n | NOMAXVALUE}]
[{CYCLE | NOCYCLE}]
[{CACHE n | NOCACHE}]
Create a test table
Sys@newtestCDB > CREATE TABLE TEST (
2 ID NUMBER (10) NOT NULL
3 DESCRIPTION VARCHAR2 (50) NOT NULL
4 CONSTRAINT test_pk PRIMARY KEY (ID)
5)
Table created.
Elapsed: 00:00:00.14
Sys@newtestCDB > CREATE SEQUENCE test_seq
Sequence created.
Elapsed: 00:00:00.02
Elapsed: 00:00:00.38
Sys@newtestCDB > CREATE OR REPLACE TRIGGER test_before_insert
2 BEFORE INSERT ON test
3 FOR EACH ROW
4 BEGIN
5 SELECT test_seq.NEXTVAL INTO: new.id FROM dual
6 END
7 /
Trigger created.
Elapsed: 00:00:00.12
Sys@newtestCDB > INSERT INTO TEST (DESCRIPTION) VALUES ('do not specify ID')
1 row created.
Elapsed: 00:00:00.08
Sys@newtestCDB > INSERT INTO TEST (ID, DESCRIPTION) VALUES (TEST_USER.DEPT_SEQ.NEXTVAL, 'specify ID')
INSERT INTO TEST (ID, DESCRIPTION) VALUES (TEST_USER.DEPT_SEQ.NEXTVAL, 'specify ID')
*
ERROR at line 1:
ORA-02289: sequence does not exist
Elapsed: 00:00:00.01
Sys@newtestCDB > INSERT INTO TEST (ID, DESCRIPTION) VALUES (TEST_SEQ.NEXTVAL, 'specify ID')
1 row created.
Elapsed: 00:00:00.01
Sys@newtestCDB > SELECT * FROM TEST
ID DESCRIPTION 1 does not specify ID 3 specify ID
Elapsed: 00:00:00.03
2.DEFAULT Values Using Sequences
Sys@newtestCDB > INSERT INTO TEST (description) VALUES ('DESCRIPTION only')
1 row created.
Elapsed: 00:00:00.01
Sys@newtestCDB > INSERT INTO TEST (id, description) VALUES (999, 'ID=999 and DESCRIPTION')
1 row created.
Elapsed: 00:00:00.00
Sys@newtestCDB > INSERT INTO TEST (id, description) VALUES (NULL, 'ID=NULL and DESCRIPTION')
1 row created.
Elapsed: 00:00:00.01
Sys@newtestCDB > SELECT * FROM test
ID DESCRIPTION 4 DESCRIPTION only 999 ID=999 and DESCRIPTION ID=NULL and DESCRIPTIONElapsed: 00:00:00.02
Sys@newtestCDB > CREATE TABLE TEST (
2 ID NUMBER (10) DEFAULT ON NULL test_seq.NEXTVAL
3 DESCRIPTION VARCHAR2 (50) NOT NULL
4)
Table created.
Elapsed: 00:00:00.02
Sys@newtestCDB > INSERT INTO TEST (description) VALUES ('DESCRIPTION only')
1 row created.
Elapsed: 00:00:00.01
Sys@newtestCDB > INSERT INTO TEST (id, description) VALUES (999, 'ID=999 and DESCRIPTION')
1 row created.
Elapsed: 00:00:00.01
Sys@newtestCDB > INSERT INTO TEST (id, description) VALUES (NULL, 'ID=NULL and DESCRIPTION')
1 row created.
Elapsed: 00:00:00.01
Sys@newtestCDB > SELECT * FROM test
ID DESCRIPTION 5 DESCRIPTION only 999 ID=999 and DESCRIPTION 6 ID=NULL and DESCRIPTION
Elapsed: 00:00:00.02
3. Look in the last article.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
SELECT dbid, baseline_name, baseline_type, moving_window_size from dba_hist_baseline; DBID BAS
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.