天易07—-韓順平oracle講解部分總結(02)(前奏補充)

來源:互聯網
上載者:User

1)啟動oracle內建的SQL PLUS命令:sqlplusw(在運行命令裡輸入此語句後會出現sql plus介面)  doc命令實現:sqlplus

2)啟動SQL PLUS之後串連資料庫命令:conn 使用者名稱/密碼@資料庫名 ;

3)修改使用者名稱密碼命令:passw 斷行符號後根據提示填寫

4)將查詢的內容結果全部放到一個 .sql檔案中的命令:spool

a)spool f:\wzh.sql ; 在f盤建立一個wzh的sql檔案

b)查詢資料:select * from users;

c)spool off ; (此時已將users表中查詢的資料全部儲存到了wzh.sql檔案中了)

5)

a)建立新使用者命令:create user wangzihu(新使用者) identified by 1234(密碼);

b)想用建立的使用者進行登入則必須為新使用者賦予許可權,命令為:

grant connect to wangzihu;

c)想在建立的使用者wangzihu中具有建立表的許可權,則需執行以下指令:

 1.重新串連到dba許可權的使用者,例如system使用者

 2.進行授權(resource)

Grant resource to wangzihu;

6)訪問不同使用者中的表

例如:wangzihu使用者想訪問system使用者中的users表,命令如下:

 grant select on users to wangzihu;(這是在使用者為system下所執行的命令,此時如果在

wangzihu使用者下只能查詢system使用者中users表的資料)如果想對system表中的資料進

行增刪改查則可以執行如下命令:

grant all on users to wangzihu;

注意:在wangzihu使用者中進行查詢system使用者中的表時,必須要加上system,例如:

Select * from system.users;

7)回收許可權(revoke)命令如下:

Revoke select on users from wangzihu;(這條指令也是在system使用者下執行的)

8)賬戶鎖定(profile)

概述:指定該賬戶登陸時最多可以輸入密碼的次數和天數

例如:指定wangzihu使用者最多嘗試3次登陸,鎖定的天數為2天

a)建立sql命令:

create profile wangzihu_lock limit failed_login_attempts 3 password_lock_time 2;

b)執行sql命令:

alter user wangzihu profile wangzihu_lock;

9)賬戶解鎖

Sql命令:alter user wangzihu account unlock;

(2012-5-29)

//oracle函數與預存程序

1.函數

1)建立函數

create or replace function get_tax(x number)

return number as

begin

 declare y number;

 begin

   y:=x-2000;

   if x <= 0 then

     return 0;

     end if;

     return y*5/100;

     end;

     end get_tax;

2)執行函數

SQL> select get_tax(1000) from dual;

結果顯示:

GET_TAX(1000)

-------------

         -50

2.預存程序

1)預存程序(in)

建立:

create or replace procedure update_test(uid in varchar2,uname in varchar2)

as

begin

 update test set username=uname where userid=uid;

 commit;

 end update_test;

執行:

SQL> execute update_test('06','王子虎');

2)預存程序(out)

建立:

create or replace procedure test_up(uid out varchar2,uname out varchar2)

as

begin

select * into uid,uname from test where userid='04';//不能缺少into

end test_up;

執行:

SQL> var id varchar2(10);

SQL> var name varchar2(30);

SQL> exec test_up(:id,:name);//括弧裡必須加上冒號,這和in的不同

結果顯示:

PL/SQL procedure successfully completed

id

---------

04

name

---------

天易

(2012-6-5)

1)對資料分組的總結(group by)

a).分組函數只能出現在挑選清單、having、order by子句中

b).如果在select語句中同時包含有group by,having,order by那麼它們的順序是group by,having,ordre by

c).在選擇列中如果有列、運算式、和分組函數,那麼這些列和運算式必須有一個出現在group by子句中,否則會出錯。例如:

select  deptno,avg(sal),max(sal) from emp group by deptno having  avg(sal)<2000;

這裡deptno就一定要出現在group by中

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.