Welcome 微信登录

首页 / 数据库 / MySQL / MySQL与Oracle一些小区别

前几天做一个项目,本来是用MySQL的,但是项目需要Oracle库,后来我经过一个月时间,把整个程序全部换成了Oracle库,在操作过程中发现MySQL与Oracle的一些不同之处.1.MySQL的大文本可以直接进行读写,Oracle的不可以,Oracle的大文本数据类型是clob,更新和读写不能直接像MySQL一样,用insert 和 update.相关语句,我贴到下面.入库时:$query=oci_parse($conn,"INSERT INTO cms_article (title,subhead,abstract,keyword,source,author,releaseDate,rate,article_type,siteID,publisher,domurl3,website,lock_state,article_state,article_sort,hits,content) values ("".$_REQUEST["title"]."","".$_REQUEST["subhead"]."","".$_REQUEST["abstract"]."","".$_REQUEST["keyword"]."","".$_REQUEST["source"]."","".$_REQUEST["author"]."","".$releaseDate."","".$_REQUEST["rate"]."","".$col."","".$siteID."","".$_SESSION["username"]."","".$_REQUEST["domurl3"]."","".$_REQUEST["website"]."",1,3,1,1,EMPTY_CLOB()) RETURNING content INTO :mylob_loc");
$myLOB = oci_new_descriptor($conn, OCI_D_LOB);
oci_bind_by_name($query, ":mylob_loc", $myLOB, -1, OCI_B_CLOB);
$result=oci_execute($query,OCI_DEFAULT);
if ( !$myLOB->save($_REQUEST["content"])) {
//if ( !$myLOB->save("INSERT: ".date("H:i:s",time())) ) {
// On error, rollback the transaction
oci_rollback($conn);
} else {
// On success, commit the transaction
oci_commit($conn);
}
// Free resources
oci_free_statement($query);
$myLOB->free();
更新时:$exec=oci_parse($conn,"update cms_article set title = "".$_REQUEST["title"]."",subhead = "".$_REQUEST["subhead"]."",abstract = "".$_REQUEST["abstract"]."",keyword = "".$_REQUEST["keyword"]."",source = "".$_REQUEST["source"]."",author = "".$_REQUEST["author"]."",releaseDate = "".$releaseDate."",rate = "".$_REQUEST["rate"]."",article_state = 2,modified_name = "".$_SESSION["username"]."",domurl3 = "".$_REQUEST["domurl3"]."",website = "".$_REQUEST["website"]."" where id_article=".$_REQUEST["id"]."");
$result=oci_execute($exec);
$sql = "SELECT content FROM cms_article WHERE id_article = ".$_REQUEST["id"]." FOR UPDATE ";
$stmt = oci_parse($conn, $sql);
// Execute the statement using OCI_DEFAULT (begin a transaction)
oci_execute($stmt, OCI_DEFAULT)
or die ("Unable to execute query ");
// Fetch the SELECTed row
if ( FALSE === ($row = oci_fetch_assoc($stmt) ) ) {
oci_rollback($conn);
die ("Unable to fetch row ");
}
// Discard the existing LOB contents
if ( !$row["CONTENT"]->truncate() ) {
oci_rollback($conn);
die ("Failed to truncate LOB ");
}
// Now save a value to the LOB
if ( !$row["CONTENT"]->save($_REQUEST["content"]) ) {
// On error, rollback the transaction
oci_rollback($conn);
} else {
// On success, commit the transaction
oci_commit($conn);
}
// Free resources
oci_free_statement($stmt);
$row["CONTENT"]->free();2.MySQL在表里可以设一个自增,而Oracle里只能用序列和触发器来实现.如果要做Oracle项目时,尽量用唯一来关联,少用自增,因为太麻烦了InnoDB与Oracle单行存储长度对比Ubuntu下成功安装Oracle学习备忘录相关资讯      mysql 
  • 数据库服务器 MySQL  (08/15/2013 06:50:23)
  • MySQL 5.6 GA 及逃亡潮  (02/08/2013 14:36:35)
  • MySQL 5.5.22、5.1.62、5.0.96全线  (03/22/2012 19:03:49)
  • MySQL Administrator连接VMWare下  (05/24/2013 09:20:58)
  • MySQL 5.1.68 发布  (02/05/2013 08:37:47)
  • CentOS 5.2+MySQL+Heartbeat双机互  (01/29/2012 11:16:55)
本文评论 查看全部评论 (0)
表情: 姓名: 字数