How to run below PL/SQL code from groovy againts oracle database -


below pl/sql code want run groovy program against oracle database.

begin    execute immediate 'drop table employee'; exception    when others       if sqlcode != -942          raise;       end if; end; / 

how can that. have every thing setup connecting oracle database groovy program. want somthing below:

sql = sql.newinstance(url, username, password, driver) string plsql="begin\n" +         "   execute immediate 'drop table employee';\n" +         "exception\n" +         "   when others then\n" +         "      if sqlcode != -942 then\n" +         "         raise;\n" +         "      end if;\n" +         "end;\n" +         "/"  sql.execute(plsql) 

error log-from comments

below error getting...

jun 29, 2015 9:05:52 pm groovy.sql.sql execute warning: failed execute: begin execute immediate 'drop table employee'; exception when others if sqlcode != -942 raise; end if; end; / because: ora-06550: line 9, column 1: pls-00103: encountered symbol "/" symbol "/" ignored. caught: java.sql.sqlexception: ora-06550: line 9, column 1: pls-00103: encountered symbol "/" symbol "/" ignored 

use call method execute pl/sql block. mentioned above not add slash, use terminating semicolon.

groovycon.call("""begin   execute immediate 'drop table employee'; exception    when others       if sqlcode != -942          raise;       end if; end;""") 

additionally may profit groovy multiline string (""") allowes direct cut , paste of pl/sql block between database , groovy.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -