Oracle数据库几个基本操作(以9.2为例)

来源:互联网 发布:阿里云激活邀请码 编辑:程序博客网 时间:2024/06/05 10:18

前段时间遇到一个关于Oracle的案子,头一次接触Oracle,遇到不少问题。特总结如下,将来如有人遇到相同情形,希望本文能在入门时提供一点小小帮助。

一、安装

a)        装过程中可能会出现的问题,需要预先处理:

                       i.             “无法在环境变量path中插入”的错误(错误内容记不清了,大致这个意思):右击“我的电脑”à“属性”à“高级”à“环境变量”à在下面的选择框中选中“Pathà“编辑”à检查字符串长度是否超过1024à删除不必要的路径à保存。(此变量定义了用户执行的命令在系统中的查找顺序,也就是说。例如你可以在命令行中输入IMPOracle恢复备份)命令,系统会在Path包含的路径中查找命令文件,找到则运行,找不到则报错

                     ii.             hostdef不存在”的错误:Oraclewin200安装结束后(具体在安装全局数据库结束后),会自动启动例程并作基本配置,此时会出现此错误,解决方法:安装过程中检查有否产生“oracle/ora90/network/ADMIN/sqlnet.ora”文件à一旦发现生成该文件,使用记事本或UltraEdit打开à"SQLNET.AUTHENTICATION_SERVICES=(NTS)"修改为"SQLNET.AUTHENTICATION_SERVICES=(NONE)"

b)       安装程序本身没太多好说的,一切按默认,过程中会要求输入一个全局数据库名作为默认库,这是唯一需要修改的地方

二、卸载

a)        先使用oracle自带的卸载程序卸载。但它不会删除原oracle的相关配置,也不会删除数据库以及几项基本服务。所以当这些部分有错误时,哪怕重新安装也无法纠正这些错误。我们需要一下步骤彻底清除oracle.

b)       停止所有Oracle相关服务;

c)        删除Oracle安装目录

d)       删除C:/Program/Oracle目录;

e)        删除注册表相关信息:

HKLM/SoftWare/Oracle

HKLM/System/CurrentContralSet/Service/Ora……

HKLM/System/ControlSet001/Service/Ora……

HKLM/System/ControlSet002/Service/Ora

f)   重新启动计算机

三、 配置

a)   安装结束后应先对Oracle进行配置(包括建立一个管理资料库),否则无法进行大部分数据库操作。

 

启动“开始菜单”àOracle程序组”àConfiguration and MigrationToolsàEnterprise ManagerConfiguration Assistant

 

步骤2

 

步骤3

 

 

步骤4

 

 

步骤5

<!-- /* Font Definitions */ @font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 680460288 22 0 262145 0;}@font-face{font-family:"Cambria Math";panose-1:2 4 5 3 5 4 6 3 2 4;mso-font-charset:1;mso-generic-font-family:roman;mso-font-format:other;mso-font-pitch:variable;mso-font-signature:0 0 0 0 0 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 680460288 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-unhide:no;mso-style-qformat:yes;mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman","serif";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;}.MsoChpDefault{mso-style-type:export-only;mso-default-props:yes;font-size:10.0pt;mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt;mso-ascii-font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-hansi-font-family:"Times New Roman";mso-font-kerning:0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;} /* List Definitions */ @list l0{mso-list-id:817110624;mso-list-type:hybrid;mso-list-template-ids:331890388 838512750 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}@list l0:level1{mso-level-number-format:japanese-counting;mso-level-text:%1、;mso-level-tab-stop:21.0pt;mso-level-number-position:left;margin-left:21.0pt;text-indent:-21.0pt;}@list l0:level2{mso-level-number-format:alpha-lower;mso-level-text:"%2/)";mso-level-tab-stop:42.0pt;mso-level-number-position:left;margin-left:42.0pt;text-indent:-21.0pt;}@list l0:level3{mso-level-number-format:roman-lower;mso-level-tab-stop:42.3pt;mso-level-number-position:right;margin-left:42.3pt;text-indent:-21.0pt;}@list l0:level4{mso-level-tab-stop:84.0pt;mso-level-number-position:left;margin-left:84.0pt;text-indent:-21.0pt;}ol{margin-bottom:0cm;}ul{margin-bottom:0cm;}-->

  i.     请记录以下两个口令和ID:

1.   SYS/Change_on_install

2.   system/manager

 

 

 

步骤6

<!-- /* Font Definitions */ @font-face{font-family:Wingdings;panose-1:5 0 0 0 0 0 0 0 0 0;mso-font-charset:2;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:0 268435456 0 0 -2147483648 0;}@font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 680460288 22 0 262145 0;}@font-face{font-family:"Cambria Math";panose-1:2 4 5 3 5 4 6 3 2 4;mso-font-charset:1;mso-generic-font-family:roman;mso-font-format:other;mso-font-pitch:variable;mso-font-signature:0 0 0 0 0 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 680460288 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-unhide:no;mso-style-qformat:yes;mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman","serif";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;}.MsoChpDefault{mso-style-type:export-only;mso-default-props:yes;font-size:10.0pt;mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt;mso-ascii-font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-hansi-font-family:"Times New Roman";mso-font-kerning:0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;}-->在“控制面板”à“管理工具”à“服务”中,启动“OracleOraHome90ManagementServer”服务。(名字中的“OraHome90”子串由安装时输入的主路径名决定,所以也许会有不同)

<!-- /* Font Definitions */ @font-face{font-family:Wingdings;panose-1:5 0 0 0 0 0 0 0 0 0;mso-font-charset:2;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:0 268435456 0 0 -2147483648 0;}@font-face{font-family:宋体;panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-alt:SimSun;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 680460288 22 0 262145 0;}@font-face{font-family:"Cambria Math";panose-1:2 4 5 3 5 4 6 3 2 4;mso-font-charset:1;mso-generic-font-family:roman;mso-font-format:other;mso-font-pitch:variable;mso-font-signature:0 0 0 0 0 0;}@font-face{font-family:"/@宋体";panose-1:2 1 6 0 3 1 1 1 1 1;mso-font-charset:134;mso-generic-font-family:auto;mso-font-pitch:variable;mso-font-signature:3 680460288 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal{mso-style-unhide:no;mso-style-qformat:yes;mso-style-parent:"";margin:0cm;margin-bottom:.0001pt;text-align:justify;text-justify:inter-ideograph;mso-pagination:none;font-size:10.5pt;mso-bidi-font-size:12.0pt;font-family:"Times New Roman","serif";mso-fareast-font-family:宋体;mso-font-kerning:1.0pt;}.MsoChpDefault{mso-style-type:export-only;mso-default-props:yes;font-size:10.0pt;mso-ansi-font-size:10.0pt;mso-bidi-font-size:10.0pt;mso-ascii-font-family:"Times New Roman";mso-fareast-font-family:宋体;mso-hansi-font-family:"Times New Roman";mso-font-kerning:0pt;} /* Page Definitions */ @page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}@page Section1{size:612.0pt 792.0pt;margin:72.0pt 90.0pt 72.0pt 90.0pt;mso-header-margin:36.0pt;mso-footer-margin:36.0pt;mso-paper-source:0;}div.Section1{page:Section1;} /* List Definitions */ @list l0{mso-list-id:817110624;mso-list-type:hybrid;mso-list-template-ids:331890388 838512750 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}@list l0:level1{mso-level-number-format:japanese-counting;mso-level-text:%1、;mso-level-tab-stop:21.0pt;mso-level-number-position:left;margin-left:21.0pt;text-indent:-21.0pt;}@list l0:level2{mso-level-number-format:alpha-lower;mso-level-text:"%2/)";mso-level-tab-stop:42.0pt;mso-level-number-position:left;margin-left:42.0pt;text-indent:-21.0pt;}@list l0:level3{mso-level-number-format:roman-lower;mso-level-tab-stop:42.3pt;mso-level-number-position:right;margin-left:42.3pt;text-indent:-21.0pt;}@list l0:level4{mso-level-tab-stop:84.0pt;mso-level-number-position:left;margin-left:84.0pt;text-indent:-21.0pt;}ol{margin-bottom:0cm;}ul{margin-bottom:0cm;}-->

一、 新建用户

a)  启动“Enterprise Manager Consoleà“独立启动”à点击“OEMREP”数据库,第一次登陆使用用户:sysman,口令:oem_temp

b)  在“OEMREP”数据库中à“安全性”à“用户”à右键创建;

c)  Oracle对用户权限分配非常详细,下面以创建一个拥有备份及恢复数据权限的用户为例演示权限分配:

   i.      新建用户后à选中该用户à选中“角色”选项卡à赋予其“EXP_FULL_DATABASE”、“IMP_FULL_DATABASE”、[DBA”角色]à“管理选项”、“默认值”打勾

  ii.     在操作系统(win2000,winXP)中添加一个同名用户

iii.      “控制面板”à“管理工具”à“本地安全策略”à“本地策略”à“用户权利指派”à双击“作为批处理作业登录”à“添加”à选择该用户加入。

  iv.     重新打开“Enterprise Manager Consoleà以用户:sysman,口令:OEM_TEMP,登陆到“Oracle Managerment Server”(第一次登陆会要求输入服务器地址:127.0.0.1;以及更换口令)à菜单栏“配置”à“首选身份证明”页签à选中节点à添加该用户。

二、 Oracle中使用SQl,使用“Application DevelopmentàSQLPlus

三、 备份及恢复备份

a)  备份

   i.      键入命林“Expà按提示键入用户名、数据库、口令

  ii.     可在键入用户时输入“用户名@数据库”例如“system @jiangbo”,或“用户名/口令@数据库”例如“system/manager @jiangbo

iii.      按提示输入缓冲区大小(输大点)

  iv.     默认备份输出在Oracle/ora90/bin目录下

b)  恢复备份

   i.      注意应建一个用户,同名于导出备份的用户。否则在A用户导出数据,再使用B用户导入时可能会报错。默认导出的备份会以用户名+其他后缀命名,导出的日志中也可查到导出的用户

  ii.     cmd中键入IMP命令à按提示键入用户名、数据库、口令

iii.      以下同于备份操作。

四、 Oracle的数据库包含若干表空间(如System表空间、User表空间、Normal表空间等等),数据表可选择保存于不同表空间中。

五、 除了下SQL,也可通过“Enterprise Manager Console”中的数据库à右击à“查找数据对象”来查找表、函数等等。

在程序中可使用普通Ado控件来操作Oracle数据库。但调用存储过程则无法象SQL Server一样下SQL,需使用TDSADOStoredProc控件。