初級Oracle和SQL學習者的學習筆記。韓順平-玩轉oracle。

來源:互聯網
上載者:User

標籤:des   style   io   ar   使用   sp   for   on   檔案   

我自己就是一個oracle和sql的初學者,前段時間看了韓順平老師的oracle視頻教程,覺得很深入淺出,收穫了很多。同時自己也做了不少筆記,現在想將紙質筆記以自己的話總結出來。俗話說得好:教學總是相得益彰,在總結的過程中想必會加深自己的印象,能夠鞏固自己的學習過程。

 

 

oracle 使用者部分:

建立使用者:create user user_name identified by user_password;

此時使用者並沒有串連資料庫的許可權。需要給其賦予串連許可權

賦予許可權:許可權分為對象許可權和系統許可權。

grant [select|updat|all] on table_name to user_name;--對象許可權

                grant connect to user_name with admin option; --系統許可權

with admin option 表示這個user可以將此許可權繼續下發 

收回許可權: revoke  Quanxian on table_name from user_name;

串連資料庫:conn user_name/user_password;

profile檔案,可以限制某些使用者的行為,如登入嘗試次數,密碼輸入錯誤次數等。

建立profile 檔案: create profile profile_name limit failed_login_attempts m password_lock time n;

應用給某使用者:alter user user_name profile profile_name;

 

在初次建立oracle資料庫執行個體的時候,預設建立了幾個使用者,但是只有幾個使用者沒有上鎖,給某個使用者解鎖的步驟如下:

首先要以sysdba的使用者登入oracle資料庫,需要開啟sqlplus這個oracle安裝內建的工具

cmd or terminal 下: sqlplus / as sysdba;

解鎖使用者:alter user user_name account unlock;

更改使用者密碼: alter user user_name identified by  password;

 

這裡,幾個常用的使用者的系統預設密碼總結如下: 

scott:tiger

system:manager

sys:change_on_install

sysdba 不要求輸入密碼登入。

幾個使用者的許可權具體如何等我總結到後面再補上,韓順平老師這裡講的有點分散。

 

繼續使用者管理。

 

設定口令曆史:修改密碼時不能使用以前使用的密碼

password_reuse_time n;--n 天后才能重用密碼 

定期修改密碼:

create profile profile_name limit password_life_time m pasword_grace_time n;

m天修改一次密碼,寬限期n天。  

 

sql語句中的幾種資料類型:

char(n) :定長字串,最長2000,查詢速度快

varchar2(n):變長字串,最長4000,節省空間的

clob(character large object) :字元型大對象,最大4G

number(m,n):m位有效數,其中n位小數

number(m) :m位整數

date:日期類型 年月日時分秒

timestamp:更精確

blob:圖片類型,位元據 可存放圖片,聲音,最大4G(韓老師當時用的是9i,我用了個64位的12c版本,估計能支援最大8G的吧。。自己猜的)

 

顯示表結構:desc table_name;

增加欄位:alter table table_name add (colum_name,colum_type);\

修改欄位: alter table table_name modify (colum_name,colum_type);

刪除欄位:alter table table_name  drop colum colum_name;

刪除表:drop table table_name;

date格式‘日-月-年‘

insert into table_name values(每個欄位的值,如果有非數位欄位值,需要用單引號對‘‘括起來)

alter session set nls_date_format ‘yyyy-mm-dd‘;

【注意】這個改的效果是臨時生效的。 

插入空值NULL(該欄位允許為空白才行)

查詢空值:select xxx from xxx where colum_name is [NULL|NOT NULL]; 

更改表內容:update table_name set colum_name=‘xxx‘ where yyy;

刪除資料:delete from table_name;--刪除資料,表的結構還在,可恢複,刪除速度略慢
truncate table table_name;刪除表中所有的資料,表結構還在,但是由於不寫日誌,無法找回刪除記錄,好處是刪除速度快。  

恢複資料:

save point point_name;--建立復原點

delete from table_name;

rollback to point_name;--恢複

刪除表結構和資料:drop table table_name;--刪除表的結構和資料

 

開啟顯示操作時間開關:set timming on;

 

nvl函數處理NULL值的情況:nvl(欄位名,值),如果欄位本身值為NULL,則改變其新值為逗號後面的那個,如果不是NULL,不做任何事。 


where 語句後面的like關鍵字用於尋找並匹配合格欄位:

%表示零到多個字元

底線_ 表示任意單個字

 

in關鍵字表示從一個範圍內選取

 

order by語句預設升序(ASC),如果想降序排列,可以這樣:

select *** from table_name where xxx order by colum_name desc; 

別名排序 select sss as xx from xxx之類的

 

資料分組函數:max,min,avg,sum,count

 

子查詢:在select語句的where欄位後接一個select語句,具體情況具體分析。

 

分組查詢

 

分頁查詢

 

明天繼續。 

 

 

 

 

 



 

初級Oracle和SQL學習者的學習筆記。韓順平-玩轉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.