CREATE TABLE T2 ( C1 NUMBER(5), C2 NUMBER(5) INVISIBLE) INSERT INTO T2 (C1,C2) VALUES (10, 20); INSERT INTO T2 VALUES(30); SELECT * FROM T2; SQL> select * from t2; C1 ---------- 10 30 SELECT C1,C2 FROM T2; SQL> select c1,c2 from t2; C1 C2 ---------- ---------- 10 20 30 ALTER TABLE T2 MODIFY (C2 VISIBLE) SELECT * FROM T2 SQL> select c1,c2 from t2; C1 C2 ---------- ---------- 10 20 30
CREATE SEQUENCE t1_seq; CREATE TABLE t1 ( id NUMBER DEFAULT t1_seq.NEXTVAL, description VARCHAR2(30) ); INSERT INTO t1 (description) VALUES ('DESCRIPTION'); INSERT INTO t1 (id, description) VALUES (999, 'DESCRIPTION'); select * from t1 SQL> select * from t1; ID DESCRIPTION ---------- ------------------------------ 1 DESCRIPTION 999 DESCRIPTION
CREATE SEQUENCE order_master_seq; CREATE SEQUENCE order_details_seq; CREATE TABLE order_master ( Order_id NUMBER DEFAULT order_master_seq.NEXTVAL, Description VARCHAR2(20) ); CREATE TABLE order_details ( id NUMBER DEFAULT order_details_seq.NEXTVAL, order_id NUMBER DEFAULT order_master_seq.CURRVAL, description VARCHAR2(50) ); insert into order_master (description) values ('First Order'); insert into order_details (description) values ('First Item'); insert into order_details (description) values ('Second Item'); select * from order_master; SQL> select * from order_master; ORDER_ID DESCRIPTION ---------- -------------------- 1 First Order select * from order_details; SQL> select * from order_details; ID ORDER_ID DESCRIPTION ---------- ---------- -------------------------------------------------- 1 1 First Item 2 1 Second Item
create sequence t1_seq; CREATE TABLE t1 ( id NUMBER DEFAULT ON NULL t1_seq.NEXTVAL, description VARCHAR2(30) ); insert into t1(description) values('First Item'); // default value is used as value for ID is missing insert into t1 values(null,'Second Item'); // default value is used even when NULL is explicitly provided insert into t1 values(333,'Third Item'); SQL> select * from t1; ID DESCRIPTION ---------- ------------------------------ 1 First Item 2 Second Item 333 Third Item
GENERATED [ALWAYS | BY DEFAULT [ ON NULL ] ] AS IDENTITY [ (identity_options ) ]
CREATE TABLE order_master ( Id NUMBER GENERATED ALWAYS AS IDENTITY, Description Varchar2(20) ); Insert into order_master (description) values('First Order'); Insert into order_master (description) values('Second Order'); SQL> select * from order_master; ID DESCRIPTION ---------- -------------------- 1 First Order 2 Second Order SQL> Insert into order_master (id,description) values(100,'Third Order'); Insert into order_master (id,description) values(100,'Third Order') * ERROR at line 1: ORA-32795: cannot insert into a generated always identity column
CREATE TABLE order_master( Id NUMBER GENERATED BY DEFAULT AS IDENTITY, Description Varchar2(20) ); Insert into order_master (description) values('First Order'); Insert into order_master (id,description) values(20,'Second Order'); select * from order_master; SQL> select * from order_master; ID DESCRIPTION ---------- -------------------- 1 First Order 20 Second Order
CREATE TABLE order_master( Id NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY , Description Varchar2(20) ); Insert into order_master (id,description) values(null,'First Order'); Insert into order_master (id,description) values(20,'Second Order'); Insert into order_master (description) values('Third Order'); SQL> select * from order_master; ID DESCRIPTION ---------- -------------------- 1 First Order 20 Second Order 2 Third Order
CREATE OR REPLACE PROCEDURE get_jobs AS job_cursor SYS_REFCURSOR; BEGIN OPEN job_cursor FOR SELECT * from jobs; DBMS_SQL.RETURN_RESULT(job_cursor); END;
EXECUTE get_jobs
WITH FUNCTION Experience(hd date) RETURN NUMBER IS BEGIN RETURN floor ((sysdate - hd) / 365); END; SELECT First_name, Experience(hire_date) FROM Employees /
OFFSET { integer-literal | ? } {ROW | ROWS} FETCH { FIRST | NEXT } [integer-literal | ? ] {ROW | ROWS} ONLY
Select * from employees fetch first row only; // retrieves only first row select * from employees fetch next 5 rows only; // retrieves first 5 rows from the beginning select * from employees offset 5 rows fetch next 5 rows only; // retrieves 5 rows from 5th row select * from employees order by salary desc fetch next 5 rows only; // retrieves first 5 highest salaried employees