TableSpace
表空間:
一個(gè)表空間對(duì)應(yīng)多個(gè)數(shù)據(jù)文件(物理的dbf文件)
用語(yǔ)法方式創(chuàng)建tablespace,用sysdba登陸:
--創(chuàng)建表空間mytabs,大小為10MB:
create tablespace mytabs datafile
'C:oracleoradatamydbmytabs1.dbf' size 10M;
alter user zgl default tablespace mytabs;
--把tabs做為zgl的默認(rèn)表空間。
grant unlimited tablespace to zgl;
--將操作表空間的權(quán)限給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('沒有查到數(shù)據(jù)!');
when too_many_rows then
dbms_output.put_line('返回了多行數(shù)據(jù)!');
end pro_test_exception;
安全管理
以下語(yǔ)句以sysdba登陸:
用戶授權(quán):
alter user zgl account lock;--鎖定帳號(hào)。
alter user zgl identified by zgl11;--修改用戶密碼。
alter user zgl account unlock;--解除帳號(hào)鎖定。
alter user zgl default tablespace tt;--修改用戶zgl的默認(rèn)表空間為tt。
create user qqq identified by qqq123 default tablespace tt;--創(chuàng)建用戶。
grant connect to qqq;--給qqq授予connect權(quán)限。
grant execute on zgl.proc01 to test;--將過程zgl.proc01授予用戶test。
grant create user to zgl;--給zgl授予創(chuàng)建用戶的權(quán)限。
revoke create user from zgl;--解除zgl創(chuàng)建用戶的權(quán)限。
角色授權(quán):
create role myrole;--創(chuàng)建角色myrole
grant connect to myrole;--給myrole授予connect權(quán)限
grant select on zgl.t_user to myrole;--把查詢zgl.t_user的權(quán)限授予myrole
grant myrole to test;--把角色myrole授予test用戶
概要文件(配置文件):
全局設(shè)置,可以在概要文件中設(shè)置登陸次數(shù),如超過這次數(shù)就鎖定用戶。
Synonym
創(chuàng)建同義詞示例:
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'
跨數(shù)據(jù)庫(kù)查詢
create database link dblinkzgl
connect to myuser identified by a using 'mydb'
Select * From
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;
更多信息請(qǐng)查看IT技術(shù)專欄