Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2885476
  • 博文数量: 599
  • 博客积分: 16398
  • 博客等级: 上将
  • 技术积分: 6875
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-30 12:04
个人简介

WINDOWS下的程序员出身,偶尔也写一些linux平台下小程序, 后转行数据库行业,专注于ORACLE和DB2的运维和优化。 同时也是ios移动开发者。欢迎志同道合的朋友一起研究技术。 数据库技术交流群:58308065,23618606

文章分类

全部博文(599)

文章存档

2014年(12)

2013年(56)

2012年(199)

2011年(105)

2010年(128)

2009年(99)

分类: C/C++

2012-01-09 21:28:04

Pro*C中COMMIT WORK 和 COMMIT WORK RELEASE的区别


首先说明的是COMMIT WORK RELEASE是Pro*C的语法,ORACLE的SQLPLUS和PL/SQL块中不支持这样的写法。
譬如:


[oracle@huateng c]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Jan 9 20:43:10 2012

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> COMMIT WORK;

Commit complete.

SQL> COMMIT WORK RELEASE;
COMMIT WORK RELEASE
            *
ERROR at line 1:
ORA-02185: a token other than WORK follows COMMIT


SQL> BEGIN
  2    COMMIT WORK;
  3  END;
  4  /

PL/SQL procedure successfully completed.

SQL> BEGIN
  2    COMMIT WORK RELEASE;
  3  END;
  4  /
  COMMIT WORK RELEASE;
              *
ERROR at line 2:
ORA-06550: line 2, column 15:
PL/SQL: ORA-02185: a token other than WORK follows COMMIT
ORA-06550: line 2, column 3:
PL/SQL: SQL Statement ignored


SQL>


在Pro*C中 COMMIT WORK 会提交事务并释放所有的锁定及其资源,而COMMIT WORK RELEASE会提交事务并释放所有的锁定及其资源
然后断开与数据库的连接,以后所有的与数据库操作的命令都会报ORA-01012错误。

看如下一个简单的Pro*C程序:

[oracle@huateng c]$ cat commit.pc
#include
#include

exec sql include sqlca;

void main()
{
  exec sql begin declare section;
     char *username="scott";
     char *password="tiger";
     char ename[30];
  exec sql end   declare section;

  exec sql connect :username identified by :password;

  exec sql commit work;
  exec sql select ename into :ename from emp where empno=7788;
  printf("sqlcode=[%d],ename=[%s]\n",sqlca.sqlcode,ename);

  exec sql commit work release;
  exec sql select ename into :ename from emp where empno=7839;
  printf("sqlcode=[%d],ename=[%s]\n",sqlca.sqlcode,ename);

  exec sql connect :username identified by :password;
  exec sql select ename into :ename from emp where empno=7844;
  printf("sqlcode=[%d],ename=[%s]\n",sqlca.sqlcode,ename);
  return;
}

[oracle@huateng c]$ proc parse=none commit.pc

Pro*C/C++: Release 11.2.0.1.0 - Production on Mon Jan 9 21:05:47 2012

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

System default option values taken from: /appsdata/oracle/product/db11gr2/precomp/admin/pcscfg.cfg

[oracle@huateng c]$ gcc  commit.c -o commit -lclntsh  -L $ORACLE_HOME/lib
[oracle@huateng c]$ ./commit
sqlcode=[0],ename=[SCOTT                        ]
sqlcode=[-1012],ename=[SCOTT                        ]
sqlcode=[0],ename=[TURNER                       ]
[oracle@huateng c]$ oerr ora 1012
01012, 00000, "not logged on"
// *Cause:
// *Action:

可以看到第一个SELECT 语句能正常运行,第二个SQL语句就报ORA-01012错误,重新登录后,第三个SELECT又可以正常运行。

[oracle@huateng c]$


SQL> select empno,ename from emp order by 1;

     EMPNO ENAME
---------- ------------------------------
      7369 SMITH
      7499 ALLEN
      7521 WARD
      7566 JONES
      7654 MARTIN
      7698 BLAKE
      7782 CLARK
      7788 SCOTT
      7839 KING
      7844 TURNER
      7876 ADAMS
      7900 JAMES
      7902 FORD
      7934 MILLER

14 rows selected.

SQL>

 


 

阅读(7781) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~