oracle基本笔记整理
生活随笔
收集整理的這篇文章主要介紹了
oracle基本笔记整理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
??????? oracle,簡單來說就是數據庫,數據庫 ,顧名思義,就是存放數據的容器!!
不知道oracle的我先科普一下吧~~~科普,科學普及簡稱科普,又稱大眾科學或者普及科學,是指利用各種傳媒以淺顯的、讓公眾易于理解、接受和參與的方式向普通大眾介紹自然科學和社會科學知識、推廣科學技術的應用、倡導科學方法、傳播科學思想、弘揚科學精神的活動。
??????? nice,科普完畢,接下來廢話不多說了,直接上代碼案例,前人說:腦子是個好東西,得用起來!!!后人補充到:古人說的對!!!
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;--創建學員信息表 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','活動',25,3) select * from stuinfo--查詢表的位置 select tablespace_name,table_name from user_tables where table_name=upper('stuinfo');--創建表空間 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;--提交事務 commit; select * from scott.emp;--修改密碼 alter user system identified by 123;select * from scott.emp; --rowid偽列數據對象編號 文件編號 塊編號 行編號 select e.*,rowid from scott.emp e; --rownum,從1開始,大于1的東西查不出來,小于等于某個值可以查詢 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;----創建學員信息表 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);--事務的處理 --沒有添加進去編號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;--選擇無重復的行distinct select distinct stuname from student;--選擇重復的行distinct(姓名和年齡) select distinct stuname ||stuage from student;/* 注釋的重要性 */ --別名 select distinct stuname "姓名" from student;--復制一個表 as后邊加一個select create table newstudent1 as select * from student; select * from newstudent1 ; --復制表的結構(不包括數據) create table newstudent as select * from student where 1=2; select * from newstudent;--查詢表中的記錄數 select count(1) from student;--查詢姓名和年齡中不存在重復的記錄 --大于等于是查詢重復的,小于是查詢不重復的 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);--查詢用戶數量大于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的日期函數last_day 意思是得到每月的最后一天,用這個函數,我們可以得到各種不同的日期. 1:得到當前月第一天與最后一天 */ 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:得到上上個月第一天與上上個月最后一天 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:得到下個月第一天與下個月最后一天 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,有的人可能之前沒學過數據庫,比如說my sql ,sql server 等等,直接上來就是oracle,所以,推薦一部視頻,即使你沒有學過sql server什么的,或者學過沒深入理解的,那么,請點擊 這里,?密碼: 3ydr,一共46節課,足足夠你學會oracle了,拿走不謝!!!
總結
以上是生活随笔為你收集整理的oracle基本笔记整理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 山推320推土机参数配置?
- 下一篇: oracle笔记整理2