我需要一些帮助。我试图从python中执行SQLLDR。我发现最好的方法是使用subprocess.call。使用params代替另一个函数,我在这段代码中复制了它。 当我运行它时,我会按预期获得相应的字段。 但是,该过程返回1,这是一个失败。 我没有其他信息,无法找到可能存在的问题。
我已经验证了data.csv从BASH加载到我的表中,但是python没有。
def load_raw():
DATA_FILE='data.csv'
CONTROL_FILE='raw_table.ctl'
LOG_FILE='logfile.log'
BAD_FILE='badfile.log'
DISCARD_FILE='discard.log'
connect_string = os.environ['CONNECT_STRING']
sqlldr_parms='rows=1000 readsize=50000 direct=true columnarrayrows=100 bindsize=500000 streamsize=500000 silent=(HEADER,FEEDBACK)'
parms = {}
parms['userid'] = connect_string
parms['sqlldr'] = sqlldr_parms
parms['data'] = DATA_FILE
parms['control'] = CONTROL_FILE
parms['log'] = LOG_FILE
parms['bad'] = BAD_FILE
parms['discard'] = DISCARD_FILE
cmd = "userid=%(userid)s %(sqlldr)s data=%(data)s control=%(control)s log=%(log)s bad=%(bad)s discard=%(discard)s" % parms
print "cmd is: %s" % cmd
with open('/opt/app/workload/bfapi/bin/stdout.txt', 'wb') as out:
process = call(cmd, shell=True, stdout=out, stderr=out)
print process
cmd是:sqlldr userid = usr / pass rows = 1000 readsize = 50000 direct = true columnarrayrows = 100 bindsize = 500000 streamsize = 500000 silent =(HEADER,FEEDBACK)data = data.csv control = raw_table.ctl log = logfile.log bad = badfile.log discard = discard.log
进程返回1 不会创建log,bad和discard的日志文件
stdout.txt包含
/ bin / sh:-c:第0行:意外令牌('
/bin/sh: -c: line 0:
附近的语法错误sqlldr userid = usr / pass rows = 1000 readsize = 50000 direct = true columnarrayrows = 100
bindsize = 500000 streamsize = 500000 silent =(HEADER,FEEDBACK)data = data.csv control = raw_table.ctl
log = logfile.log bad = badfile.log discard = discard.log'
data.csv包含
id~name~createdby~createddate~modifiedby~modifieddate
6~mark~margaret~"19-OCT-16 01.03.23.966000 PM"~kyle~"21-OCT-16 03.11.22.256000 PM"
8~jill~margaret~"27-AUG-16 12.10.12.214000 PM"~kyle~"21-OCT-16 04.16.01.171000 PM"
raw_table.ctl
OPTIONS ( SKIP=1)
LOAD DATA
CHARACTERSET UTF8
INTO TABLE RAW_TABLE
FIELDS TERMINATED BY '~' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
(ID,
NAME,
CREATED_BY,
CREATED_DATETIME TIMESTAMP,
MODIFIED_BY,
MODIFIED_DATETIME TIMESTAMP)
答案 0 :(得分:0)
错误是由无声参数引起的。用单引号将其包装允许代码工作,如下所示:silent ='(HEADER,FEEDBACK)'