ORACLE常用技巧
1
select
COMPCODE,
2 COMPNAME,
3 LEVEL ,
4 TOTAL,
5 F_CAC_VAL( ' 1 ' || SYS_CONNECT_BY_PATH(TOTAL, ' * ' )) V,
6 ' 1 ' || SYS_CONNECT_BY_PATH(TOTAL, ' * ' ) P
7 from T_M_COMPONENT T
8 where COMPTYPE = 0
9 start with bompid = 117808
2 COMPNAME,
3 LEVEL ,
4 TOTAL,
5 F_CAC_VAL( ' 1 ' || SYS_CONNECT_BY_PATH(TOTAL, ' * ' )) V,
6 ' 1 ' || SYS_CONNECT_BY_PATH(TOTAL, ' * ' ) P
7 from T_M_COMPONENT T
8 where COMPTYPE = 0
9 start with bompid = 117808
10 connect by NOCYCLE prior bomid = bompid 一. 数据闪回功能
在ORACLE使用过程中经常会误删除行记录,而且COMMIT了,怎样找回误删的数据是个麻烦事.
1
SQL
>
select
dbms_flashback.get_system_change_number fscn
from
dual;
2
3 FSCN
4 -- --------
5 6603893
2
3 FSCN
4 -- --------
5 6603893
2.根据闪回点追寻数据
SQL
>
select
*
from
t_sys_role
as
of
scn
6589999
;
看看如果误删的数据存在这里,即可根据6589999这个点进行回闪数据
3.恢复数据
SQL
>
insert
into
t_sys_role
select * from t_sys_role as of scn 6589999
where roleid not in ( select roleid from t_sys_role)
select * from t_sys_role as of scn 6589999
where roleid not in ( select roleid from t_sys_role)
4.另外一种方法
select * from 表名 as of timestamp sysdate-1/6
```````````````这里是4小时之前的数据
如果表被drop了,则使用:
flashback table 表名 to before drop;
二.ORACLE创建用户指令
create
temporary
tablespace guhan_temp tempfile
'
/home/db_data/mis/temp.dbf
'
size 512m autoextend
on
next
512m;
create tablespace mis_data datafile ' /home/db_data/mis/mis_data.dbf ' size 1024m autoextend on next 2048m;
create user mis identified by mis_guhan default tablespace mis_data temporary tablespace guhan_temp;
grant connect,resource,dba to mis;
create tablespace mis_data datafile ' /home/db_data/mis/mis_data.dbf ' size 1024m autoextend on next 2048m;
create user mis identified by mis_guhan default tablespace mis_data temporary tablespace guhan_temp;
grant connect,resource,dba to mis;
三.ORACLE启动指令
1
# su
-
oracle
//
关键
2 # sqlplus / nolog
3 SQL > startup mount
4 SQL > ALTER DATABASE OPEN
5 SQL > STARTUP
6 $ lsnrctl start
7 $ emctl start dbconsole
2 # sqlplus / nolog
3 SQL > startup mount
4 SQL > ALTER DATABASE OPEN
5 SQL > STARTUP
6 $ lsnrctl start
7 $ emctl start dbconsole
四.ORACLE数据库的字符集转换
ALTER
DATABASE
character
set
INTERNAL_USE ZHS16GBK;
五.更新记录不存在,则插入
1
BEGIN
2 UPDATE T_TABLE SET COL = ' VALUE ' WHERE 1 = 2 ;
3 IF SQL % ROWCOUNT < 1 THEN
4 INSERT INTO T_TALBE(COL) VALUES ( ' VALUE ' );
5 END IF ;
6 END ;
2 UPDATE T_TABLE SET COL = ' VALUE ' WHERE 1 = 2 ;
3 IF SQL % ROWCOUNT < 1 THEN
4 INSERT INTO T_TALBE(COL) VALUES ( ' VALUE ' );
5 END IF ;
6 END ;
六. 在Redhat5.7-x64上安装11gR1遇到的问题
第一次安装老有很多包找不到,装到复制文件78%左右,出现不能编译脚本的错误,手动安装gcc也失败,后来重装系统,一定要安装老的开发工具,否则找不着gcc,不能正常安装,碰上x-server的情况,可用root执行xhost + 命令
安装后面出现了一个错误,dbms脚本错误,结果实例没有配置完成,导致数据库不能使用
sqlplus /nolog 可以登录并且启动实例,但是sqlplus 帐号/密码@实例不能登录,tnsping是正常的,怀疑tns的oracle_sid和实例的sid可能不一样发现原因:
$ORACLE_HOME/dbs/init.ora 里缺少intance_name
可能是上面的错误导致init.ora的参数未初始化完毕
#su oracle
$sqlplus /nolog
$conn / as sysdba
$shutdown abort
$startup
成功启动,再连接 OK!
七.树形卷叠计算
七. linux常用的简单命
七. linux常用的简单命
令
八: 设置权限:chmod 777 db_data
八:禁用exp导出权限
sys权限进入oracle,执行
1
select
COMPCODE,
2
COMPNAME,
3 LEVEL ,
4 TOTAL,
5 F_CAC_VAL( ' 1 ' || SYS_CONNECT_BY_PATH(TOTAL, ' * ' )) V,
6 ' 1 ' || SYS_CONNECT_BY_PATH(TOTAL, ' * ' ) P
7 from T_M_COMPONENT T
8 where COMPTYPE = 0
9 start with bompid = 117808
10 connect by NOCYCLE prior bomid = bompid
目录授权(修改目录所有者): chown -R oracle:dba db_data/ 3 LEVEL ,
4 TOTAL,
5 F_CAC_VAL( ' 1 ' || SYS_CONNECT_BY_PATH(TOTAL, ' * ' )) V,
6 ' 1 ' || SYS_CONNECT_BY_PATH(TOTAL, ' * ' ) P
7 from T_M_COMPONENT T
8 where COMPTYPE = 0
9 start with bompid = 117808
10 connect by NOCYCLE prior bomid = bompid
八: 设置权限:chmod 777 db_data
八:禁用exp导出权限
sys权限进入oracle,执行
revoke select on sys.exu8usru from public;