oracle


一、創建表

create table tablename (

id int <not null >| identity(1,1) | primary key | unique ,

name varchar (20) default 'ada')

identity(1,1) 是用來定義逐漸增長的數據 ,(1,1) 第二個參數表示增長幅度,第一個表示參照於前面哪個,如1表示前面一個數的值,2則表示前面第二個數的值


二、alter table 修改表

新增加一個列

alter table tablename

add columnname type(數據類型) 如 alter table plays add pay int default '1000' 往plays中添加工資一列 默認爲1000

但是若原先就含有數據,那pay設置爲null , 新的數據才顯示1000

最好做法就是 alter table plays add pay int default 1000 not null 有了not null 已經存在的數據就會按1000錄入


select name,pay,pay*(2+500)
from plays




select name+'name' as 名字加後綴 ,pay
from plays




select distinct pay from plays


select * from plays
where pay between '2000' and '4000'


select * from plays
where pay in( '2000' , ' 5000')


select * from plays
where name like 'l%'




select * from plays
where clubId > 2
and id<7
or name like'l%' //and 的優先級 大於or


select starttime as 時間 from plays
order by 時間 desc //按別名排序


select LOWER(name) 小寫 from plays


select UPPER(name) 大寫 from plays




select INITCAP(name) from plays //oracle 纔有INITCAP這個函數 首字母大寫 其他小寫


select length(pay) from plays
where pay in( '2000' , ' 5000')


select RoUND(pay,-2) 百位四捨五入
from plays


select (getdate()-starttime) as 任期
from plays
where id =5

create table player( pid int not null primary key ,
pname varchar(20),
p_cid int not null ,
ptime date default sysdate,
foreign key (p_cid) references play(cid))


發佈了61 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章