zoukankan      html  css  js  c++  java
  • oracle 学习笔记

    1.oracle查询结果去除重复项

    SELECT DISTINCT * FROM TABLE_NAME

    2.合并查询结果

    select id,name from wg_person
    union
    select id,name from wg_superUsers
    从person表和superuser表中查询到的结果合并

    3.递归查询

    START WITH PID = :id CONNECT BY PRIOR ID = PID
    一般和union语句结合使用:
    START WITH PID = :id CONNECT BY PRIOR ID = PID 
    union
    select id from wg_depart where id=:id

    4.新安装的数据库,需要设置nls_lang环境变量

    变量名:NLS_LANG
    值:AMERICAN_AMERICA.ZHS16GBK
    

    5.oracle从dmp文件导入数据

    $imp 'aichannel/aichannel@192.168.1.36/orcl as dba' full=y file=路径\文件名.dmp ignore=y
    imp userid=username/password@192.168.1.36/orcl file=路径\文件名.dmp full=y

    6.oracle从dmp文件导出数据

    $exp username/password@orcl file=/path/db.sql log=/path/dblog.log owner=username
    

    7.pl/sql登录本地数据库失败问题

    可能原因:
    1.服务没启动,需要启动的有两个,OracleOraDb11g_home1TNSListener和OracleServiceOrcl
    2.把需要连接的数据库名字改为127.0.0.1/orcl
    

    8.oracle修改最大连接数,修改内存占用

    show parameter processes;
    show parameter sessions;
    alter system set processes=2000 scope=spfile;
    alter system set sessions=2200 scope=spfile;
    show parameter memory;
    alter system set memory_target=2688M scope=spfile;
    alter system set memory_max_target=2688M scope=spfile;
    

    9.oracle创建用户,并赋权限

    create user uname identified by pass
    grant dba,connect to zyl
    

    10.oracle导入dmp文件

    imp userName/password FILE=文件路径.dmp FULL=Y
    

    11.plsql提示:ORA-04098:trigger 'XXX.XXX' is invalid and failed re-falidation 错误

    应该是在表上建了触发器,在Triggers中找到并禁用就能插入数据了
    

    12.复杂update语句

    update person t set t.url=replace(url,'aaa','bbb') where t.url is not null  // 把url中的aaa替换成bbb
    

    13.批量插入查询到的数据到新表中

    insert into tb_workgroupdispatch a(id,departid,workgroupid)
    select rownum,w.jigouid,w.id from wggl_workgroup w where 条件;
    

    14.oracle生成uuid方法

    create or replace function fun_get_uuid
    return varchar
    is
    guid varchar (50);
    begin
    	guid := lower(rawtohex(sys_guid()));
    	return substr(guid,1,8)||'-'||substr(guid,9,4)||'-'||substr(guid,13,4)||'-'||substr(guid,17,4)||'-'||substr(guid,21,12);
    end fun_get_uuid;
    
    select fun_get_uuid from dual;
    update tb_person t set t.uuid=(select fun_get_uuid from dual) where t.id=1;--修改id=1的uuid

    15.循环更新表中所有记录

    create or replace procedure pro_set_person_uuid 
    is
      i number;
    begin
      i:=15000;
      --select count(1) into i from tb_person p where p.uuid is null;分批执行,如果太多,容易内存溢出
      while i>0 
      loop
          i:=i-1;
          update tb_person t set t.uuid=(select fun_get_uuid from dual) where t.uuid is null and rownum=1;
      end loop;
    end;
    
    begin
    	pro_set_person_uuid;
    end;
  • 相关阅读:
    大话领域驱动
    c#之循环效率
    编程思想之——"人是活的,程序是死的"
    C#之系统异常处理机制
    EF操作扩展之async
    C#提供APP接口之JSON差异
    EF操作MySql
    WCF 消息压缩性能问题及解决方法
    [NoSQL]-Elasticsearch 7.9
    [Linux]-Debian10基础使用
  • 原文地址:https://www.cnblogs.com/zhouyalei/p/2563637.html
Copyright © 2011-2022 走看看