2014-10-06 114 views
0

您好我需要导出这些密钥值,IM geeting而出口,请分享你的想法,这样perl的数据未插入到Oracle数据库

Oct 1 06:25:45 github.com: { "pid":14428, "ppid":14397, "program":"upload-pack", "git_dir":"/data/repo/testorg/testrepo.git", "cmdline":"git-upload-pack --stateless-rpc .", "repo_name":"testrepo", "hostname":"github.com", "pusher":"testuserusha", "real_ip":"192.168.1.", "user_agent":"git/1.7.0", "transaction_id":"c0124fc145ffgwss677", "frontend":"github.com", "frontend_pid":20470, "frontend_ppid":20029, "repo_id":1355, "repo_public":true, "repo_guest_branches_enabled":false, "repo_config":"{}", "user_id":7068, "user_login":"testuser", "user_operator_mode":false, "pgroup":"13428", "status":"create_pack_file", "features":"", "cloning":true, "uploaded_bytes":4223321, "uploaded_bytes_rate":2929, "uploaded_bytes_last":1412222qq556 } 
Oct 2 06:35:45 github.com github_audit: {"actor_ip":"127.0.0.1","note":"From Git","user":"testuser","user_id":null,"actor":"testuser","actor_id":null,"org_id":null,"action":"user.failed_login","created_at":141225644589,"data":{"actor_location":{"location":{"lat":null,"lon":null}}}} 
Oct 2 06:40:45 github.com github_audit: {"actor_ip":"127.0.0.1","note":"From Git","user":"Username for 'https","user_id":null,"actor":"Username for 'https","actor_id":null,"org_id":null,"action":"user.failed_login","created_at":1412256464790,"data":{"actor_location":{"location":{"lat":null,"lon":null}}}} 

IM

我的数据文件不能添加完整的代码在这里

my @values = values %hash;  
my $dbh = DBI->connect("DBI:Oracle:host=$host;port=1500;SID=$sid",$user,$passwd);  
my $sth = $dbh->prepare("INSERT INTO AUDIT_TABLE(id, value) VALUES (?,?);");  
$sth->execute_array({},\@keys, \@values);  

输出

VALUE: 
DBD::Oracle::st execute_array failed: ORA-00911: invalid character (DBD ERROR: error possibly near <*> indicator at char 60 in 'INSERT INTO AUDIT_TABLE(id, value) VALUES (:p1,:p2)<*>;') [for Statement "INSERT INTO AUDIT_TABLE(id, value) VALUES (?,?);"] at 1.pl line 43, <IN> line 1. 

我用这个代码

my @values = @hash{qw(id value)}; 
my $dbh = DBI->connect("DBI:Oracle:host=$host;port=1521;SID=$sid",$user,$passwd); 
my $sth = $dbh->prepare("INSERT INTO AUDIT_TABLE(id, value) VALUES (?,?)"); 
$sth->execute_array({},\@keys, \@values); 

我收到此错误

DBD::Oracle::st execute_array failed: ORA-00911: invalid character (DBD ERROR: error possibly near <*> indicator at char 60 in 'INSERT INTO GITHUB_AUDIT_HISTORY(id, value) VALUES (:p1,:p2)<*>;') [for Statement "INSERT INTO AUDIT_TABLE(id, value) VALUES (?,?);"] at 1.pl line 44, <IN> line 1. 
+0

'我@values @hash {(id值)QW} =;'如果值责令此事查询。 – 2014-10-06 06:50:15

回答

1

问题是分号终止你的发言。 This isn't valid

SQL查询结尾的分号是SQL编辑器/命令行实用程序(例如SQL * Plus)的一个功能,而不是数据库本身。它们只能作为复合语句的一部分发送到服务器(例如BEGIN...END或创建过程)。

1

它的分号,它必须是这样的:

my $sth = $dbh->prepare("INSERT INTO GITHUB_AUDIT_HISTORY(id, value) VALUES (?,?)"); 
+0

感谢大家的建议 – organicuser 2014-10-06 11:13:58