Oracle的一些基础用法

本文深入探讨Oracle数据库的多项核心功能,包括其高可用性、安全性、数据类型、表空间管理、用户创建与权限分配、序列使用、同义词概念、索引类型、分区表优势、PL/SQL编程基础及存储过程实现。通过详细解析,帮助读者全面理解Oracle数据库的架构与操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Oracle的一些用途:

优点:
      1.可用性、支持多用户、大并发、大事务量、可扩展、可移植、跨平台、安全性。

      2.全局数据库名:数据库实例、表空间、数据文件、控制文件、日志文件、模式和
         
         模式对象
      
      3.启动服务:OracleOraDb11g_home1TNSListener、OracleServiceORCL

   	  4.数据类型:varchar2(可变字符串)、number(p,s)、date、timestamp、CLOB

         BLOB、
      
      5.伪列:rowid、rownum

	  6.表空间:
	    
	    create  tablespace  tablespace01 dataFile  'D:/java/'  size 10M  autoextends no;
		//删除表空间
		drop  tablespace   表空间名
		
		//表空间分类:
		永久性表空间、临时表空间、撤销表空间
		
		//修改表空间、向表空间添加数据
		alter  tablespace  表空间名  add  dataFile  '文件路径' size  20m  autoextends  on;
		
		//更改数据文件大小
		Alter  database  DATAFile  '路径' RESIZE  80M;
	   
	   7.创建用户:
	       
	       create  user   用户名  identified by  密码 [表空间、临时表空间]
	       
      		[DEFAULT   TABLESPACE   tablespace]
			[TEMPORARY   TABLESPACE   tablespace]
			[QUOTA Integer [K|M] | UNLIMITED}] ON tablespace;
			[QUOTA Integer [K|M] | UNLIMITED}] ON tablespace];
			[PASSWORD EXPIRE] 
		
	   8.给用户赋予权限:
	         
	         grant   resource,connect  to  用户名
	         表权限:grant    select  on  scott.emp  to  用户名
	   
	   9.创建序列:
           
           create    sequence   序列名(sequence_name)   start  with  2005  increment  by  1
           (每次递增1)  maxValue  3000   nocycle  cache 30(缓存数30)
		
	  10.访问序列名:select  序列名.currval  from  dual。

	  11.同义词:访问其它用户的表,设置同义词,方便访问(类似表别名)
		
	  12.索引:唯一索引,反向键索引,位图索引,B树索引。
          
          1.创建B树索引:create   index  索引名  on  emp(empno)
          2.位图索引:   create  bitmap  索引名  on  emp(salary)
          3.反向键索引:create  index  索引名  on  emp(job)  reverse
     	  4.基于函数的索引:create  index  索引名 on  emp(lower(job))
      	  5.唯一索引:create  unique index  索引名  on  emp(empno)
     
      13.分区表:(范围分区和列表分区):可以提高对数据的检索速度

	  14.pl/sql编程:
             结构:declare  声明  begin  执行部分   [Exception 异常处理]  end;

	  15.类型:%type引用数据库表中某个字段的类型, %rowtype引用数据表中整行的类型
		
	  16.条件判断语句:if  条件  then  null  else                
       
17.for  变量   in   上限..下限   loop
             要执行的代码块;
             end  loop;
      
18.游标:相当于一个集合,存储整张表内容:声明游标、代开游标、提取游标、关闭游标
           
           游标第一种写法:
			
	   declare
                name    emp.ename%type;
                sal     emp.sal %type
             	--声明游标
             	cursor    emp_cursor   is  select  ename,sal  from  emp;
				
		begin
       	    --打开游标          
             open   emp_cursor;
            --提取游标
            fetch  emp_cursor  into  name,sal;
			--异常
			exit   when   emp_cursor%notfound;
			--输出
			dbms_output.put_line('第'||emp_cursor||'位员工:'||name||'的
			工资为:'||sal);
			close  emp_cursor;
		end;
				
 第二种写法:
     declare
          cursor   emp_cursor  is  select  ename,sal  from  emp;
     begin
          for   emp_record   in  emp_cursor  loop
          --输出
            dbms_output.putline('第'||emp_cursor%rowcount||'位员工:'||emp_record.ename||
            '的工资位:'||emp_cursor.sal);
            end  loop;
       end;

	19:存储过程:oracle中的一段编码程序,可执行的,相当于java中的方法
		语法结构:
          
             create   or  replace   procedure  存储过程名(
						变量(例如数据库中的字段名)
						eno    number,
						name   varchar2
             )
             is
             begin
                 insert   into  emp(empno,ename)values(eno,ename)
             end;
             --调用存储过程
             begin
                存储过程名('值1','值2')
             end;
             --进行新一轮查询
             select  *  from   emp;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值