oracle中常用的一些語句----"增刪改查_百度文庫_第1頁
oracle中常用的一些語句----"增刪改查_百度文庫_第2頁
oracle中常用的一些語句----"增刪改查_百度文庫_第3頁
oracle中常用的一些語句----"增刪改查_百度文庫_第4頁
oracle中常用的一些語句----"增刪改查_百度文庫_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、如何查找、刪除表中重復(fù)的記錄方法原理:1、Oracle中,每一條記錄都有一個(gè)rowid,rowid在整個(gè)數(shù)據(jù)庫中是唯一的,rowid確定了每條記錄是在ORACLE中的哪一個(gè)數(shù)據(jù)文件、塊、行上。2、在重復(fù)的記錄中,可能所有列的內(nèi)容都相同,但rowid不會(huì)相同,所以只要確定出重復(fù)記錄中那些具有最大rowid的就可以了,其余全部刪除。實(shí)現(xiàn)方法:SQL create table a (2 bm char(4), -編碼3 mc varchar2(20) -名稱4 )5 /表已建立。SQL insert into a values(1111,1111);SQL insert into a values(

2、1112,1111);SQL insert into a values(1113,1111);SQL insert into a values(1114,1111);SQL insert into a select * from a;插入4個(gè)記錄。SQL commit;完全提交。SQL select rowid,bm,mc from a;ROWID BM MC- - -查詢到8記錄。 查出重復(fù)記錄SQL select rowid,bm,mc from a where a.rowid!=(select max(rowid) from a b where a.bm=b.bm and a.mc=b.

3、mc);ROWID BM MC- - -刪除重復(fù)記錄SQL delete from a a where a.rowid!=(select max(rowid) from a b where a.bm=b.bm and a.mc=b.mc);刪除4個(gè)記錄。SQL select rowid,bm,mc from a;ROWID BM MC- - -desc table;檢查表結(jié)構(gòu)select * from tab where tabtype=TABLE;顯示當(dāng)前用戶下的所有表。select count(*) from table;顯示此表的數(shù)據(jù)行數(shù);spool c:tony.txt;日記路徑spo

4、ol off;關(guān)閉記錄后可以看到日記文件里的內(nèi)容。alter table stu add(classid number(2);添加字段alter table stu modify(xm varchar2(12);修改字段的長(zhǎng)度alter table stu drop column sal;drop table stu;rename student to stu;alter table student drop column sal; alter table stu add(salary number(7,2);insert into stu values(A001,張三,男,01-5月-05,

5、10);insert into stu(xh,xm,sex) values (A003,JOHN,女);insert into student(xh,xm,sex,birthday) values (A004,MARTIN,男,null);修改updateupdate stu set sex=女 where xh=A001;update student set sex=男,birthday=1980-04-01where xh=A001;update student set classid=20 where birthday is null;delete from stu;drop table

6、 student;delete from stu where xh=A001;truncate table stu;刪除表中的所有記錄,表結(jié)構(gòu)還在不寫日記無法找回記錄select * from stu;select * from student where classid like 1%;select * from student where xh like %A%;select * from student where xh like A%;select * from student where xh like %A;select * from student where xh = A%;s

7、elect * from student order by birthday;select * from student order by birthday desc,xh asc; -按birthday 降序 按xh升序(asc/默認(rèn))select * from student where sex=女 or birthday=1999-02-01;select * from student where sex=女 and birthday=1999-02-01;select * from student where salary 20 and xh B002; (!=) oracle函數(shù)的學(xué)

8、習(xí)單行函數(shù) 返回值只有一個(gè)分組函數(shù) 返回值是多條記錄group bysumavgselect sysdate from dual;dual啞元素 沒有表需要查詢的時(shí)候select xm|-|classid from stu;select 1+1 from dual;select job,next_date,next_sec,failures,broken from user_jobs;show parameter job_queue_processes;alter system set job_queue_processes=5;select owner,object_name from db

9、a_objects where object_type=DATABASE LINK;select * from dualgis3; 判斷是否創(chuàng)建select object_name,object_typefrom user_objectsorder by object_type; -用戶所擁有的對(duì)象select object_name,object_typefrom user_objectsWHERE object_type=TABLE; -用戶所擁有的表另外一種方法select table_name from user_tables;select object_name,object_typ

10、efrom user_objectsWHERE object_type=INDEX; -用戶所擁有的索引INSERT INTO Store_Information (store_name, Sales, Date)SELECT store_name, Sales, DateFROM Sales_InformationWHERE to_char(date,yyyy)=1998;exp/imp help=y 顯示exp/imp命令下的參數(shù)imp tony/gisinfo file=tony.dmp log=loga show=y full=yif-then-end if的使用if v_test=1

11、 then begin 。.。. end; end if;while-loop-end loop的使用if v_test=1 then begin 。.。.。.end;end if; CASE的使用update jzqld1 set bcrq=casewhen id like 3% then 09010102when id like 4% then 09010204else 09010805end;刪除用戶drop user tony/create user tonyshowdown abort; startup;希望在scott用戶下能看到mk用戶中test表的數(shù)據(jù)?connect mk/m

12、123grant select on test to scott; /授權(quán)scott能selectconnect scott/tigerselect * from mk.test;create synonym mtest for mk.test; /為表建立的/可以為任何對(duì)象建立同義詞select * from mtest; /相當(dāng)于select * from mk.test;位圖索引create bitmap index ind_aa on emp(job);create index ind_dept on dept(dname,loc);/聯(lián)合索引 分次序的create index ind

13、_dept1 on dept(loc,dname);show parameter db_name數(shù)據(jù)庫名DBA要及時(shí)查看數(shù)據(jù)庫中數(shù)據(jù)文件的狀態(tài)(如被誤刪除),根據(jù)實(shí)際情況決定如何進(jìn)行處理,檢查數(shù)據(jù)文件的狀態(tài)的SQL如下:select file_name,status from dba_data_files;如果數(shù)據(jù)文件的STATUS列不是AVAILABLE,那么就要采取相應(yīng)的措施,如對(duì)該數(shù)據(jù)文件進(jìn)行恢復(fù)操作,或重建該數(shù)據(jù)文件所在的表空間。/給用戶授予權(quán)限grant connect,dba,resource to testserver_user;/創(chuàng)建用戶并指定表空間create user ORACLE8I identified by ORACLE8Idefault tablespace ORACLE8Itemporary tablespace test_temp ;/創(chuàng)建數(shù)據(jù)表空間create tablespace oracle8iloggingsize 32mautoextend onnext 32m maxsize 2048mextent man

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論