Oracle 資料庫的8個學習點

來源:互聯網
上載者:User
   學習Oracle也有一段日子了,今天看到這篇關於oracle學習的總結還是覺得蠻有用的。遂留下品味品味。

 TableSpace

     資料表空間: 一個資料表空間對應多個資料檔案(物理的dbf檔案) 用文法方式建立     tablespace,用sysdba登陸: --建立資料表空間mytabs,大小為10MB:


create tablespace mytabs datafile            'C:\oracle\oradata\mydb\mytabs1.dbf' size 10M;            alter user zgl default tablespace mytabs;            --把tabs做為zgl的預設資料表空間。            grant unlimited tablespace to zgl;            --將動作表空間的許可權給zgl。


 Exception
樣本:

create or replace procedure            pro_test_exception(vid in varchar2) is            userName varchar2(30);            begin            select name into userName from t_user where id=vid;            dbms_output.put_line(userName);            exception            when no_data_found then            dbms_output.put_line('沒有查到資料!');            when too_many_rows then            dbms_output.put_line('返回了多行資料!');            end pro_test_exception;

 安全管理

    以下語句以sysdba登陸: 使用者授權: alter user zgl account lock;--鎖定帳號。 alter  user zgl identified by zgl11;--修改使用者密碼。 alter user zgl account unlock;--解除帳號鎖定。 alter user zgl default tablespace tt;--修改使用者zgl的預設資料表空間為tt。 create user qqq identified by qqq123 default tablespace tt;--建立使用者。

 grant connect to qqq;--給qqq授予connect許可權。 grant execute on zgl.proc01 to test;--將過程zgl.proc01授予使用者test。 grant create user to zgl;--給zgl授予建立使用者的許可權。 revoke create user from zgl;--解除zgl建立使用者的許可權。

角色授權: create role myrole;--建立角色myrole grant connect to myrole;--給myrole授予connect許可權 grant select on zgl.t_user to myrole;--把查詢zgl.t_user的許可權授予myrole grant myrole to test;--把角色myrole授予test使用者

 概要檔案(設定檔): 全域設定,可以在概要檔案中設定登陸次數,如超過這次數就鎖定使用者。

 Synonym

 建立同義字樣本:


create public synonym xxx for myuser.t_user            create synonym t_user for myuser.t_user            select * from dba_synonyms where table_name='T_USER'


 跨資料庫查詢


create database link dblinkzgl            connect to myuser identified by a using 'mydb'            Select * From t_user@dblinkzgl


 course樣本
樣本1:


create or replace procedure pro_test_cursor is            userRow t_user%rowtype;            cursor userRows is            select * from t_user;            begin            for userRow in userRows loop            dbms_output.put_line            (userRow.Id||','||userRow.Name||','||userRows%rowcount);            end loop;            end pro_test_cursor;

樣本2:


create or replace procedure            pro_test_cursor_oneRow(vid in number) is            userRow t_user%rowtype;            cursor userCur is            select * from t_user where id=vid;            begin            open userCur;            fetch userCur into userRow;            if userCur%FOUND then            dbms_output.put_line            (userRow.id||','||userRow.Name);            end if;            close userCur;            end pro_test_cursor_oneRow;

 record樣本


create or replace            procedure pro_test_record(vid in varchar2) is            type userRow is record(            id t_user.id%type,            name t_user.name%type            );            realRow userRow;            begin            select id,name into            realRow from t_user where id=vid;            dbms_output.put_line            (realRow.id||','||realRow.name);            end pro_test_record;

 rowtype樣本


create or replace procedure            pro_test_rowType(vid in varchar2) is            userRow t_user%Rowtype;            begin            select * into userRow from t_user where id=vid;            dbms_output.put_line            (userRow.id||','||userRow.name);            end pro_test_rowType;

 

 

聯繫我們

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