Home  >  Article  >  Database  >  Oracle事务处理多条sql语句

Oracle事务处理多条sql语句

WBOY
WBOYOriginal
2016-06-07 17:04:431249browse

问题,执行一段代码反回一个字符串,这个串中就是要执行我多条SQL语句。怎样让它在ORACLE中通过呢。想来想去想到了动态SQL,EXEC

问题,执行一段代码反回一个字符串,这个串中就是要执行我多条SQL语句。怎样让它在Oracle中通过呢。想来想去想到了动态SQL,EXECUTE IMMEDIATE 这是一个解析和执行标准SQL语句的语法。只要在这条字符串中格式化一下我们要执行的语句就可以了,比如这条要执行的多条SQL的字符串为:

delete tableA where Aid=1;update tableB where Bid=2;insert into tableC values(id,3,4);

像这样的SQL语句想一起执行是不可以的,,只要加点格式化就OK了,

要这样:BEGIN EXECUTE IMMEDIATE 'delete tableA where Aid=1';EXECUTE IMMEDIATE 'update tableB where Bid=2';EXECUTE IMMEDIATE 'insert into tableC values(id,3,4)';END;

注意,一定要写好格式,比如END后的分号。这样就可以在ORACLE中执行这个字符串了。

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn