oracle基本笔记整理
生活随笔
收集整理的這篇文章主要介紹了
oracle基本笔记整理
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
??????? oracle,簡(jiǎn)單來(lái)說(shuō)就是數(shù)據(jù)庫(kù),數(shù)據(jù)庫(kù) ,顧名思義,就是存放數(shù)據(jù)的容器!!
不知道oracle的我先科普一下吧~~~科普,科學(xué)普及簡(jiǎn)稱科普,又稱大眾科學(xué)或者普及科學(xué),是指利用各種傳媒以淺顯的、讓公眾易于理解、接受和參與的方式向普通大眾介紹自然科學(xué)和社會(huì)科學(xué)知識(shí)、推廣科學(xué)技術(shù)的應(yīng)用、倡導(dǎo)科學(xué)方法、傳播科學(xué)思想、弘揚(yáng)科學(xué)精神的活動(dòng)。
??????? nice,科普完畢,接下來(lái)廢話不多說(shuō)了,直接上代碼案例,前人說(shuō):腦子是個(gè)好東西,得用起來(lái)!!!后人補(bǔ)充到:古人說(shuō)的對(duì)!!!
select * from scott.emp; select eName from scott.emp; select rowid,ename from scott.emp where ename='SMITH'; select emp.*,rownum from scott.emp where rownum<11;--創(chuàng)建學(xué)員信息表 create table student ( stuNo char(6) not null, stuName varchar2(20) not null, stuAge number(3,0) not null, stuID number(18,0), stuSeat number(2,0) );insert into stuinfo(stuNo,stuname,stuAge,stuSeat)values('2','活動(dòng)',25,3) select * from stuinfo--查詢表的位置 select tablespace_name,table_name from user_tables where table_name=upper('stuinfo');--創(chuàng)建表空間 create tablespace test datafile 'D:\oracle\shujuku\test.ora' size 1000M; create user test identified by test default tablespace test quota 500M on users; grant all privileges to test;--查看表空間 select file_name,tablespace_name,bytes,autoextensible from dba_data_files where tablespace_name='test';select * from test.stuinfo;--提交事務(wù) commit; select * from scott.emp;--修改密碼 alter user system identified by 123;select * from scott.emp; --rowid偽列數(shù)據(jù)對(duì)象編號(hào) 文件編號(hào) 塊編號(hào) 行編號(hào) select e.*,rowid from scott.emp e; --rownum,從1開(kāi)始,大于1的東西查不出來(lái),小于等于某個(gè)值可以查詢 select e.*,rownum from scott.emp e where rownum<=10; select * from scott.dept; insert into scott.dept(deptno,dname,loc)values('5','1111','dsds'); commit;delete from scott.dept where deptno='5' ;commit;----創(chuàng)建學(xué)員信息表 create table student ( stuNo number not null, stuName varchar2(20) not null, stuAge number(3,0) not null, stuSeat number(2,0) ); select * from studentinsert into student(stuNo,stuname,stuAge,stuSeat)values('1','張三',18,1); insert into student(stuNo,stuname,stuAge,stuSeat)values('2','李四',20,2); insert into student(stuNo,stuname,stuAge,stuSeat)values('3','王五',15,3); insert into student(stuNo,stuname,stuAge,stuSeat)values('4','張三',18,4); insert into student(stuNo,stuname,stuAge,stuSeat)values('5','張三',20,5);--事務(wù)的處理 --沒(méi)有添加進(jìn)去編號(hào)8 insert into student(stuNo,stuname,stuAge,stuSeat)values('6','王五1',12,6); insert into student(stuNo,stuname,stuAge,stuSeat)values('7','張三1',14,7); savepoint a; insert into student(stuNo,stuname,stuAge,stuSeat)values('8','張三',20,5); rollback to savepoint a; commit; select * from test.student;--選擇無(wú)重復(fù)的行distinct select distinct stuname from student;--選擇重復(fù)的行distinct(姓名和年齡) select distinct stuname ||stuage from student;/* 注釋的重要性 */ --別名 select distinct stuname "姓名" from student;--復(fù)制一個(gè)表 as后邊加一個(gè)select create table newstudent1 as select * from student; select * from newstudent1 ; --復(fù)制表的結(jié)構(gòu)(不包括數(shù)據(jù)) create table newstudent as select * from student where 1=2; select * from newstudent;--查詢表中的記錄數(shù) select count(1) from student;--查詢姓名和年齡中不存在重復(fù)的記錄 --大于等于是查詢重復(fù)的,小于是查詢不重復(fù)的 select stuname,stuage from student group by stuname,stuage having(count(stuname||stuage)<2); select stuname,stuage from student group by stuname,stuage having(count(stuname||stuage)>1); select stuname from student group by stuname having(count(stuname)<5);--查詢用戶數(shù)量大于10的 select * from user_all_tables a where a.num_rows>1;--添加列,刪除列 alter table student add(phone varchar2(20),emil varchar2(20)); alter table student drop(phone); select * from student;select * from stuinfo; select stuname from student group by stuname having(count(stuname)>1);/* oracle的日期函數(shù)last_day 意思是得到每月的最后一天,用這個(gè)函數(shù),我們可以得到各種不同的日期. 1:得到當(dāng)前月第一天與最后一天 */ select to_char(trunc(sysdate,'MONTH'),'yyyymmdd')firstday , to_char(last_day(trunc(sysdate,'MONTH')),'yyyymmdd') lastdayfrom dual;--2:得到上月第一天與上月最后一天 SELECT to_char( last_day(add_months(SYSDATE, -2)) + 1 ,'yyyymmdd') firstday ,to_char(last_day(add_months(SYSDATE, -1)),'yyyymmdd') lastday FROM dual; --3:得到上上個(gè)月第一天與上上個(gè)月最后一天 SELECT to_char( last_day(add_months(SYSDATE, -3)) + 1 ,'yyyymmdd') firstday ,to_char(last_day(add_months(SYSDATE, -2)),'yyyymmdd')lastday FROM dual; --4:得到下個(gè)月第一天與下個(gè)月最后一天 SELECT to_char( last_day(add_months(SYSDATE, 0)) + 1 ,'yyyymmdd') firstday ,to_char(last_day(add_months(SYSDATE, 1)),'yyyymmdd')lastday FROM dual;
?????? nice,有的人可能之前沒(méi)學(xué)過(guò)數(shù)據(jù)庫(kù),比如說(shuō)my sql ,sql server 等等,直接上來(lái)就是oracle,所以,推薦一部視頻,即使你沒(méi)有學(xué)過(guò)sql server什么的,或者學(xué)過(guò)沒(méi)深入理解的,那么,請(qǐng)點(diǎn)擊 這里,?密碼: 3ydr,一共46節(jié)課,足足夠你學(xué)會(huì)oracle了,拿走不謝!!!
總結(jié)
以上是生活随笔為你收集整理的oracle基本笔记整理的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 山推320推土机参数配置?
- 下一篇: 推流电脑为什么叫推流机?