jgugugiug 发表于 2018-9-11 08:08:18

Oracle常用操作

1.建立表空间和用户的步骤:  
用户
  
建立:create user 用户名 identified by "密码";
  
授权:grant create session to 用户名;
  
            grant create table to用户名;
  
            grant create tablespace to用户名;
  
            grant create view to用户名;
  

  

  
2.表空间
  
建立表空间(一般建N个存数据的表空间和一个索引空间):
  
create tablespace 表空间名
  
datafile ' 路径(要先建好路径)\***.dbf' size *M
  
tempfile ' 路径\***.dbf ' size *M
  
autoextend on--自动增长
  
--还有一些定义大小的命令,看需要
  
default storage(
  
initial 100K,
  
next 100k,
  
);
  

  
例子:创建表空间
  
create tablespace DEMOSPACE
  
datafile 'E:/oracle_tablespaces/DEMOSPACE_TBSPACE.dbf'
  
size 1500M
  
autoextend on next 5M maxsize 3000M;
  
删除表空间
  
drop tablespace DEMOSPACE including contents and datafiles
  

  
3.用户权限
  
授予用户使用表空间的权限:
  
alter user 用户名 quota unlimited on 表空间;
  
或 alter user 用户名 quota *M on 表空间;
  

  

  
4.--表空间
  
CREATE TABLESPACE sdt
  
DATAFILE 'F:\tablespace\demo' size 800M
  
         EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
  
--索引表空间
  
CREATE TABLESPACE sdt_Index
  
DATAFILE 'F:\tablespace\demo' size 512M
  
         EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
  

  
--2.建用户
  
create user demo identified by demo
  
default tablespace demo;
  

  
--3.赋权
  
grant connect,resource to demo;
  
grant create any sequence to demo;
  
grant create any table to demo;
  
grant delete any table to demo;
  
grant insert any table to demo;
  
grant select any table to demo;
  
grant unlimited tablespace to demo;
  
grant execute any procedure to demo;
  
grant update any table to demo;
  
grant create any view to demo;
  

  

  
5.--导入导出命令
  
ip导出方式: exp demo/demo@127.0.0.1:1521/orcl file=f:/f.dmp full=y
  
exp demo/demo@orcl file=f:/f.dmp full=y
  
imp demo/demo@orcl file=f:/f.dmp full=y ignore=y
  

  

  
6.--创建数据链
  
create database link ygbgtest_portaltest_link
  
   connect to portal identified by portal
  
   using '(DESCRIPTION =
  
   (ADDRESS_LIST =
  
       (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.104.102)(PORT = 1521))
  
   )
  
   (CONNECT_DATA =
  
       (SERVICE_NAME = orcl)
  
   )
  
   )';
  

  
select * from portal_information@ygbgtest_portaltest_link;
  

  

  

  
7.--创建临时表以获取远程表数据
  
Create global temporary table temp_ygbg_information on commit preserve rows
  
as select * from portal_information@ygbgtest_portaltest_link;
  
select count(1) from temp_ygbg_information t;
  

  
select * from temp_ygbg_information;
  

  

  
8.--从临时表中将数据插入到目的表中
  
insert into portal_information
  
(id,
  
   title,
  
   picture_url,
  
   status,
  
   author_id,
  
   author_name,
  
   create_time,
  
   modify_date,
  
   delete_date,
  
   view_num,
  
   order_flag,
  
   summary,
  
   type,
  
   promulgation_charge,
  
   information_source,
  
   sort_num,
  
   sub_title,
  
   is_slidenews)
  
select
  
   SEQ_PORTAL_INFORMATION.NEXTVAL,
  
   title,
  
   picture_url,
  
   status,
  
   author_id,
  
   author_name,
  
   create_time,
  
   modify_date,
  
   delete_date,
  
   view_num,
  
   order_flag,
  
   summary,
  
   type,
  
   promulgation_charge,
  
   information_source,
  
   sort_num,
  
   sub_title,
  
   is_slidenews from temp_ygbg_information t1 where t1.id=3338;


页: [1]
查看完整版本: Oracle常用操作