내가하려고하는 것은 oracle의 쿼리 결과를 MySQL 데이터베이스의 테이블에 복사하는 것입니다. 이것에 대한 추론은 그 질문에 중요하지 않으며, 나는 정말로 다른 접근법을 취할 수 없습니다.오라클 결과 집합을 MySQL로 복사 할 때의 문제
내가하고있는 일은 php를 통해 쿼리를 실행 한 다음 결과를 oracle의 새로 생성 된 테이블에 복사하는 것입니다. 이것은 매우 효율적이지는 않지만 쿼리가 매우 오래 실행 되더라도 테이블 크기는 매우 작다는 것을 알고 있습니다.
오라클에서 데이트를 가져 오는 데 문제가 있습니다. 내가 그것을 실행하면 내 날짜 필드는 0으로 설정됩니다. 내가하고있는 일은 오라클의 결과 집합을 검사하여 열 유형이 "DATE (7)"인지 확인한 다음 "DATE"타입의 MySQL 컬럼. 그러나 어떤 이유로이 방법은 효과가 없습니다.
다음 코드를 사용하고 있습니다. 죄송합니다. 길지만 아주 좋습니다.
function hmis_query_transfer ($query_name, $parameters = NULL) {
//Create Connections to both servers
$dbConn_Oracle = hmis_oci_connect();
hmis_mysql_connect("hmis_temp");
//Retrieve the text for the query and run it on the Oracle server
$query_Oracle = hmis_query_by_name($query_name, $parameters);
$stmt_Oracle = hmis_oci_query($dbConn_Oracle , $query_Oracle);
$ncols = oci_num_fields($stmt_Oracle);
//Test if table is already created in MySQL
$mysql_check = "DESC ".$query_name;
@hmis_mysql_query($mysql_check);
if (mysql_errno()==1146){
$mysql_create = "CREATE TABLE ".$query_name." (";
//Transform and append column names to query string
for ($j = 1; $j <= $ncols; $j++) {
$name = oci_field_name($stmt_Oracle, $j);
$type = oci_field_type($stmt_Oracle, $j);
if ($type == "NUMBER") {
$type = "INT";
} else if ($type == "VARCHAR2"){
$type = "VARCHAR";
}
$type .= "(".oci_field_size($stmt_Oracle, $j).")";
if ($type == "DATE(7)") {
$type = "DATE";
}
$mysql_create .= $name." ".$type.",";
}
$mysql_create = substr_replace($mysql_create, "", -1);
$mysql_create .= ')';
//Create Table
$result = hmis_mysql_query($mysql_create);
if (!$result){
die('<strong>Failed Create:</strong>'.mysql_error());
}
}
elseif (!mysql_errno()) {
//If the table already exists, empty it
$mysql_truncate = "TRUNCATE TABLE ".$query_name;
$result = hmis_mysql_query($mysql_truncate);
if (!$result){
die('<strong>Failed Truncate:</strong>'.mysql_error());
}
}
//Copy over row by row the data from the result set to MySQL
while ($results_row = oci_fetch_array($stmt_Oracle, OCI_ASSOC)) {
$mysql_insert = "INSERT INTO ".$query_name." VALUES (";
for ($i = 1; $i <= $ncols; $i++) {
$mysql_insert .= "'".$results_row[oci_field_name($stmt_Oracle, $i)]."',";
}
$mysql_insert = substr_replace($mysql_insert, "", -1);
$mysql_insert .= ")";
$result = hmis_mysql_query($mysql_insert);
if (!$result){
die('<strong>Failed Insert:</strong>'.mysql_error());
}
}
}
누구든지 내 코드의 결함을 볼 수 있습니까? 나는 내 코드를 유지할 수 있기를 원하지만 어떻게 다른 방식으로이 작업을 수행 할 수 있는지 제안합니다. 어떤 도움을 주셔서 감사합니다.
내가 MySQL을 오라클에서 데이터를 복사하고있어 그 이유는 쿼리의 대부분은 재치 거대한 데이터 세트 (2 억) (15 ~ 20 분) 실행하고 처리하는 것은 매우 오랜 시간이 걸리지 만, 때문에 내 결과 집합 매우 작습니다 (많아야 수천). 내 애플리케이션이 구축 된 방식은 동일한 데이터 세트에서 반복 쿼리를 실행하여 작업을 완료해야합니다. 나는 오라클에서 이것을 달성하기위한 견해를 만들고 싶었지만 그렇게 할 수있는 권한이 없다. 따라서 중간 계층 결과 집합을 저장하고 훨씬 더 빠른 시스템에서 발생하는 내 분석을 수행합니다.
"놀랍지 만, 당신이 엉덩이를 뒤로 할 수있는 간단한 일을 정말 좋아하지는 않았습니다." Dixie Flatline, * Neuromancer * – APC