• oracle学习


    在平时的工作学习中,经常需要使用到oracle数据库,将平时用到的一些技巧记录在这里,以便以后随时可以翻阅。

    1.日期类型的比较

    插入日期时,经常会使用sysdate来插入数据,但sysdate插入的数据类型并不是date类型,当我们需要通过日期来查找数据时,要对数据进行处理再比较,

    to_date(to_char(sysdate,'YYYY-MM-DD'),'YYYY-MM-DD') > to_date('2016-10-01','YYYY-MM-DD');

    2.关联多张表形成一张大表进行查询

    需要从多张表中查询数据时,可以通过union拼接多张表一起查询

    (select * from A

    union all select * from B

    union all select * from C) M  将A,B,C三张表联查作为表M;

    3.存储过程卡住解决方法

    (1):查V$DB_OBJECT_CACHE

    SELECT * FROM V$DB_OBJECT_CACHE WHERE name='CUX_OE_ORDER_RPT_PKG' AND LOCKS!='0';

    注意:CUX_OE_ORDER_RPT_PKG 为存储过程的名称。

    发现 locks=2

    (2):按对象查出sid的值

    select /*+ rule*/  SID from V$ACCESS WHERE object='CUX_OE_ORDER_RPT_PKG';

    注意:CUX_OE_ORDER_RPT_PKG 为存储过程的名称。

    (3):查sid,serial#

    SELECT SID,SERIAL#,PADDR FROM V$SESSION WHERE SID='刚才查到的SID';

    (4):alter system kill session 'sid值,serial#值' immediate;

    4.查询表中重复数据

    select * from a group by XX having counts > 2 

     5.建一个表结构一样的临时表

    create table new_table as select * from old_table where 1 = 2; //最后的条件是为了不导入数据只导入结构

    6.为字段建索引

    create index 索引名 on 表名(字段名)

    7.导出dmp文件

    导出表结构(oracle服务端)

    1.使用plsql-tools-export 来导出

    2.使用cmd命令 

    exp 用户名/密码@数据库名 file=d:1116.dmp tables=(表1,表2,表3。。。) 

    *file后面的路径必须已经被创建,这个命令不会主动创建路径

    8.删除锁表

    delete * from table_locks

    9.查看用户对应的表空间

    select* fromuser_users

    10.察看表空间大小

    select* from dba_free_space a where a.tablespace_name = ‘’

    11.

    查看表空间使用情况

    select a.tablespace_name,total,free,total-free used from 

    (select tablespace_name,sum(bytes)/1024/1024 total from dba_data_files

      group by tablespace_name) a, 

    ( select tablespace_name,sum(bytes)/1024/1024 free from dba_free_space

      group by tablespace_name) b

    where a.tablespace_name=b.tablespace_name;

    12.查询锁表语句并删除锁

     select sess.sid, sess.serial#, lo.oracle_username, lo.os_user_name, ao.object_name, lo.locked_mode from v$locked_object lo, dba_objects ao, v$session sess where ao.object_id = lo.object_id and lo.session_id = sess.sid;

    select * from v$session t1, v$locked_object t2 where t1.sid = t2.SESSION_ID;
    alter system kill session '2616,10819'

    *当表被锁住时,在plsql中通过上述手段杀掉进程,会话的状态会从active变为killed,此时只是代表进程被kill了,但资源还没有释放,需要再过一段时间资源才会释放,彻底杀出进程的话,要从os一级去杀。

  • 相关阅读:
    appium+python自动化项目实战(一):引入nose和allure框架
    jmeter+WebDriver:启动浏览器进行web自动化
    jmeter强大的扩展插件!!
    jmeter+Fiddler:通过Fiddler抓包生成jmeter脚本
    appium+python自动化测试真机测试时报错“info: [debug] Error: Could not extract PIDs from ps output. PIDS: [], Procs: ["bad pid 'uiautomator'"]”
    Appium+python移动端自动化测试-python库及pycharm安装(二)
    Appium+python移动端自动化测试-环境搭建(一)
    安全测试之bWAPP环境搭建
    Battery Historian之App耗电量测试
    (15)Docker之用Nginx实现SpringBoot应用的负载均衡简单记录
  • 原文地址:https://www.cnblogs.com/ningenNY/p/5988548.html
Copyright © 2020-2023  润新知