GVKun编程网logo

Oracle 学习笔记十一 游标(oracle游标的使用详解)

1

本篇文章给大家谈谈Oracle学习笔记十一游标,以及oracle游标的使用详解的知识点,同时本文还将给你拓展Fororacledatabases,ifthetopshowingtheoracledat

本篇文章给大家谈谈Oracle 学习笔记十一 游标,以及oracle游标的使用详解的知识点,同时本文还将给你拓展For oracle databases, if the top showing the oracle database, then oracle process is using the top c、How I Simplified Oracle Database 12c and 11g Installations on Oracle Linux 6、JavaScript 学习笔记十一 函数高级应用、NodeJS-Oracle DB - NJS-040 连接超时,在 ICP 中使用带有 Lopback 的 oracle 驱动程序(loopback-connector-oracle)等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

Oracle 学习笔记十一 游标(oracle游标的使用详解)

Oracle 学习笔记十一 游标(oracle游标的使用详解)

游标的简介

游标的概念

游标是从数据表中提取出来的数据,以临时表的形式存放在内存中,在游标中有一个数据指针,在初始状态下指向的是首记录,利用 fetch 语句可以移动该指针,从而对游标中的数据进行各种操作,然后将操作结果写回数据表中。

逐行处理查询结果,以编程的方式访问数据。

 

游标的定义

游标作为一种数据类型,首先必须进行定义,其语法如下:

cursor 游标名 is select 语句;

cursor 是定义游标的关键词,select 是建立游标的数据表查询命令。

 

declare
  cursor  c1  is 
    select  ename, sal  from emp  where rownum<11;  --定义游标
  v_ename varchar2(10);
  v_sal number(7,2);
begin
  open  c1;  --打开游标
  fetch  c1  into  v_ename, v_sal;  --fetch游标,读取数据
  while  c1%found 
 loop
  dbms_output.put_line(v_ename||to_char(v_sal) );
  fetch  c1  into v_ename, v_sal;
end loop;
close c1;  --关闭游标
end;

 

 

 

 游标的类型

 

 隐式游标

在 PL/SQL 中使用 DML 语句时自动创建隐式游标,即:所有的 SQL 语句在上下文区内部都是可执行的,因此都有一个游标指向上下文区,此游标就是所谓的 SQL 游标 (SQL cursor),与显式游标不同,SQL 游标不被程序打开和关闭,通过检查隐式游标的属性可以获得最近执行的 DML 语句的信息。

 

隐式游标的属性有:SQL + 属性

  1.% FOUND – SQL 语句影响了一行或多行时为 TRUE

  2.% NOTFOUND – SQL 语句没有影响任何行时为 TRUE

  3.% ROWCOUNT – SQL 语句影响的行数

  4.% ISOPEN  - 游标是否打开,始终为 FALSE

 

SET SERVEROUTPUT ON
BEGIN
    UPDATE toys SET toyprice=270
    WHERE toyid= ''P005'';
    IF SQL%FOUND THEN    --只有在 DML 语句影响一行或多行时,才返回 True
        DBMS_OUTPUT.PUT_LINE(''表已更新'');
    END IF;
END;

 

 

 

 

SET SERVEROUTPUT ON
DECLARE
      v_TOYID TOYS.ID%type := ''&TOYID'';
      v_TOYNAME TOYS.NAME%Type := ''&TOYNAME'';
     BEGIN
      UPDATE TOYS SET NAME = v_TOYNAME
      WHERE toyid=v_TOYID;
      IF SQL%NOTFOUND THEN      --如果 DML 语句不影响任何行,则返回 True 
            DBMS_OUTPUT.PUT_LINE(''编号未找到。'');
     ELSE
        DBMS_OUTPUT.PUT_LINE(''表已更新'');
    END IF;
END;

 

 

SET SERVEROUTPUT ON 
BEGIN
    UPDATE vendor_master
    SET venname= ''Rob Mathew''
    WHERE vencode=''V004'';
    DBMS_OUTPUT.PUT_LINE (SQL%ROWCOUNT);    --返回 DML 语句影响的行数
END;

 

 

BEGIN
   UPDATE rooms  SET number_seats = 100
     WHERE room_id = 99980;
       -- 如果更新没有匹配则插入一新行
   IF SQL%ROWCOUNT = 0  THEN
           INSERT INTO rooms ( room_id, number_seats )
           VALUES ( 99980, 100 ) ;
   END IF;
END;

 

 

SELECT INTO 语句

SET SERVEROUTPUT ON
DECLARE 
    empid VARCHAR2(10);
    desig VARCHAR2(10);
BEGIN
    empid:= ''&Employeeid'';
    SELECT designation INTO desig 
        FROM employee WHERE empno=empid;
    EXCEPTION
        WHEN NO_DATA_FOUND THEN    --如果没有与SELECT INTO语句中的条件匹配的行,将引发NO_DATA_FOUND异常
            DBMS_OUTPUT.PUT_LINE(''职员未找到'');
END;

 

 

 

SET SERVEROUTPUT ON
DECLARE 
  empid VARCHAR2(10);
BEGIN
  SELECT empno INTO empid FROM employee;--给变量多个值
  EXCEPTION
    WHEN TOO_MANY_ROWS THEN      --如果 SELECT INTO 语句返回多个值,将引发TOO_MANY_ROWS异常
      DBMS_OUTPUT.PUT_LINE(''该查询提取多行'');
END;

 

 

 

显式游标

显式游标在 PL/SQL 块的声明部分定义查询,该查询可以返回多行。

 

显式游标的操作过程:

如何使用?

游标的打开操作

  如果要使用创建好的游标,需要先打开游标,语法结构如下:

  open 游标名;

  打开游标的过程有以下两个步骤:

    (1)将符合条件的记录送入内存。

    (2)将指针指向第一条记录的前面。

游标打开了要关闭:CLOSE 游标名;

 

游标提取数据的操作(每次只能提取一行);

  如果要提取游标中的数据,需要使用 fetch 命令,语法形式如下。

  fetch 游标名 into 变量名 1, 变量名 2,……;

  或 fetch 游标名 into 记录型变量名;

 

示例代码:

set serveroutput on 
declare
     tempsal scott.emp.sal%type;    --定义cursorrecord变量是游标mycursor的记录行变量 
    cursor mycursor is 
    select * from scott.emp 
    where sal>tempsal;     --在游标mycursor的结果中找到sal字段大于800的第一个记录
    cursorrecord mycursor%rowtype;    
begin
     tempsal:=800;
    open mycursor; 
    fetch mycursor into cursorrecord; 
    dbms_output.put_line(cursorrecord.deptno);     --显示deptno字段的内容 
end;

 

 

set serveroutput on 
declare     tempsal scott.emp.sal%type; 
    cursor mycursor is 
    select * from scott.emp 
    where sal>tempsal; 
    cursorrecord mycursor%rowtype; 
begin     tempsal:=800; 
    if mycursor%isopen then 
        fetch mycursor into cursorrecord; dbms_output.put_line(to_char(cursorrecord.deptno)); 
    else     dbms_output.put_line(''游标没有打开!''); 
    end if; 
end;

 

 

SET SERVER OUTPUT ON
DECLARE
  my_toy_price toys.toyprice%TYPE;    
  CURSOR toy_cur IS
    SELECT toyprice FROM toys
      WHERE toyprice<250;    --声明游标
BEGIN
  OPEN toy_cur;      --打开游标
  LOOP
    FETCH toy_cur INTO my_toy_price;    --提取行
    EXIT WHEN toy_cur%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(''TOYPRICE=:玩具单价=:''||my_toy_price);
  END LOOP;
  CLOSE toy_cur;    --关闭游标
END;

 

 

带参数的显式游标

声明显式游标时可以带参数以提高灵活性。

声明带参数的显式游标的语法如下:

  CURSOR <cursor_name>(<param_name> <param_type>)

     IS select_statement;

要注意的是:参数定义时,数据类型只能写名字,而不能定义长度!还有,当定义了参数游标后一定要在游标子查询的 where 子句中引用参数不然就没有意义。

SET SERVEROUTPUT ON
DECLARE
  desig    VARCHAR2(20);
  emp_code VARCHAR2(5);
  empnm    VARCHAR2(20);
  CURSOR emp_cur(desigparam VARCHAR2) IS
    SELECT empno, ename FROM employee
      WHERE designation=desigparam;
BEGIN
  desig:= ''&desig'';
  OPEN emp_cur(desig);
  LOOP
    FETCH emp_cur INTO emp_code,empnm;
    EXIT WHEN emp_cur%NOTFOUND;
      DBMS_OUTPUT.PUT_LINE(emp_code||'' ''||empnm);
  END LOOP;
  CLOSE emp_cur;
END;

 

使用显式游标更新行

允许使用游标删除或更新活动集中的行。

声明游标时必须使用 SELECT … FOR UPDATE OF 列名 [nowait] 语句. For update 用于结果集上加锁,nowait 不等待锁。

  CURSOR <cursor_name> IS

    SELECT statement FOR UPDATE;

更新的语法

  UPDATE <table_name>

    SET <set_clause>

      WHERE CURRENT OF <cursor_name>

删除的语法

DELETE FROM <table_name>

  WHERE CURRENT OF <cursor_name>

 

SET SERVEROUTPUT ONDECLARE
  new_price NUMBER;
  CURSOR cur_toy IS
    SELECT toyprice FROM toys WHERE toyprice<100
      FOR UPDATE OF toyprice;
BEGIN
  OPEN cur_toy;
  LOOP
    FETCH cur_toy INTO new_price;
    EXIT WHEN cur_toy%NOTFOUND;
    UPDATE toys
      SET toyprice = 1.1*new_price
        WHERE CURRENT OF cur_toy;
  END LOOP;
  CLOSE cur_toy;
  COMMIT;
END;

 

循环游标

循环游标用于简化游标处理代码,当用户需要从游标中提取所有记录时使用,不需要显示打开和关闭游标。

 

循环游标的语法如下:

FOR <record_index> IN <cursor_name>
LOOP
    <executable statements>
END LOOP;

注意: <record_index> 名字可以不需要定义,直接使用,因为是 Oracle 隐含定义的变量名

 

SET SERVER OUTPUT ON
DECLARE 
  CURSOR mytoy_cur IS
    SELECT toyid, toyname, toyprice
      FROM toys;
BEGIN
  FOR toy_rec IN mytoy_cur
  LOOP
    DBMS_OUTPUT.PUT_LINE(''玩具编号:''||'' '' ||toy_rec.toyid||'' ''            
            ||''玩具名称:''||'' ''||toy_rec.toyname||'' ''
            ||''玩具单价:''||'' ''||toy_rec.toyprice);
  END LOOP;
END;

 

 

REF 游标和游标变量

REF 游标和游标变量用于处理运行时动态执行的 SQL 查询。

创建游标变量需要两个步骤:

  1. 声明 REF 游标类型

Type newer_cur is ref cursor; --定义了一个newer_cur的游标类型(弱类型)
Type newer_cur is ref cursor return emp%rowtype; --强游标类型,表示这个游标的结果返回的一定是empty类型

  2. 声明 REF 游标类型的变量

Mycur newer_cur;  --定义变量mycur,它是引用游标类型

 

 

用于声明 REF 游标类型的语法为:

TYPE <ref_cursor_name> IS REF CURSOR [RETURN <return_type>];

 

打开游标变量的语法如下:

OPEN cursor_name FOR select_statement;

 

声明强类型的 REF 游标

TYPE my_curtype IS REF CURSOR
  RETURN stud_det%ROWTYPE;
order_cur my_curtype; 

 

 

声明弱类型的 REF 游标

TYPE my_ctype IS REF CURSOR;
stud_cur my_ctype;

 

 

DECLARE 
  TYPE toys_curtype IS REF CURSOR
    RETURN toys%ROWTYPE;
  toys_curvar toys_curtype;
  toys_rec toys%ROWTYPE;
BEGIN
  OPEN toys_curvar FOR
    SELECT * FROM toys;
  FETCH toys_curvar INTO toys_rec;
  ...
  CLOSE toys_curvar;
END;

 

游标变量的优点和限制

游标变量的功能强大,可以简化数据处理。

游标变量的优点有:

  1. 可从不同的 SELECT 语句中提取结果集

  2. 可以作为过程的参数进行传递

  3. 可以引用游标的所有属性

  4. 可以进行赋值运算

使用游标变量的限制:

  1. 不能在程序包中声明游标变量

  2.FOR UPDATE 子句不能与游标变量一起使用

  3. 不能使用比较运算符

 

可以使用游标变量执行动态构造的 SQL 语句。

打开执行动态 SQL 的游标变量的语如下:

OPEN cursor_name FOR dynamic_sqlstring [USING bind_argument_list];

 

DECLARE
  r_emp emp%ROWTYPE;
  TYPE c_type IS REF CURSOR;
  cur c_type;
  p_salary NUMBER;
BEGIN
  p_salary := 2500;
  OPEN cur FOR ''select * from emp where sal>:1 order by sal desc'' USING p_salary;
  DBMS_OUTPUT.PUT_LINE(''薪水大于''|| p_salary ||''的员工有:'');
  LOOP
    FETCH cur INTO r_emp;
  EXIT WHEN cur%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(''编号:''|| r_emp.empno
      || '' 姓名:'' || r_emp.ename|| '' 薪水:'' || r_emp.sal );
  END LOOP;
  CLOSE cur; 
END;

 

 

其他笔记

显示游标

-- 更新员工的奖金,如果成功了,则提示成功的信息,失败了则提示失败的信息。

begin
    update emp set comm = 1 where empno = 8499; --DML语句
    if SQL%found then
        dbms_output.put_line(''数据已经成功更新了'');
    else
        dbms_output.put_line(''数据更新失败'');
    end if;
end;

 

-- 记录用户登录情况的信息(更新用户的登录信息)

Begin
    Update login set ltime = sysdate where name = ''zs'';
    If sql%notfound then
        Insert into login values(''zs'', sysdate);
    End if;
End;

-- 在 PL/SQL 中显示所有工资大于 2000 的员工信息

Declare
    --定义一个游标,里面保存的是工资大于2000的数据
    Cursor mycursor is select * from emp where sal > 2000;
    mydata emp%rowtype;
Begin
    Open mycursor;   --打开游标
    Fetch mycursor into mydata;  --提取一行数据
    Dbms_output.put_line(mydata.empno || '' '' || mydata.ename);
    Close mycursor;  --关闭游标
End;

 

-- 循环输出

Declare
    --定义一个游标,里面保存的是工资大于2000的数据
    Cursor mycursor is select * from emp where sal > 2000;
    mydata emp%rowtype;
Begin
    Open mycursor;   --打开游标
    loop
        Fetch mycursor into mydata;  --提取一行数据
        If mycursor%notfound then
            Exit;
        End if;
        Dbms_output.put_line(mydata.empno || '' '' || mydata.ename || '' '' || mydate.sal);
    End loop;
    Close mycursor;  --关闭游标
End;

 

-- 使用 for 循环来操作

Declare
    --定义一个游标,里面保存的是工资大于2000的数据
    Cursor mycursor is select * from emp where sal > 2000;
    mydata emp%rowtype;
Begin
    For myname in mycursor loop  --无需打开关闭和,表示提取一行到myname里面
        Dbms_ouptup.put_line(myname.empno || '' '' || myname.ename);
    End loop;
End;

-- 使用游标 2: 列数和顺序要一致

Declare
    Cursor mycur is select ename, sal from emp;
    Var_row emp%rowtype;
    Var_name emp.ename%type;
    Var_sal emp.sal%type;
Begin
    Open mycur;
    Loop
        --fetch mycur into var_row; --错误 PLS-00394: 在FETCH语句的INTO列表中值数量出现错误
        Fetch mycur into var_name, var_sal; -- 使用变量来接收结果
        Exit when mycur%notfound;
        Dbms_output.put_line(var_name || '' '' || var_sal);
    End loop;
    Close mycur;
End;

-- 参数游标:在定义游标的时候通过定义参数提高灵活性。

-- 指定工资参数的游标:

Declare
    Cursor cur_sal(vsal number) is select * from emp where sal > vsal;
Begin
    For row in cur_sal(2000) loop
        Dbms_output.put_line(row.ename || '' '' || row.sal);
    End loop;
End;

 

-- 可更新游标

--更新
Declare
    Cursor cur is select * from emp where sal > 2500 for update;
Begin
    For row in cur loop
        Dbms_output.put_line(row.ename || '' '' || row.sal ||  '' '' || row.comm);
        --update emp set comm = 9 where empno = row.empno;
        Update emp set comm = 9 where current of cur;
        --delete emp where current of cur;  --删除游标数据
    End loop;
End;

REF 游标

-- 使用

Declare
    Type newer_cur is ref cursor;
    Var_row emp%rowtype;
    Var_cur newer_cur;
Begin
    Open var_cur for select * from emp where sal > 2500;
    Loop
        Fetch var_cur into var_row;
        Exit when var_cur%notfound;
        Dbms_output.put_line(var_row.empno || '' '' || var_row.ename || '' '' || var_row.sal);
    End loop;
End;

-- 根据员工所在的部门信息来查询数据,如果员工是 10 部门则查询前 5 个员工,如果是 20 部门则查询 6-10 号,如果是 30 部门则查询 10 号以后的员工

Declare
    Type mycur is ref cursor;
    Cur mycur;
    Var_dept int;
    Var_n varchar2(20);
    Var_sal int;
    Var_rn int;
Begin
    Var_dept := &n;
    If var_dept = 10 then
        Open cur for select * from (select rownum rn, d.* from (select ename,sal from emp order by sal desc) d ) where rn <=5;
    Else if var_dept = 20 then
        Open cur for select * from (select rownum rn, d.* from (select ename,sal from emp order by sal desc) d ) where rn > 5 and rn <=10;
    Else
        Open cur for select * from (select rownum rn, d.* from (select ename,sal from emp order by sal desc) d ) where rn > 10;
    End if;
    End if;
    
    Loop
        Fetch cur into var_rn, var_n, var_sal;
        Exit when cur%notfound;
        Dbms_output.put_line(var_n || '' '' || var_sal || '' '' || var_rn);
    End loop;
End;

For oracle databases, if the top showing the oracle database, then oracle process is using the top c

For oracle databases, if the top showing the oracle database, then oracle process is using the top c

Note 805586.1 Troubleshooting Session Administration (Doc ID 805586.1) Note 822527.1 How To Find Where The Memory Is Growing For A Process (Doc ID 822527.1) Note 273646.1 How to diagnose the high cpu utilization of ORACLE.EXE in Windows environment Note 728539.1 Find Blocking Sessions In sqlPLUS Note 61552.1 Troubleshooting Oracle Database Hanging Issues for versions from 7 to 9--Exhaustive Note 164760.1 Detecting and Resolving Locking Conflicts using TopSessions

How I Simplified Oracle Database 12c and 11g Installations on Oracle Linux 6

How I Simplified Oracle Database 12c and 11g Installations on Oracle Linux 6

How I Simplified Oracle Database 12c and 11g Installations on Oracle Linux 6

by Ginny Henningsen; updated by Michele Casey

How to simplify the installation of Oracle Database 12c or 11g on Oracle Linux 6 by installing the oracle-rdbms-server-12cR1-preinstall or oracle-rdbms-server-11gR2-preinstall RPM package, which automatically performs a number of tasks, such as installing required software packages, resolving package dependencies, and modifying kernel parameters.

 

Published September 2012 (updated September 2017)

READ THIS FIRST: Important Changes Since Publication

While the content in this article is still valid, several details have changed.  For example:

  • For Oracle Database 12c Release 2, the preinstall RPM has a different name than the one used in the article belowpu:
    • oracle-database-server-12cR2-preinstall
    • See also this documentation: Automatically Configuring Oracle Linux with Oracle Preinstallation RPM
  • The preinstall RPMs are published on Oracle Linux yum server for both Oracle Linux 6 and 7 in the Latest repositories which are configured and enabled by default in recent releases of Oracle Linux 6 and 7 


 

Introducing the oracle-rdbms-server-12cR1-preinstall and oracle-rdbms-server-11gR2-preinstall RPM for Oracle Linux

Before installing Oracle Database 12c or 11g on a system, you need to preconfigure the operating environment since the database requires certain software packages, package versions, and tweaks to kernel parameters. (Be sure to review the appropriate Oracle Database installation guide to familiarize yourself with hardware, software, and operating system requirements.)

Want to comment on this article? Post the link on Facebook''s OTN Garage page.  Have a similar article to share? Bring it up on Facebook or Twitter and let''s discuss.

Note: This article applies to Oracle Linux 6. A previous article, "How I Simplified Oracle Database Installation on Oracle Linux," covered performing a similar task on versions of Oracle Linux 5.

On Oracle Linux, I discovered that there is a remarkably easy way to address these installation prerequisites: First, depending on your database version, install either the RPM package called oracle-rdbms-server-12cR1-preinstall or oracle-rdbms-server-11gR2-preinstall. This RPM performs a number of preconfiguration steps, including the following:

  • Automatically downloading and installing any additional software packages and specific package versions needed for installing Oracle Grid Infrastructure and Oracle Database 12 c Release 1 (12.1) or 11g Release 2 (11.2.0.3), with package dependencies resolved via yum or up2date capabilities.
  • Creating the user oracle and the groups oinstall (for OraInventory) and dba (for OSDBA), which are used during database installation. (For security purposes, this user has no password by default and cannot log in remotely. To enable remote login, please set a password using the passwd tool.)
  • Modifying kernel parameters in /etc/sysctl.conf to change settings for shared memory, semaphores, the maximum number of file descriptors, and so on.
  • Setting hard and soft shell resource limits in /etc/security/limits.conf, such as the locked-in memory address space, the number of open files, the number of processes, and core file size.
  • Setting numa=off in the kernel for x86_64 machines.

Note that oracle-rdbms-server-12cR1-preinstall and oracle-rdbms-server-11gR2-preinstall parses the existing /etc/sysctl.conf and /etc/security/limits.conf files and updates values only as needed for database installation. Any precustomized settings not related to database installation are left as is.

The oracle-rdbms-server-12cR1-preinstall and oracle-rdbms-server-11gR2-preinstall RPM packages are accessible through the Oracle Unbreakable Linux Network (ULN, which requires a support contract), from the Oracle Linux distribution media, or from the Oracle public yum repository. Thus, whether or not your system is registered with ULN to access Oracle patches and support, you can use oracle-rdbms-server-12cR1-preinstall and oracle-rdbms-server-11gR2-preinstall to simplify database installation on Oracle Linux. In addition, the Oracle public yum repository now includes all security and bug errata, ensuring systems are secured and stable with the latest security updates and bug fixes.

Installing the oracle-rdbms-server-12cR1-preinstall or oracle-rdbms-server-11gR2-preinstall RPM

The remainder of this article steps through the procedure that I used for installing oracle-rdbms-server-11gR2-preinstall on Oracle Linux via the Oracle public yum repository. The same steps outlined in the following section can be used for either version of the preinstall RPM package. I started with a system running Oracle Linux Release 6 Update 4 for x86_64, a 64-bit version of Oracle Linux that I downloaded from the Oracle software delivery cloud (requires registration or login). First, I set up a yum configuration file that pointed to the correct repository, and then I installed the oracle-rdbms-server-11gR2-preinstall RPM from that repository.

Here are the steps for preconfiguring a system for Oracle Database installation using oracle-rdbms-server-11gR2-preinstall. Remember, the steps are the same when using the oracle-rdbms-server-12cR1-preinstall package; you simply need to change the name of the RPM package during the yum installation step.

  1. As an authorized user (for example, root), retrieve the file that configures repository locations:
     
    # cd /etc/yum.repos.d
    
    # wget http://yum.oracle.com/public-yum-ol6.repo
  2. Using a text editor, modify the file, changing the field enabled=0 to enabled=1 to reflect repositories that correspond to the machine''s operating system release.
     

    Here is an excerpt of public-yum-old6.repo with the changed lines in boldface.

    [ol6_latest]
    
    name=Oracle Linux $releasever Latest ($basearch)
    
    baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/latest/$basearch/
    
    gpgkey=http://yum.oracle.com/RPM-GPG-KEY-oracle-ol6
    
    gpgcheck=1
    
    enabled=1
    
    
    
    
    
    [ol6_UEK_latest]
    
    name=Latest Unbreakable Enterprise Kernel for Oracle Linux $releasever ($basearch)
    
    baseurl=http://yum.oracle.com/repo/OracleLinux/OL6/UEK/latest/$basearch/
    
    gpgkey=http://yum.oracle.com/RPM-GPG-KEY-oracle-ol6
    
    gpgcheck=1
    
    enabled=1
     

    Because the target system is running Oracle Linux Release 6 Update 4 for x86_64, which installs the Oracle Unbreakable Enterprise Kernel by default, there are two repositories to enable, [ol6_latest] and [ol6_UEK_latest].

  3. Next, install the oracle-rdbms-server-11gR2-preinstall RPM using the yum install command. If you are using Oracle Database 12c, then you would type yum install.
     

    The output in Listing 1 shows how the installation checks dependencies and then downloads and installs the required packages.

    # yum install oracle-rdbms-server-11gR2-preinstall
    
    Loaded plugins: refresh-packagekit, rhnplugin, security
    
    Setting up Install Process
    
    Resolving Dependencies
    
    --> Running transaction check
    
    ---> Package oracle-rdbms-server-11gR2-preinstall.x86_64 0:1.0-6.el6 will be installed
    
    --> Processing Dependency: gcc-c++ for package: oracle-rdbms-server-11gR2-preinstall-1.0-6.el6.x86_64
    
    --> Processing Dependency: gcc for package: oracle-rdbms-server-11gR2-preinstall-1.0-6.el6.x86_64
    
    --> Processing Dependency: libaio-devel for package: oracle-rdbms-server-11gR2-preinstall-1.0-6.el6.x86_64
    
    --> Processing Dependency: libstdc++-devel for package: oracle-rdbms-server-11gR2-preinstall-1.0-6.el6.x86_64
    
    --> Processing Dependency: glibc-devel for package: oracle-rdbms-server-11gR2-preinstall-1.0-6.el6.x86_64
    
    --> Processing Dependency: compat-libstdc++-33 for package: oracle-rdbms-server-11gR2-preinstall-1.0-6.el6.x86_64
    
    --> Processing Dependency: ksh for package: oracle-rdbms-server-11gR2-preinstall-1.0-6.el6.x86_64
    
    --> Processing Dependency: compat-libcap1 for package: oracle-rdbms-server-11gR2-preinstall-1.0-6.el6.x86_64
    
    --> Running transaction check
    
    ---> Package compat-libcap1.x86_64 0:1.10-1 will be installed
    
    ---> Package compat-libstdc++-33.x86_64 0:3.2.3-69.el6 will be installed
    
    ---> Package gcc.x86_64 0:4.4.6-4.el6 will be installed
    
    --> Processing Dependency: cpp = 4.4.6-4.el6 for package: gcc-4.4.6-4.el6.x86_64
    
    --> Processing Dependency: cloog-ppl >= 0.15 for package: gcc-4.4.6-4.el6.x86_64
    
    ---> Package gcc-c++.x86_64 0:4.4.6-4.el6 will be installed
    
    --> Processing Dependency: libmpfr.so.1()(64bit) for package: gcc-c++-4.4.6-4.el6.x86_64
    
    ---> Package glibc-devel.x86_64 0:2.12-1.80.el6_3.4 will be installed
    
    --> Processing Dependency: glibc-headers = 2.12-1.80.el6_3.4 for package: glibc-devel-2.12-1.80.el6_3.4.x86_64
    
    --> Processing Dependency: glibc-headers for package: glibc-devel-2.12-1.80.el6_3.4.x86_64
    
    ---> Package ksh.x86_64 0:20100621-16.el6 will be installed
    
    ---> Package libaio-devel.x86_64 0:0.3.107-10.el6 will be installed
    
    ---> Package libstdc++-devel.x86_64 0:4.4.6-4.el6 will be installed
    
    --> Running transaction check
    
    ---> Package cloog-ppl.x86_64 0:0.15.7-1.2.el6 will be installed
    
    --> Processing Dependency: libppl_c.so.2()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64
    
    --> Processing Dependency: libppl.so.7()(64bit) for package: cloog-ppl-0.15.7-1.2.el6.x86_64
    
    ---> Package cpp.x86_64 0:4.4.6-4.el6 will be installed
    
    ---> Package glibc-headers.x86_64 0:2.12-1.80.el6_3.4 will be installed
    
    --> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.12-1.80.el6_3.4.x86_64
    
    --> Processing Dependency: kernel-headers for package: glibc-headers-2.12-1.80.el6_3.4.x86_64
    
    ---> Package mpfr.x86_64 0:2.4.1-6.el6 will be installed
    
    --> Running transaction check
    
    ---> Package kernel-uek-headers.x86_64 0:2.6.32-300.32.1.el6uek will be installed
    
    ---> Package ppl.x86_64 0:0.10.2-11.el6 will be installed
    
    --> Finished Dependency Resolution
    
    
    
    Dependencies Resolved
    
    
    
    ================================================================================
    
     Package                         Arch   Version                Repository  Size
    
    ================================================================================
    
    Installing:
    
     oracle-rdbms-server-11gR2-preinstall
    
                                     x86_64 1.0-6.el6              ol6_latest  15 k
    
    Installing for dependencies:
    
     cloog-ppl                       x86_64 0.15.7-1.2.el6         ol6_latest  93 k
    
     compat-libcap1                  x86_64 1.10-1                 ol6_latest  17 k
    
     compat-libstdc++-33             x86_64 3.2.3-69.el6           ol6_latest 183 k
    
     cpp                             x86_64 4.4.6-4.el6            ol6_latest 3.7 M
    
     gcc                             x86_64 4.4.6-4.el6            ol6_latest  10 M
    
     gcc-c++                         x86_64 4.4.6-4.el6            ol6_latest 4.7 M
    
     glibc-devel                     x86_64 2.12-1.80.el6_3.4      ol6_latest 970 k
    
     glibc-headers                   x86_64 2.12-1.80.el6_3.4      ol6_latest 600 k
    
     kernel-uek-headers              x86_64 2.6.32-300.32.1.el6uek ol6_latest 713 k
    
     ksh                             x86_64 20100621-16.el6        ol6_latest 684 k
    
     libaio-devel                    x86_64 0.3.107-10.el6         ol6_latest  13 k
    
     libstdc++-devel                 x86_64 4.4.6-4.el6            ol6_latest 1.5 M
    
     mpfr                            x86_64 2.4.1-6.el6            ol6_latest 156 k
    
     ppl                             x86_64 0.10.2-11.el6          ol6_latest 1.3 M
    
    
    
    Transaction Summary
    
    ================================================================================
    
    Install      15 Package(s)
    
    
    
    Total download size: 25 M
    
    Installed size: 61 M
    
    Is this ok [y/N]: Downloading Packages:
    
    --------------------------------------------------------------------------------
    
    Total                                           710 kB/s |  25 MB     00:35     
    
    Running rpm_check_debug
    
    Running Transaction Test
    
    Transaction Test Succeeded
    
    Running Transaction
    
    
    
      Installing : mpfr-2.4.1-6.el6.x86_64                                     1/15 
    
      Installing : libstdc++-devel-4.4.6-4.el6.x86_64                          2/15 
    
      Installing : cpp-4.4.6-4.el6.x86_64                                      3/15 
    
      Installing : ppl-0.10.2-11.el6.x86_64                                    4/15 
    
      Installing : cloog-ppl-0.15.7-1.2.el6.x86_64                             5/15 
    
      Installing : kernel-uek-headers-2.6.32-300.32.1.el6uek.x86_64            6/15 
    
      Installing : glibc-headers-2.12-1.80.el6_3.4.x86_64                      7/15 
    
      Installing : glibc-devel-2.12-1.80.el6_3.4.x86_64                        8/15 
    
      Installing : gcc-4.4.6-4.el6.x86_64                                      9/15 
    
      Installing : gcc-c++-4.4.6-4.el6.x86_64                                 10/15 
    
      Installing : compat-libstdc++-33-3.2.3-69.el6.x86_64                    11/15 
    
      Installing : libaio-devel-0.3.107-10.el6.x86_64                         12/15 
    
      Installing : ksh-20100621-16.el6.x86_64                                 13/15 
    
      Installing : compat-libcap1-1.10-1.x86_64                               14/15 
    
    
    
      Installing : oracle-rdbms-server-11gR2-preinstall-1.0-6.el6.x86_64      15/15 
    
      Verifying  : gcc-4.4.6-4.el6.x86_64                                      1/15
    
      Verifying  : compat-libcap1-1.10-1.x86_64                                2/15 
    
      Verifying  : ksh-20100621-16.el6.x86_64                                  3/15 
    
      Verifying  : glibc-devel-2.12-1.80.el6_3.4.x86_64                        4/15 
    
      Verifying  : libaio-devel-0.3.107-10.el6.x86_64                          5/15 
    
      Verifying  : oracle-rdbms-server-11gR2-preinstall-1.0-6.el6.x86_64       6/15 
    
      Verifying  : gcc-c++-4.4.6-4.el6.x86_64                                  7/15 
    
      Verifying  : glibc-headers-2.12-1.80.el6_3.4.x86_64                      8/15 
    
      Verifying  : libstdc++-devel-4.4.6-4.el6.x86_64                          9/15 
    
      Verifying  : compat-libstdc++-33-3.2.3-69.el6.x86_64                    10/15 
    
      Verifying  : mpfr-2.4.1-6.el6.x86_64                                    11/15 
    
      Verifying  : kernel-uek-headers-2.6.32-300.32.1.el6uek.x86_64           12/15 
    
      Verifying  : cpp-4.4.6-4.el6.x86_64                                     13/15 
    
      Verifying  : ppl-0.10.2-11.el6.x86_64                                   14/15 
    
      Verifying  : cloog-ppl-0.15.7-1.2.el6.x86_64                            15/15 
    
    
    
    Installed:
    
      oracle-rdbms-server-11gR2-preinstall.x86_64 0:1.0-6.el6                       
    
    
    
    Dependency Installed:
    
      cloog-ppl.x86_64 0:0.15.7-1.2.el6                                             
    
      compat-libcap1.x86_64 0:1.10-1                                                
    
      compat-libstdc++-33.x86_64 0:3.2.3-69.el6                                     
    
      cpp.x86_64 0:4.4.6-4.el6                                                      
    
      gcc.x86_64 0:4.4.6-4.el6                                                      
    
      gcc-c++.x86_64 0:4.4.6-4.el6                                                  
    
      glibc-devel.x86_64 0:2.12-1.80.el6_3.4                                        
    
      glibc-headers.x86_64 0:2.12-1.80.el6_3.4                                      
    
      kernel-uek-headers.x86_64 0:2.6.32-300.32.1.el6uek                            
    
      ksh.x86_64 0:20100621-16.el6                                                  
    
      libaio-devel.x86_64 0:0.3.107-10.el6                                          
    
      libstdc++-devel.x86_64 0:4.4.6-4.el6                                          
    
      mpfr.x86_64 0:2.4.1-6.el6                                                     
    
      ppl.x86_64 0:0.10.2-11.el6                                                    
    
    
    
    Complete!

    Listing 1: Installing the oracle-rdbms-server-11gR2-preinstall RPM

    The yum installation logs messages about kernel changes in the file /var/log/oracle-rdbms-server-11gR2-preinstall/results/orakernel.log, and it makes backups of current system settings in the directory /var/log/oracle-rdbms-server-11gR2-preinstall/backup.

  4. At this point, the system is ready for the installation of Oracle Database. For example, to install Oracle Database 11g Release 2, follow the directions in Chapter 4, "Installing Oracle Database," of the Database Installation Guide for Linux."
     

    Here are the steps I followed while installing Oracle Database 11g Release 2 in my test environment. Make sure you review all documentation and follow recommended best practices before installing into your production environment.

    1. As root, create a parent directory in a file system that has sufficient space to be the target location for the downloaded files:
       
      # mkdir /home/OraDB11g
      
      # cd /home/OraDB11g
       

      The amount of disk space needed in the file system varies according to the specific installation type, but roughly twice the size of the zip archives, or 5 GB, is enough to house the software and data files.

    2. Into this target directory, download the installation media files from the Oracle Database Software Downloads page on Oracle Technology Network.
    3. Extract the files:
       
      # unzip linux.x64_11gR2_database_1of2.zip
      
      # unzip linux.x64_11gR2_database_2of2.zip 
    4. Log in as the user oracle. Change directory to the database directory and enter the following command to run the Oracle Universal Installer:
       
      $ cd /home/OraDB11g/database
      
      $ ./runInstaller

    The Oracle Universal Installer performs a number of checks, verifying that the necessary OS packages and versions are installed. In addition, it checks kernel parameters set by the oracle-rdbms-server-11gR2-preinstall installation. During the kernel settings check, the installer might flag a few settings as "failed," and you should investigate these failures. In some cases, you still might be able to continue with the database installation. If you check kernel settings in /etc/sysctl.conf, you''ll see that oracle-rdbms-server-11gR2-preinstall has modified and added the necessary settings to ensure the minimum requirements are met, as defined in section 2.10.1, "Displaying and Changing Kernel Parameter Values," in Chapter 2, "Oracle Database Preinstallation Requirements," of the Oracle Database Installation Guide 11g Release2 (11.2) for Linux. Below is the list of requirements:

    fs.aio-max-nr = 1048576
    
    fs.file-max = 6815744
    
    kernel.shmall = 2097152
    
    kernel.shmmax = 4294967295
    
    kernel.shmmni = 4096
    
    kernel.sem = 250 32000 100 128
    
    net.ipv4.ip_local_port_range = 9000 65500
    
    net.core.rmem_default = 262144
    
    net.core.rmem_max = 4194304
    
    net.core.wmem_default = 262144
    
    net.core.wmem_max = 1048576
     

    If necessary, you can (as root) edit the file /etc/sysctl.conf to specify a setting manually, for example:

    # vi /etc/sysctl.conf 
    
    # /sbin/sysctl -p
     

    The Oracle Universal Installer performs additional checks, such as verifying the glibc version, sufficient disk space, environmental variable and path settings, and sufficient physical memory and swap space. Generally, installing oracle-rdbms-server-11gR2-preinstall takes care of the prerequisites so that you can proceed directly with installing the database.

Final Thoughts

Installing the oracle-rdbms-server-12cR1-preinstall and oracle-rdbms-server-11gR2-preinstall RPMs can save time when installing Oracle Database 12c and 11g on Oracle Linux. These RPMs address most Oracle Database installation prerequisites and greatly simplify the installation process.

See Also

Here are the resources referenced earlier in this document:

  • Oracle Unbreakable Linux Network: https://linux.oracle.com
  • Oracle Linux yum server: http://yum.oracle.com/
  • Oracle software delivery cloud (requires registration or login): https://edelivery.oracle.com/linux
  • Chapter 4, "Installing Oracle Database," of the Database Installation Guide for Linux: http://docs.oracle.com/cd/E11882_01/install.112/e24321/inst_task.htm#BABBBHJH
  • Oracle Database Software Downloads page on Oracle Technology Network: http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html

And here are some additional resources from the Oracle Database Documentation Library (http://www.oracle.com/pls/db112/homepage). Relevant subsections from the Oracle Database Installation Guide 11g Release 2 (11.2) for Linux (http://download.oracle.com/docs/cd/E11882_01/install.112/e16763/toc.htm) with currently valid URLs are as follows:

  • "About the Oracle RDBMS Pre-Install and Oracle Validated RPMs" from Chapter 1, "Overview of Oracle Database Installation": http://download.oracle.com/docs/cd/E11882_01/install.112/e16763/install_overview.htm#BABDBHCJ
  • Chapter 2, "Oracle Database Preinstallation Requirements": http://download.oracle.com/docs/cd/E11882_01/install.112/e16763/pre_install.htm#BABFDGHJ
  • "Downloading Oracle Software" from Chapter 4, "Installing Oracle Database," which describes how to download installation files from the Oracle Technology Network Website: http://docs.oracle.com/cd/E11882_01/install.112/e16763/inst_task.htm#autoId6

Also see the blog entry "Oracle RDBMS Server 11gR2 Pre-Install RPM for Oracle Linux 6 has been released": https://blogs.oracle.com/linux/entry/oracle_rdbms_server_11gr2_pre

About the Authors

Ginny Henningsen has worked for the last 15 years as a freelance writer developing technical collateral and documentation for high-tech companies. Prior to that, Ginny worked for Sun Microsystems, Inc. as a Systems Engineer in King of Prussia, PA and Milwaukee, WI. Ginny has a BA from Carnegie-Mellon University and a MSCS from Villanova University.

Michele Casey is the Director of Product Management for Oracle Linux. She has worked with commercial Linux distributions and open source projects as a product manager since 2006. She has also held positions as a system administrator, project manager, and technical support engineer.

Revision 1.1, 07/09/2013; added information about using the
oracle-rdbms-server-12cR1-preinstall package to install
Oracle Database 12c

 

Follow us:

JavaScript 学习笔记十一 函数高级应用

JavaScript 学习笔记十一 函数高级应用

var logs = function (str) {
            document.writeln(str + "<br>");
        }

        //利用闭包,保存两个对象各自成员的值,避免两个对象的成员的值影响
        var s = function () {
            var i = 0;
            return function () {
                return i++;
            }
        }
        var aa = s();
        logs(aa()); //aa 对象返回 0
        var ab = s();
        logs(ab()); //ab 对象返回 0
        logs(aa());  //aa 对象返回 1
        logs(ab()); //ab 对象返回 1

        var sdd = Base.extend({
            constructor:function () {
                this.name = ''bb'';
            },
            name:"sdd",
            age:10,
            getName:function () {
                return this.name;
            }
        });
        var sddc = new sdd();
        logs(sddc.getName()); //bb

        //匿名函数的高级应用
        var mapped = [10, 2, 3].map(function (x) {
            return x * 2
        });
        logs(mapped);  //20,4,6

        [
            {id:"item1"},
            {id:"item2"},
            {id:"item3"}
        ].map(function (current) {
                    logs(current.id);   //     item1     item2      item3
                });

        // 柯里化
        //柯里化就是预先将函数的某些参数传入,得到
        //一个简单的函数,但是预先传入的参数被保存在闭包中,因此会有一些奇特的特性。
        var adder = function (num) {
            return function (y) {
                return num + y;
            }
        }
        var inc = adder(1);   //inc/dec 两个变量事实上是两个新的函数,可以通过括号来调用
        var dec = adder(-1);
        logs(inc(99));// 100   ++1   logs(adder(1)(99));
        logs(dec(99));//98     --1   logs(adder(-1)(99));

        //eg...当请求从服务端返回后,我们需要更新一些特定的页面元素,也就是局部刷新的概
        //      念。使用柯里化,则可以很大程度上美化我们的代码,使之更容易维护
        function update(item) {
            return function (text) {
                $("div#" + item).html(text);
            }
        }
        //Ajax请求,当成功是调用参数callback
        function refresh(url, callback) {
            var params = {
                type:"echo",
                data:"dd"
            };

            $.ajax({
                type:"post",
                url:url,
                cache:false,
                async:true,
                dataType:"json",
                data:params,
                //当异步请求成功时调用
                success: function(data,status){
                    callback(data);
                },
                //当请求出现错误时调用
                error: function(err){
                    logs("error : "+err);
                }
            });
        }
        refresh("action.do?target=news", update("newsPanel"));

NodeJS-Oracle DB - NJS-040 连接超时,在 ICP 中使用带有 Lopback 的 oracle 驱动程序(loopback-connector-oracle)

NodeJS-Oracle DB - NJS-040 连接超时,在 ICP 中使用带有 Lopback 的 oracle 驱动程序(loopback-connector-oracle)

如何解决NodeJS-Oracle DB - NJS-040 连接超时,在 ICP 中使用带有 Lopback 的 oracle 驱动程序(loopback-connector-oracle)?

我正在使用 loopback-connector-oracle 4.1.1 版寻求有关我面临的问题的一些信息。分析如下: 我们有 DB 连接配置,可以使用 json 文件格式的 oracle 连接器使用属性连接到 oracle DB 数据源。 "maxConn": 20,“主机”:DB_HOST, “端口”:DB_PORT, “数据库”:DB_NAME, “密码”:DB_PASSWORD, “用户”:DB_USER, "connector": "oracle",

有两个进程/pod 正在运行,每个进程/pod 都有自己的池供oracle 连接器使用。发生的情况是,在一个实例中,oracle 能够连接并处理请求,但在第二个 pod/进程中,我注意到 njs-040 错误连接超时。由于两者都运行在同一个环境中,所以连接性不会成为问题。我正在寻求您的帮助或意见以了解连接池耗尽的原因?正如我所看到的,DB 上的连接/会话数量配置的数量较少。 当我重新启动 pod/进程时,一切都会恢复正常。在我的流程中遇到的一些问题,如果您可以指导并提供宝贵的意见,我正在寻求您的帮助。

  • 如果使用连接池(oracle 连接器),它也应该释放对象,耗尽的机会会减少吗?
  • 在进程/pod 启动并通过连接器 (oracle) 获取数据源中的连接对象后,发生网络问题并且进程和数据库之间的连接丢失,连接器是否恢复?根据我的观察,我在其他进程中注意到的似乎应该被恢复,当它与范围一起运行时,在一个进程中可能会导致什么?

我非常感谢您的回复。 提前致谢 桑吉夫

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

关于Oracle 学习笔记十一 游标oracle游标的使用详解的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于For oracle databases, if the top showing the oracle database, then oracle process is using the top c、How I Simplified Oracle Database 12c and 11g Installations on Oracle Linux 6、JavaScript 学习笔记十一 函数高级应用、NodeJS-Oracle DB - NJS-040 连接超时,在 ICP 中使用带有 Lopback 的 oracle 驱动程序(loopback-connector-oracle)的相关知识,请在本站寻找。

本文标签: