FW:Oracle之七零八落

SELECT INSTR(‘AAAC‘, ‘AAC‘) FROM DUAL; --2
SELECT SUBSTR(‘ABC‘, 2, 1) FROM DUAL; --B
SELECT ‘AA‘ || CHR(ASCII(‘B‘) + 1) FROM DUAL; -- AAC

SELECT * FROM V$VERSION;
SELECT * FROM PRODUCT_COMPONENT_VERSION;

-- 查询表空间
SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
       D.TOT_GROOTTE_MB "表空间大小(M)",
       D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
       TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,
                     2),
               ‘990.99‘) "使用比",
       F.TOTAL_BYTES "空闲空间(M)",
       F.MAX_BYTES "最大块(M)"
  FROM (SELECT TABLESPACE_NAME,
               ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,
               ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES
          FROM SYS.DBA_FREE_SPACE
         GROUP BY TABLESPACE_NAME) F,
       (SELECT DD.TABLESPACE_NAME,
               ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
          FROM SYS.DBA_DATA_FILES DD
         GROUP BY DD.TABLESPACE_NAME) D
 WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME
 ORDER BY 4 DESC;

当误删除某些表时,可以通过命令恢复回来:
flashback table tablename to befor drop;

查看是否开启了闪回功能:
select flashback_on from v$database;

如果确定某些表确实可以删除,可以使用下面的语句,就不会出现BIN$开头的表了
drop table table_name purge;

删除Bin开头的表,即已经drop但存在于回收站中的表:
查询所有此类表SQL> select * from recyclebin where type=‘TABLE‘;
用来删除回收站中所有的表SQL> PURGE RECYCLEBIN;
用来删除指定的表SQL> PURGE TABLE TABLE_NAME;
可以在的Drop表时不产生Bin型表SQL> DROP TABLE "TableName" purge;

-- 查询数据库被锁住的进程
SELECT A.SID, B.OWNER, OBJECT_NAME, OBJECT_TYPE
  FROM V$LOCK A, ALL_OBJECTS B
 WHERE TYPE = ‘TM‘
   AND A.ID1 = B.OBJECT_ID;

SELECT SID, SERIAL# FROM V$SESSION WHERE SID = &SID;

ALTER SYSTEM KILL SESSION ‘SID, SERIAL#’;

SELECT SID, SERIAL#
  FROM V$SESSION
 WHERE SID IN (SELECT A.SID
                 FROM V$LOCK A, ALL_OBJECTS B
                WHERE TYPE = ‘TM‘
                  AND A.ID1 = B.OBJECT_ID);

-- 查询/删除重复记录
DELETE FROM EMP E
 WHERE E.ROWID > (SELECT MIN(X.ROWID) FROM EMP X WHERE X.EMP_NO = E.EMP_NO);

SELECT *
  FROM COM_ITEM_CODE E
 WHERE E.ROWID >
       (SELECT MIN(X.ROWID) FROM COM_ITEM_CODE X WHERE X.BILL_NO = E.BILL_NO);
-- 反向递归
SELECT H.HR_DEPT_CODE, H.ERP_DEPT_NAME, H.ERP_DEPT_CODE, H.ERP_DEPT_NAME
  FROM (SELECT *
          FROM AOL_SYS_ORGANIZATION
         START WITH ORG_NO = ‘00164‘
        CONNECT BY PARENT_ORG_ID = PRIOR LINE_ID) O,
       AOL_COM_HRTOERP H
 WHERE O.ORG_NO = H.HR_DEPT_CODE;
-- 1、查看表所占空间
SELECT TABLESPACE_NAME,
       TO_CHAR(SUM(BYTES) / (1024 * 1024), ‘999G999D999‘) CNT_MB
  FROM DBA_EXTENTS
 WHERE OWNER = ‘&OWNER‘
   AND SEGMENT_NAME = ‘&TABLE_NAME‘
   AND SEGMENT_TYPE LIKE ‘TABLE%‘ * /
 GROUP BY TABLESPACE_NAME;

--有两种含义的表大小。--一种是分配给一个表的物理空间数量,而不管空间是否被使用。可以这样查询获得字节数:

SELECT SEGMENT_NAME, BYTES FROM USER_SEGMENTS WHERE SEGMENT_TYPE = ‘TABLE‘;

SELECT SEGMENT_NAME, SUM(BYTES) / 1024 / 1024
  FROM USER_EXTENTS
 GROUP BY SEGMENT_NAME;

-- 另一种表实际使用的空间。这样查询:

ANALYZE TABLE ABCDEF COMPUTE STATISTICS;
SELECT NUM_ROWS * AVG_ROW_LEN FROM USER_TABLES WHERE TABLE_NAME = ‘ABCDEF‘;

SELECT NUM_ROWS, TABLE_NAME FROM USER_TABLES;
-- 存储过程的闪回
SQL> set pagesize 0
SQL> column text format a4000
SQL> spool C:\7.text
Started spooling to C:\7.text
SQL> SELECT text
       FROM DBA_source AS OF TIMESTAMP TO_TIMESTAMP(‘2009-12-25 10:07:00‘, ‘YYYY-MM-DD HH24:MI:SS‘)
      WHERE OWNER = ‘用户名‘
        AND NAME = ‘存储过程名’
       ORDER BY LINE
     ;
SQL> spool off;
-- 修改DBLINK的global_name
update global_name set global_name=‘oradb‘; 
时间: 2024-11-05 03:39:43

FW:Oracle之七零八落的相关文章

FW:Oracle之时间操作(待整理)

TO_DATE格式(以时间:2007-11-02 13:45:25为例) Year: yy two digits 两位年 显示值:07 yyy three digits 三位年 显示值:007 yyyy four digits 四位年 显示值:2007 Month: mm number 两位月 显示值:11 mon abbreviated 字符集表示 显示值:11月,若是英文版,显示nov month spelled out 字符集表示 显示值:11月,若是英文版,显示november Day:

FW:Oracle之job

-- 数据字典 select * from dba_jobs; select * FROM all_jobs; select * FROM user_jobs; select * FROM dba_jobs_running; job_queue_process 表示oracle能够并发的job的数量,可以通过语句 show parameter job_queue_process;alter system set job_queue_processes=39 scope=spfile;//最大值不

FW:Oracle之PL/SQL学习笔记

看到一个关于Oracle系列文章,基本集中在一些基础知识的汇总. 比较适合新员工培训和知识汇总回顾.记录之前不了解或者不确定的知识 http://my.oschina.net/KingPan/blog?catalog=504011 1.得到序列的下一个值或当前值 select your_sequence.nextval from dual;--获得序列your_sequence的下一个值 select your_sequence.currval from dual;--获得序列your_sequ

FW:Oracle之sqlldr

-- Create table create table TSQ ( ID NUMBER, NAME VARCHAR2(2) ) -- tsq.ctl load data append into table tsq fields terminated by ',' TRAILING NULLCOLS ( ID , NAME ) windows sqlldr tmall/[email protected] control=D:\tsq\tsq.ctl data=D:\tsq\tsq.csv rea

FW:Oracle之PL/SQL 时间转换

CREATE OR REPLACE FUNCTION TTD(V_DATE NUMBER) RETURN VARCHAR2 IS RESULT VARCHAR(100); BEGIN SELECT TO_CHAR(TO_DATE('1970-1-1 00:00:00', 'yyyy-mm-dd hh24:mi:ss') + V_DATE / 3600 / 24 + 8 / 24, 'yyyy-mm-dd hh24:mi') INTO RESULT FROM DUAL; RETURN(RESULT

风清杨之Oracle的安装与说明

1.Oracle官网与下载地址 Oracle中文官网:http://www.oracle.com/cn/index.html Oracle中文官网下载:http://www.oracle.com/technetwork/cn/database/enterprise-edition/downloads/index.html Oracle英文官网:http://www.oracle.com/index.html Oracle英文官网下载:http://www.oracle.com/technetwo

SQLSERVER中WITH AS递归来实现ORACLE的INSTR函数以及固定分隔符字符串截取

分享个sqlserver的sql给大家,能用with as的递归实现oracle中的instr函数,并且能将分隔符的字符串解析,例如: 字符串为:'O3O,30,4834,348934,AA,09WOFJOWE,FW' 解析完成: 1)实现oracle的instr函数,sql如下: WITH CTE1 AS ( SELECT '1' AS ID , 'O3O,30,4834,348934,AA,09WOFJOWE,FW' AS STR ), CTE2 AS ( SELECT 1 AS LEVEL

Java中使用Oracle的客户端 load data和sqlldr命令执行数据导入到数据库中

Windows环境下测试代码: import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; public class testTimer { /** * @param

oracle 10g 生成awr报告过程

SQL> exitDisconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP and Data Mining options[[email protected]_maridb ~]$ sqlplus / as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on M