oracle常用基本知识

oracle通过表名和字段名查询字段类型

select data_type from user_tab_columns where table_name ='表名' and column_name ='字段名' 

数据库建立dblink

-- Drop existing database link 
drop database link DFH;
-- Create database link 
create database link DFH
  connect to LZWG
  using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.103)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)';

------------------
Oracle中如何使用DBLink
我们有两个数据库a,b,分别有两个用户A和B,用户A希望访问B的所有表.

第一步:在用户B所在的数据库中新建一个用户c,然后将B的所有表的查询权限赋给c.

set pages 999;
set heading off;
spool run_grant.sql
select 'grant select on '||owner||'.'||object_name||' to c;'
from dba_objects
where object_type='TABLE' and owner='B';
spool off;
@ run_grant

第二步:用户A新建一个dblink_b

DROP  PUBLIC  DATABASE  LINK dblink_b

 create database link dblink_c
  connect to c identified by c的密码
  using '(DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 主机ip)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = 实例名)
    )
  )';

然后用下面的语句访问用户

 select * from B.table@dblink_b 

oracle表解锁语句

select object_name,machine,s.sid,s.serial#
from v$locked_object l,dba_objects o ,v$session s
where l.object_id = o.object_id and l.session_id=s.sid;

alter system kill session '58,1053'; 
alter system kill session '19,692'; 

你可能感兴趣的:(数据库)