• oracle 一些小资料


    用户解锁

    alter user hzdz account unlock;

    建立序列

    create sequence ZHJX 
    minvalue 1
    maxvalue 999999999999999999999999999
    start with 741
    increment by 1
    cache 20;

    游标

    --连接中间用户建立中间表

    --连接用户建立存储过程

    --建立存储

    CREATE OR REPLACE Procedure pro_getjsxx as

    cursor get_jsxx is select * from jsxxb where zgh is not null  ; 

    jsxx_record  get_jsxx%rowtype;

    strXm varchar2(20); --姓名

    strXbmc varchar2(20); --性别

    strCsrq varchar2(20); --出生日期

    strJg varchar2(50);   --籍贯

    strMz varchar2(50);   --民族

    strDwmc varchar2(50); --单位名称 

    strKsmc varchar2(50); --科室名称 

    strZjh varchar2(50);  --证件号

    strJzglx varchar2(20); --教职工类别

    strZc varchar2(20);  --职称

    strZw varchar2(50);  --职务

    strXl varchar2(50);  --学历

    strXw varchar2(50);  --学位

    strCjgzsj varchar2(50); ---参加工作时间

    countMd number;       

    begin

      ---操作教师信息表

       begin

       --打开游标

       open get_jsxx;

       --循环

       loop

       fetch get_jsxx into jsxx_record;

       exit when get_jsxx%notfound;

         --判断职工号在表中是否存在

           begin

           select count(*) into countMd  from jsxxb_bak where zgh=jsxx_record.zgh;

           exception

           when others then

               countMd:=0;

           end;

         --如果存在执行以下过程

         if countMd>0 then

             --获取字段信息

             begin

                select xm,xb,csrq,jg,mz,bm,ks,sfzh,jzglb,zc,zw,xl,xw,cjgzsj 

                into strXm,strXbmc,strCsrq,strJg,strMz,strDwmc,strKsmc,strZjh,strJzglx,

                strZc,strZw,strXl,strXw,strCjgzsj from jsxxb_bak where zgh=jsxx_record.zgh ;

             exception

               when others then

               goto pro_getjsxxend;

             end;

          

             --更新教师信息表

             update jsxxb set xm=strXm,

             xb=strXbmc,

             csrq=strCsrq,

             jg=strJg,

             mz=strMz,

             bm=strDwmc,

             ks=strKsmc,

             sfzh=strZjh,

             JZGLB=strJzglx,

             zc=strZc,

             zw=strZw,

             xl=strXl,

             xw=strXw,

             Cjgzsj=strCjgzsj

             where zgh=jsxx_record.zgh;

          end if ;

         end loop;

        close get_jsxx;

        

       exception

         when others then

         goto pro_getjsxxend;

       end;

       commit;

     <<pro_getjsxxend>>

     null;

    end;

    建立oraclejob 定时执行存储过程 

    alter system set job_queue_processes = 8;

    /

    variable job1 number;

    begin

    dbms_job.submit(:job1,'pro_getjsxx;',sysdate,'sysdate+1/2');

    commit;

    end;

    /

    begin

    dbms_job.run(:job1);

    commit;

    end;

    /


    oracle 

      select t2.username,t2.sid,t2.serial#,t2.logon_time 
    from v$locked_object t1,v$session t2 
    where t1.session_id=t2.sid order by t2.logon_time;

    --把锁给KILL

    --alter system kill session 'sid,serial#';
    alter system kill session '146,21177';

    恢复表数据

     alter table xsjbxxb enable row movement; 

     flashback table xsjbxxb to timestamp to_timestamp('2010-10-08   14:30:00','yyyy-mm-dd hh24:mi:ss');

     commit;

     

    创建临时表空间
    create temporary tablespace test_temp
    tempfile 'E:\oracle\product\10.2.0\oradata\testserver\test_temp01.dbf'
    size 32m
    autoextend on
    next 32m maxsize 2048m
    extent management local;


    创建数据表空间
    create tablespace test_data
    logging
    datafile 'E:\oracle\product\10.2.0\oradata\testserver\test_data01.dbf'
    size 32m
    autoextend on
    next 32m maxsize 2048m
    extent management local;


    创建用户并指定表空间
    create user testserver_user identified by testserver_user
    default tablespace test_data
    temporary tablespace test_temp;


    给用户授予权限
    grant connect,resource to testserver_user; (db2:指定所有权限)
    导入导出命令:
    Oracle数据导入导出imp/exp就相当于oracle数据还原与备份。exp命令可以把数据从远程数据库服务器导出到本地的dmp文件, imp命令可以把dmp文件从本地导入到远处的数据库服务器中。 利用这个功能可以构建两个相同的数据库,一个用来测试,一个用来正式使用。

    执行环境:可以在SQLPLUS.EXE或者DOS(命令行)中执行,
    DOS中可以执行时由于 在oracle 8i 中 安装目录ora81BIN被设置为全局路径,
    该目录下有EXP.EXEIMP.EXE文件被用来执行导入导出。
    oraclejava编写,SQLPLUS.EXEEXP.EXEIMP.EXE这两个文件有可能是被包装后的类文件。
    SQLPLUS.EXE调用EXP.EXEIMP.EXE所包裹的类,完成导入导出功能。

    下面介绍的是导入导出的实例。
    数据导出:
    将数据库TEST完全导出,用户名system 密码manager 导出到D:daochu.dmp
       exp system/manager@TESTfile=d:daochu.dmp full=y
    将数据库中system用户与sys用户的表导出
       exp system/manager@TESTfile=d:daochu.dmp owner=(system,sys)
    将数据库中的表inner_notifynotify_staff_relat导出
        exp aichannel/aichannel@TESTDB2file= d:datanewsmgnt.dmp tables=(inner_notify,notify_staff_relat)
    将数据库中的表table1中的字段filed1"00"打头的数据导出
       exp system/manager@TESTfile=d:daochu.dmp tables=(table1) query=" where filed1 like '00%'"

    上面是常用的导出,对于压缩,既用winzipdmp文件可以很好的压缩。
    也可以在上面命令后面 加上 compress=y 来实现。
    数据的导入
    D:daochu.dmp 中的数据导入 TEST数据库中。
       imp system/manager@TESTfile=d:daochu.dmp
       imp aichannel/aichannel@HUSTfull=y file=d:datanewsmgnt.dmp ignore=y
       上面可能有点问题,因为有的表已经存在,然后它就报错,对该表就不进行导入。
       在后面加上 ignore=y 就可以了。
    d:daochu.dmp中的表table1 导入
    imp system/manager@TESTfile=d:daochu.dmp tables=(table1)

    基本上上面的导入导出够用了。不少情况要先是将表彻底删除,然后导入。

    注意:
    操作者要有足够的权限,权限不够它会提示。
    数据库时可以连上的。可以用tnsping TEST 来获得数据库TEST能否连上。
    附录一:
    给用户增加导入数据权限的操作
    第一,启动sql*puls
    第二,以system/manager登陆
    第三,create user 用户名 IDENTIFIED BY 密码 (如果已经创建过用户,这步可以省略)
    第四,GRANT CREATE USER,DROP USER,ALTER USER ,CREATE ANY VIEW ,
       DROP ANY VIEW,EXP_FULL_DATABASE,IMP_FULL_DATABASE,
          DBA,CONNECT,RESOURCE,CREATE SESSION TO 用户名字
    第五运行-cmd-进入dmp文件所在的目录,
          imp userid=system/manager full=y file=*.dmp
          或者 imp userid=system/manager full=y file=filename.dmp
    执行示例:
    F:WorkOracle_Databackup>imp userid=test/test full=y file=inner_notify.dmp
    屏幕显示
    Import: Release 8.1.7.0.0 - Production on 星期四 2月 16 16:50:05 2006
    (c) Copyright 2000 Oracle Corporation. All rights reserved.
    连接到: Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.0.0 - Production
    经由常规路径导出由EXPORT:V08.01.07创建的文件
    已经完成ZHS16GBK字符集和ZHS16GBK NCHAR 字符集中的导入
    导出服务器使用UTF8 NCHAR 字符集 (可能的ncharset转换)
    正在将AICHANNEL的对象导入到 AICHANNEL
    . . 正在导入表                  "INNER_NOTIFY"          4行被导入
    准备启用约束条件...
    成功终止导入,但出现警告。

    附录二:
    Oracle 不允许直接改变表的拥有者利用Export/Import可以达到这一目的.
    先建立import9.par,
    然后,使用时命令如下:imp parfile=/filepath/import9.par
    例 import9.par 内容如下:
            FROMUSER=TGPMS      
            TOUSER=TGPMS2     (注:把表的拥有者由FROMUSER改为TOUSERFROMUSERTOUSER的用户可以不同)          
            ROWS=Y
            INDEXES=Y
            GRANTS=Y
            CONSTRAINTS=Y
            BUFFER=409600
            file==/backup/ctgpc_20030623.dmp
            log==/backup/import_20030623.log

    排序 OW_NUMBER() OVER

    select xkkh,max(decode(wz,1,bjmc))||','||max(decode(wz,2,bjmc)) from 
    (select ROW_NUMBER() OVER (partition BY xkkh ORDER BY bjmc,zyfx) wz,xkkh,bjmc from jxrwb ) 
    group by xkkh

    Oracle sga_max_size参数修改过大启动不了的解决方案

         拷贝E:\oracle\product\10.2.0\admin\orcl\pfile文件夹中的配置文件init.ora.7152011202338到 

    E:\oracle\product\10.2.0\db_1\database”文件夹中。

       修改配置文件“init.ora.715201120233”的文件名为“initorcl.ora”。

    启动sqlplus,以sysdba的方式连接,设置oracle的启动选择配置文件路径。

     

    修改原有的配置文件的文件名“SPFILEORCL.ORA”成“SPFILEORCL.ORA1”,当然你也可以修改成其他的文件名。这样做的目的就是重新生成新的配置文件,不然你每次启动oracle 只能用指定配置文件的方式启动了。

    创建完配置文件,这样整个过程就完成了。

    Oracle  查看表空间利用率

    Select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024   "used MB",b.bytes/1024/1024 "free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"  
    from  
    (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name)   a,   
    (select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name)   b   
    where   a.tablespace_name=b.tablespace_name   
    order   by   ((a.bytes-b.bytes)/a.bytes)   desc  

  • 相关阅读:
    python:JSON的两种常用编解码方式实例解析
    Python中的map与reduce函数简介
    Python初学者的几个迷惑点
    Python Numpy中数据的常用的保存与读取方法
    python全栈 day03 操作系统 -- 摘要
    python全栈 day02 计算机原理 -- 硬件
    Python作业之购物商城
    Lesson one of python
    总体设计
    ASP.Net页面上用户控件相互调用的方法
  • 原文地址:https://www.cnblogs.com/zj1111184556/p/2349736.html
Copyright © 2020-2023  润新知