首页 > 代码库 > Oracle使用小结

Oracle使用小结

误删数据库表解决方法

SQL> alter table test1 enable row movement;//在闪回前必须 启动行移动功能 否则会报错误: ORA-08189: 因为未启用行移动功能, 不能闪回表

SQL> FLASHBACK TABLE test1 TO TIMESTAMP to_timestamp(‘2013-06-03 15:35:00‘,‘yyyy-mm-dd hh24:mi:ss‘);//注意:恢复时间点必须是在删除数据之前 这里是2013-06-03 15:35:57 之前就可以

 

INSERT INTO BOOKUSER SELECT * FROM BOOKUSER AS OF TIMESTAMP SYSDATE-100/1440 100分钟之前的

闪回操作
FLASHBACK TABLE T_SCM_COST_UNIT TO BEFORE DROP;

 

 

 

使用UNION ALL把两个查询结果放在一张表中,‘入库‘ as mark,新列,其中数据都是‘入库’

(SELECT   T0.ID MATERIAL_ID,T0.MATERIAL_NO,T0.NAME MATERIAL_NAME,T0.SPECIFICATION,T1.PLAN_PRICE PLAN_PRICE_IN,T1.AMOUNT AMOUNT_IN, ‘入库‘ as mark

FROM T_SCM_STORE_IN_DETAIL T1     LEFT JOIN T_EMS_MATERIAL T0     ON T0.ID= T1.MATERIAL_ID

GROUP BY T0.ID,T0.MATERIAL_NO,T0.NAME,T0.SPECIFICATION,T1.PLAN_PRICE,T1.AMOUNT,‘入库‘)
UNION ALL
(SELECT T0.ID MATERIAL_ID,T0.MATERIAL_NO,T0.NAME MATERIAL_NAME,T0.SPECIFICATION,T2.PLAN_PRICE PLAN_PRICE_OUT,T2.AMOUNT AMOUNT_OUT,‘出库‘ as mark

FROM  T_SCM_STORE_OUT_DETAIL T2   LEFT JOIN T_EMS_MATERIAL T0 
ON T0.ID= T2.MATERIAL_ID

GROUP BY T0.ID,T0.MATERIAL_NO,T0.NAME,T0.SPECIFICATION,T2.PLAN_PRICE,T2.AMOUNT,‘出库‘)

Oracle使用小结