您好,登錄后才能下訂單哦!
1.類型對比
oracle | mysql |
int | int |
number(6,2) | decimal(6,2) |
date (sysdate) | timestamp (now()) |
varchar2(20) | varchar(20) |
2.常用函數(shù)
/* DATE_FORMAT(date,format) 根據(jù)format字符串格式化date值 */ select date_format('2013-09-21 14:01:20','%Y-%m-%d %H:%i:%s') from dual; select case 2 when 1 then 1 when 2 then 2 else 0 end from dual; select IFNULL(null,0) from dual;
3.分頁
從第10條記錄開始檢索20條記錄
select * from sys_option limit 10,20; select * from table [查詢條件] order by id limit ?,?;
以下語句是先排序后的分頁(很好)
SELECT * FROM test_yutong ORDER BY ID DESC LIMIT 0,1;
order只能這么實現(xiàn)(沒有mysql方便)
SELECT * FROM(SELECT * FROM TABLE_A ORDER BY ID DESC)B WHERE ROWNUM=1;
4.自定義序列函數(shù)(來源 http://www.oschina.net/code/snippet_110375_12231)
/* CREATE TABLE Sequence */ DROP TABLE IF EXISTS Sequence; CREATE TABLE Sequence ( name VARCHAR(32), maxIndex INTEGER, CONSTRAINT cst_Sequence_pk PRIMARY KEY (name, maxIndex) ); /* FUNCTION nextval */ SET GLOBAL log_bin_trust_function_creators = 1; DROP FUNCTION IF EXISTS nextval; DELIMITER // CREATE FUNCTION nextval(sequenceName VARCHAR(32)) RETURNS INTEGER NOT DETERMINISTIC CONTAINS SQL BEGIN DECLARE iMaxIndex INTEGER; UPDATE Sequence SET maxIndex = maxIndex + 1 WHERE name = sequenceName; SELECT maxIndex INTO iMaxIndex FROM Sequence WHERE name = sequenceName; RETURN iMaxIndex; END // DELIMITER ;
/* 測試例子 */ INSERT INTO Sequence(NAME,maxIndex)VALUES('CK10_GHDJ',1); SELECT nextval('CK10_GHDJ')FROM DUAL; SELECT * FROM Sequence;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。