<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technical LeoLo &#187; Oracle</title>
	<atom:link href="http://blog.leolo.cc/labels/oracle/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.leolo.cc</link>
	<description>My Learning note</description>
	<lastBuildDate>Thu, 12 Mar 2009 08:58:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>在Oracle中找出重複的紀錄的方法</title>
		<link>http://blog.leolo.cc/2008/05/06/15/</link>
		<comments>http://blog.leolo.cc/2008/05/06/15/#comments</comments>
		<pubDate>Tue, 06 May 2008 06:38:00 +0000</pubDate>
		<dc:creator>leolo</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[duplicate]]></category>
		<category><![CDATA[PLSQL]]></category>

		<guid isPermaLink="false">http://leolo.wordpress.com/2008/05/06/%e5%9c%a8oracle%e4%b8%ad%e6%89%be%e5%87%ba%e9%87%8d%e8%a4%87%e7%9a%84%e7%b4%80%e9%8c%84%e7%9a%84%e6%96%b9%e6%b3%95/</guid>
		<description><![CDATA[在Oracle中找出重複的紀錄的方法SELECT aid FROM atable GROUP BY aid HAVING COUNT(*) &#62;1;
刪除重複的記錄DELETE FROM atable a where a.ROWID!=(SELECT MAX(ROWID) FROM atable b WHERE a.aid=b.aid;
]]></description>
		<wfw:commentRss>http://blog.leolo.cc/2008/05/06/15/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在ORACLE/PLSQL裡使用游標FOR迴圈(cursor FOR loop)</title>
		<link>http://blog.leolo.cc/2008/05/06/14/</link>
		<comments>http://blog.leolo.cc/2008/05/06/14/#comments</comments>
		<pubDate>Tue, 06 May 2008 05:55:00 +0000</pubDate>
		<dc:creator>leolo</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[cursor]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[PLSQL]]></category>

		<guid isPermaLink="false">http://leolo.wordpress.com/2008/05/06/%e5%9c%a8oracleplsql%e8%a3%a1%e4%bd%bf%e7%94%a8%e6%b8%b8%e6%a8%99for%e8%bf%b4%e5%9c%88cursor-for-loop/</guid>
		<description><![CDATA[藉由從abc_stu資料表內抓取該學號的生日，來更新stu資料表裡每個學號的生日。
DECLARE   CURSOR cur IS       SELECT stuid FROM stu;BEGIN   FOR rec IN cur   LOOP        UPDATE stu           SET (birth_yr,birth_mm,birth_dd)=          [...]]]></description>
		<wfw:commentRss>http://blog.leolo.cc/2008/05/06/14/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle/PLSQL: If Exists Update Else Insert</title>
		<link>http://blog.leolo.cc/2008/05/04/13/</link>
		<comments>http://blog.leolo.cc/2008/05/04/13/#comments</comments>
		<pubDate>Sun, 04 May 2008 06:35:00 +0000</pubDate>
		<dc:creator>leolo</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[exist]]></category>
		<category><![CDATA[insert]]></category>
		<category><![CDATA[PLSQL]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://leolo.wordpress.com/2008/05/04/oracleplsql-if-exists-update-else-insert/</guid>
		<description><![CDATA[If data exists then update it, otherwise insert it.In Oracle/PLSQL
BEGINUPDATE TABLE_NAME SET COL=&#8217;a&#8217; WHERE ID=&#8217;foobar&#8217;;IF sql%rowcount = 0 THENINSERT INTO TABLE_NAME (ID,COL) VALUES(&#8216;foobar&#8217;,'a&#8217;);END IF;END;
]]></description>
		<wfw:commentRss>http://blog.leolo.cc/2008/05/04/13/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle中設定auto increment的一些相關筆記</title>
		<link>http://blog.leolo.cc/2008/04/10/11/</link>
		<comments>http://blog.leolo.cc/2008/04/10/11/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 06:36:00 +0000</pubDate>
		<dc:creator>leolo</dc:creator>
				<category><![CDATA[Oracle]]></category>
		<category><![CDATA[auto increment]]></category>
		<category><![CDATA[sequence]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[trigger]]></category>
		<category><![CDATA[truncate]]></category>

		<guid isPermaLink="false">http://leolo.wordpress.com/2008/04/10/oracle%e4%b8%ad%e8%a8%ad%e5%ae%9aauto-increment%e7%9a%84%e4%b8%80%e4%ba%9b%e7%9b%b8%e9%97%9c%e7%ad%86%e8%a8%98/</guid>
		<description><![CDATA[清空資料表
truncate table TABLE_NAME;
設定Auto Increment參考資料：http://www.lifeaftercoffee.com/2006/02/17/how-to-create-auto-increment-columns-in-oracle/
先建立一個sequence
create sequence SEQUENCE_NAMEstart with 1increment by 1nocache;
再建立一個trigger
create or replace trigger TRIGGER_NAMEbefore inserton TABLE_NAMEreferencing NEW as NEWfor each rowbeginselect SEQUENCE_NAME.nextval into :NEW.AUTO_INCREMENT_COLUMN from dual;end;/
這樣就完成了
SEQUENCE有下列參數：MINVALUE、MAXVALUE、START WITH、INCREMENT BY、CACHE、NOCACHE、CYCLE
要加nocache，sequence才不會亂跳
SEQUENCE到達最大值之前不能重新計數，只能用DROP刪除後再重新CREATE建立。可以用ALTER來修改SEQUENCE的參數
ALTER SEQUENCE seq01INCREMENT BY 100;
用NEXTVAL取得下一個值
SELECT seq01.NEXTVAL FROM DUAL;
用CURRVAL取的目前值
SELECT seq01.CURRVAL FROM DUAL;

]]></description>
		<wfw:commentRss>http://blog.leolo.cc/2008/04/10/11/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
