oracle學習筆記

來源:互聯網
上載者:User

標籤:

--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學習筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.