八个学习点帮助你全面认识Oracle数据库
TableSpace
表空间:
一个表空间对应多个数据文件(物理的dbf文件)
用语法方式创建tablespace,用sysdba登陆:
--创建表空间mytabs,大小为10MB:
createtablespacemytabsdatafile'C:\oracle\oradata\mydb\mytabs1.dbf'size10M;alteruserzgldefaulttablespacemytabs;--把tabs做为zgl的默认表空间。grantunlimitedtablespacetozgl;--将操作表空间的权限给zgl。
Exception
示例:
createorreplaceprocedurepro_test_exception(vidinvarchar2)isuserNamevarchar2(30);beginselectnameintouserNamefromt_userwhereid=vid;dbms_output.put_line(userName);exceptionwhenno_data_foundthendbms_output.put_line('没有查到数据!');whentoo_many_rowsthendbms_output.put_line('返回了多行数据!');endpro_test_exception;
安全管理
以下语句以sysdba登陆:
用户授权:
alteruserzglaccountlock;--锁定帐号。
alteruserzglidentifiedbyzgl11;--修改用户密码。
alteruserzglaccountunlock;--解除帐号锁定。
alteruserzgldefaulttablespacett;--修改用户zgl的默认表空间为tt。
createuserqqqidentifiedbyqqq123defaulttablespacett;--创建用户。
grantconnecttoqqq;--给qqq授予connect权限。
grantexecuteonzgl.proc01totest;--将过程zgl.proc01授予用户test。
grantcreateusertozgl;--给zgl授予创建用户的权限。
revokecreateuserfromzgl;--解除zgl创建用户的权限。
角色授权:
createrolemyrole;--创建角色myrole
grantconnecttomyrole;--给myrole授予connect权限
grantselectonzgl.t_usertomyrole;--把查询zgl.t_user的权限授予myrole
grantmyroletotest;--把角色myrole授予test用户
概要文件(配置文件):
全局设置,可以在概要文件中设置登陆次数,如超过这次数就锁定用户。
Synonym
创建同义词示例:
createpublicsynonymxxxformyuser.t_usercreatesynonymt_userformyuser.t_userselect*fromdba_synonymswheretable_name='T_USER'
跨数据库查询
createdatabaselinkdblinkzglconnecttomyuseridentifiedbyausing'mydb'Select*Fromt_user@dblinkzgl
course示例
示例1:
createorreplaceprocedurepro_test_cursorisuserRowt_user%rowtype;cursoruserRowsisselect*fromt_user;beginforuserRowinuserRowsloopdbms_output.put_line(userRow.Id||','||userRow.Name||','||userRows%rowcount);endloop;endpro_test_cursor;
示例2:
createorreplaceprocedurepro_test_cursor_oneRow(vidinnumber)isuserRowt_user%rowtype;cursoruserCurisselect*fromt_userwhereid=vid;beginopenuserCur;fetchuserCurintouserRow;ifuserCur%FOUNDthendbms_output.put_line(userRow.id||','||userRow.Name);endif;closeuserCur;endpro_test_cursor_oneRow;
record示例
createorreplaceprocedurepro_test_record(vidinvarchar2)istypeuserRowisrecord(idt_user.id%type,namet_user.name%type);realRowuserRow;beginselectid,nameintorealRowfromt_userwhereid=vid;dbms_output.put_line(realRow.id||','||realRow.name);endpro_test_record;
rowtype示例
createorreplaceprocedurepro_test_rowType(vidinvarchar2)isuserRowt_user%Rowtype;beginselect*intouserRowfromt_userwhereid=vid;dbms_output.put_line(userRow.id||','||userRow.name);endpro_test_rowType;