import groovy.sql.Sql
sql = Sql.newInstance(
"jdbc:oracle:thin:@oraclesrv:1521:orcl",
"system",
"manager",
"oracle.jdbc.driver.OracleDriver")
// 外部表を作成する
query = """
create table dept_lookup
(
dept_id NUMBER(4),
dept_name VARCHAR2(20)
)
organization external
(
type oracle_loader
default directory external_tables
access parameters
(
records delimited by newline
fields terminated by ',' optionally enclosed by '"'
(
dept_id,
dept_name
)
)
location('dept_lookup.csv')
)
"""
sql.execute(query)
// 外部表をselect
sql.eachRow("select * from dept_lookup"){
println("${it.dept_id},${it.dept_name}")
}
// 外部表をdrop
sql.execute("drop table dept_lookup")
動作環境
groovy 1.7.5, JDK6 Update22, Oracle11g R2
0 件のコメント:
コメントを投稿