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;
  • 相关阅读:
    系统维护相关问题
    Python环境维护
    哈希表解决字符串问题
    论文笔记二:《A Tutoral on Spectral Clustering》
    论文笔记之哈希学习比较--《Supervised Hashing with Kernels》《Towards Optimal Binary Code Learning via Ordinal Embedding》《Top Rank Supervised Binary Coding for Visual Search》
    Java中String、StringBuffer、StringBuilder的比较与源 代码分析
    浙大pat1040 Longest Symmetric String(25 分)
    浙大pat1039 Course List for Student(25 分)
    浙大pat---1036 Boys vs Girls (25)
    百炼oj-4151:电影节
  • 原文地址:https://www.cnblogs.com/zhouyalei/p/2563637.html
Copyright © 2011-2022 走看看