- Oracle相关学习笔记,在此稍作记录。
--创建表空间:
create tablespace onsale logging datafile 'e:\app\shang\oradata\orcl\onsale.dbf' size 1024m reuse extent management local segment space management auto;
--创建用户:
create user onsale identified by onsale default tablespace onsale temporary tablespace temp profile default;
--分配权限
grant connect,resource,dba to onsale;
--导入数据库文件
imp onsale/onsale@127.0.0.1/orcl file = d:\onsale.dmp full=y;
--查看数据库的所有表空间及空间大小
select t.tablespace_name, round(sum(bytes / (1024 * 1024)), 0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
--删除表空间onsale
drop tablespace rec1 including contents and datafiles cascade constraint;
--删除用户
drop user rec1;
--导出数据库文件(CMD命令行直接执行)
exp nhbi_work/nhbi@127.0.0.1:1521/orcl file=d:\nhbi_work.dmp owner=nhbi_work(用户名)
--简单的触发器
create or replace trigger TRI_CDR_REQUEST_COMMON
after insert on cdr_request_common
for each row
declare
begin
if :NEW.VISIT_TYPE='01' and :NEW.EQUIPMENT_TYPE_NAME in ('CT','MRI') then
insert into IBP_APPLICATION_O(regno,FLAG,ddate) VALUES(:NEW.REQUEST_NO,'0',sysdate);
end if;
if :NEW.VISIT_TYPE='03' and :NEW.EQUIPMENT_TYPE_NAME in ('CT','MRI') then
insert into IBP_APPLICATION_I(regno,FLAG,ddate) VALUES(:NEW.REQUEST_NO,'0',sysdate);
end if;
exception when others then dbms_output.put_line('触发失败');
end TRI_CDR_REQUEST_COMMON;
--查看oracle当前最大连接数
select value from v$parameter where name = 'processes';
--查看oracle当前连接数
select count(*) from v$process;
--修改oracle最大连接数
alter system set processes = 1000 scope = spfile;
--把以'.0'结尾的数据都截取掉
update base_dict set value_code=replace(value_code,'.0','') where range_code='HIP068';
--导出远程数据库中的某张表
C:\Users\Administrator>exp storage/123456@192.168.84.52:1521/orcl file=d:\base_t
ype_new.dmp tables=(base_type);
--将单张表数据导入到远程数据库、并指定导入的表名
C:\Users\Administrator>imp storage/123456@192.168.226.25:1521/ptai file=d:\base_
type_new.dmp tables=(base_type);
--oracle 11g空表导不出解决,然后将执行结果复制到另一个SQL窗口,并执行
select 'alter table '||table_name||' allocate extent;' from user_tables where num_rows=0;
--将一个用户下的数据导入到另一个用户下的表(表结构相同)
insert into empin.code_list (select * from nempi.code_list)
--查看表结构
desc table_name
--创建dblink
create public database link TYYY
connect to TYYY identified by tsd
using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =192.168.226.25)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ptai)
)
)';