標籤:
--Oracle查詢目前的版本
select * from v$version;
----------Oracle 查詢服務器端編碼----------
select * from v$nls_parameters where parameter=‘NLS_CHARACTERSET‘;
----------Oracle 查詢目前時間的三種方式----------
select sysdate from dual;
--2016/8/5 21:47:44
select current_date from dual;
--2016/8/5 21:48:42
select SYSTIMESTAMP from dual;
--05-8月 -16 09.48.23.880000 下午 +08:00
DESC STUINFO;
select name from v$database;
select * from v$database;
select * from user_tables;
select * from user_tablespaces;
select index_name from user_indexes;
select database from user_datapump_jobs;
/*建立學生資訊表*/
CREATE table stuInfo(
stuName varchar2(20) NOT NULL,
stuNo char(6) NOT NULL,
stuAge number(3,0) default 0,
stuID numeric(18,0),
stuSeat NUMERIC(2,0)
)
--建立學員成績表
create table stuMarks
(
examNO CHAR(7) NOT NULL,
stuNo CHAR(6) NOT NULl,
writtenExam NUMERIC(3,0),
labExam numeric(3,0)
);
--刪除約束
alter table stuinfo
drop constraint id;
--增加主鍵約束
alter table stuinfo
add constraint pk_stuno primary key (stuno);
alter table stumarks
add constraint pk_examno primary key (examno);
--添加唯一約束
alter table stuinfo
add constraint UQ_STUID UNIQUE (STUID);
--添加檢查約束check
alter table stuinfo
add constraint ck_stuage check(stuAge between 15 and 40);
--添加外鍵索引
alter table stumarks
add constraint fk_stuno foreign key(stuno) references stuinfo(stuno);
--查看錶空間
select * from user_tablespaces
--修改欄位的類型
alter table stuinfo modify (stuAddress number(20));
--查詢出使用者所有表的索引
select * from user_indexes
--修改列名
alter table stuinfo rename column stuAdress to stuAddress;
--修改表名
ALTER TABLE username.TEST1 RENAME TO stuinfo
oracle學習筆記