当前位置:网站首页>Common modification commands of Oracle for tables

Common modification commands of Oracle for tables

2022-07-06 23:43:00 Jaffy

Sometimes when we do projects, we don't just touch a single database ,MySQL Database or Oracle database , Generally, you should learn more or less in the process of participation , Next, I will record a few of our Oracle Several operation commands commonly used in database , In order to meet in the future , There is a place to find .

Add column fields of the table
alter table  Table name  add(
	 Field 1  data type ,
     Field 2  data type 
);

-- Example   In the existing User Add an address field to the table `address`, The data type is varchar2, The length is 30
alter table user add(
	address varchar2(30)
);
Modify the column fields of the table
alter table  Table name  modify( Field 1  data type ,.....)

-- Example , Modify existing User Address fields in the table `address`, The data type is varchar2, The length is 50
alter table user modify(address varchar2(50));
Remove the column fields of the table
alter table  Table name  drop column  Field 

-- Example , Delete existing tables User Address fields in the table `address`
alter table user drop column address
Set the comment for the field
COMMENT ON COLUMN " Table space "." Table name "." Field name " IS ' The comment ';

-- Example , Set the existing User Address fields in the table `address` The content of the note is ' Address '
COMMENT ON COLUMN "scott"."user"."address" IS ' Address ';
Paging templates
SELECT *

  FROM (SELECT a.*, ROWNUM rn

          FROM (
          		 Business sql
          ) a

         WHERE ROWNUM <=  Final offset )

 WHERE rn >=  Starting offset 
 
 
 -- Example , Inquire about User The data table , Show the first page , each page 20 Data 
 SELECT *

  FROM (SELECT a.*, ROWNUM rn

          FROM (
          		select * from user
          ) a

         WHERE ROWNUM <= 20)

 WHERE rn >= 1
Create a sequence of tables
CREATE SEQUENCE  " Table space "." The sequence of "  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE  NOORDER  NOCYCLE

-- Example , establish user Sequence of tables , Used to increment id
CREATE SEQUENCE  "scott"."user_S"  MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE  NOORDER  NOCYCLE
原网站

版权声明
本文为[Jaffy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061558569914.html