﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-似水流年-文章分类-Oracle</title><link>http://www.blogjava.net/huhu/category/9422.html</link><description>Huhu'Blog</description><language>zh-cn</language><lastBuildDate>Wed, 28 Feb 2007 13:51:49 GMT</lastBuildDate><pubDate>Wed, 28 Feb 2007 13:51:49 GMT</pubDate><ttl>60</ttl><item><title>NVL Function【Oracle/PLSQL】（转载）</title><link>http://www.blogjava.net/huhu/articles/39362.html</link><dc:creator>似水流年</dc:creator><author>似水流年</author><pubDate>Wed, 05 Apr 2006 05:38:00 GMT</pubDate><guid>http://www.blogjava.net/huhu/articles/39362.html</guid><wfw:comment>http://www.blogjava.net/huhu/comments/39362.html</wfw:comment><comments>http://www.blogjava.net/huhu/articles/39362.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huhu/comments/commentRss/39362.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huhu/services/trackbacks/39362.html</trackback:ping><description><![CDATA[
		<p>In Oracle/PLSQL, the <b>NVL</b> function lets you substitute a value when a null value is encountered.</p>
		<p>The syntax for the <b>NVL</b> function is:</p>
		<blockquote>
				<blockquote class="definition">
						<p>NVL( string1, replace_with )</p>
				</blockquote>
		</blockquote>
		<p>
				<i>string1</i> is the string to test for a null value.</p>
		<p>
				<i>replace_with</i> is the value returned if <i>string1</i> is null.</p>
		<br />
		<p>
				<u>Example #1:</u>
		</p>
		<blockquote class="sql_command">
				<p>select NVL(supplier_city, 'n/a')<br />from suppliers;</p>
		</blockquote>
		<p>The SQL statement above would return 'n/a' if the supplier_city field contained a null value. Otherwise, it would return the supplier_city value.</p>
		<br />
		<p>
				<u>Example #2:</u>
		</p>
		<blockquote class="sql_command">
				<p>select supplier_id,<br />NVL(supplier_desc, supplier_name)<br />from suppliers;</p>
		</blockquote>
		<p>This SQL statement would return the <i>supplier_name</i> field if the <i>supplier_desc</i> contained a null value. Otherwise, it would return the <i>supplier_desc</i>.</p>
		<br />
		<p>
				<u>Example #3:</u>
		</p>
		<blockquote class="sql_command">
				<p>select NVL(commission, 0)<br />from sales;</p>
		</blockquote>
		<p>This SQL statement would return 0 if the <i>commission</i> field contained a null value. Otherwise, it would return the <i>commission</i> field.</p>
		<br />
		<h2>Frequently Asked Questions</h2>
		<hr />
		<p>
				<b>Question</b>:  I tried to use the NVL function through VB to access Oracle DB.</p>
		<p>To be precise,</p>
		<blockquote>
				<p>select NVL(DIstinct (emp_name),'AAA'),................ from.................</p>
		</blockquote>
		<p>I got an oracle error when I use distinct clause with NVL, but when I remove distinct it works fine.</p>
		<p>
				<b>Answer</b>:  It is possible to the use the DISTINCT clause with the NVL function. However, the DISTINCT must come before the use of the NVL function. For example:</p>
		<blockquote class="sql_command">
				<p>select distinct NVL(emp_name, 'AAA')<br />from employees;</p>
		</blockquote>
		<p>Hope this helps!</p>
		<hr />
		<p>
				<b>Question</b>:  Is it possible to use the NVL function with more than one column with the same function call?  To be clear, if i need to apply this NVL function to more than one column like this:</p>
		<blockquote>
				<p>NVL(column1;column2 ...... , here is the default value for all )</p>
		</blockquote>
		<p>
				<b>Answer</b>:  You will need to make separate NVL function calls for each column. For example:</p>
		<blockquote class="sql_command">
				<p>select NVL(table_name, 'not found'), NVL(owner, 'not found')<br />from all_tables;</p>
		</blockquote>
		<!-- InstanceEndEditable -->
<img src ="http://www.blogjava.net/huhu/aggbug/39362.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huhu/" target="_blank">似水流年</a> 2006-04-05 13:38 <a href="http://www.blogjava.net/huhu/articles/39362.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Decode Function【Oracle/PLSQL】（转载）</title><link>http://www.blogjava.net/huhu/articles/39124.html</link><dc:creator>似水流年</dc:creator><author>似水流年</author><pubDate>Tue, 04 Apr 2006 04:51:00 GMT</pubDate><guid>http://www.blogjava.net/huhu/articles/39124.html</guid><wfw:comment>http://www.blogjava.net/huhu/comments/39124.html</wfw:comment><comments>http://www.blogjava.net/huhu/articles/39124.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huhu/comments/commentRss/39124.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huhu/services/trackbacks/39124.html</trackback:ping><description><![CDATA[
		<p>In Oracle/PLSQL, the <b>decode</b> function has the functionality of an IF-THEN-ELSE statement.</p>
		<p>The syntax for the <b>decode</b> function is:</p>
		<blockquote>
				<blockquote class="definition">
						<p>decode( expression , search , result [, search , result]... [, default] )</p>
				</blockquote>
		</blockquote>
		<p>
				<i>expression</i> is the value to compare.</p>
		<p>
				<i>search</i> is the value that is compared against <i>expression</i>.</p>
		<p>
				<i>result</i> is the value returned, if <i>expression</i> is equal to <i>search</i>.</p>
		<p>
				<i>default</i> is optional. If no matches are found, the decode will return <i>default</i>. If <i>default</i> is omitted, then the decode statement will return null (if no matches are found).</p>
		<br />
		<p>
				<u>For Example:</u>
		</p>
		<p>You could use the decode function in an SQL statement as follows:</p>
		<blockquote>
				<div align="left">
						<table class="sql_command" cellspacing="0" cellpadding="0" width="400" border="0">
								<tbody>
										<tr>
												<td width="398" colspan="3">SELECT supplier_name,</td>
										</tr>
										<tr>
												<td width="121">decode(supplier_id,</td>
												<td width="47">10000,</td>
												<td width="226">'IBM',</td>
										</tr>
										<tr>
												<td width="121">
												</td>
												<td width="47">10001,</td>
												<td width="226">'Microsoft',</td>
										</tr>
										<tr>
												<td width="121">
												</td>
												<td width="47">10002,</td>
												<td width="226">'Hewlett Packard',</td>
										</tr>
										<tr>
												<td width="121">
												</td>
												<td width="47">
												</td>
												<td width="226">'Gateway') result</td>
										</tr>
										<tr>
												<td width="398" colspan="3">FROM suppliers;</td>
										</tr>
								</tbody>
						</table>
				</div>
		</blockquote>
		<br />
		<p>The above decode statement is equivalent to the following IF-THEN-ELSE statement:</p>
		<blockquote class="sql_command">
				<p>IF supplier_id = 10000 THEN<br />     result := 'IBM';</p>
				<p>ELSIF supplier_id = 10001 THEN<br />    result := 'Microsoft';</p>
				<p>ELSIF supplier_id = 10002 THEN<br />    result := 'Hewlett Packard';</p>
				<p>ELSE<br />    result := 'Gateway';</p>
				<p>END IF;</p>
		</blockquote>
		<br />
		<p>The decode function will compare each supplier_id value, one by one.</p>
		<br />
		<h2>Frequently Asked Questions</h2>
		<hr />
		<p>
				<b>Question</b>:  One of our viewers wanted to know how to use the decode function to compare two dates (ie: date1 and date2), where if date1 &gt; date2, the decode function should return date2. Otherwise, the decode function should return date1.</p>
		<p>
				<b>Answer</b>:  To accomplish this, use the decode function as follows:</p>
		<blockquote class="sql_command">
				<p>decode((date1 - date2) - abs(date1 - date2), 0, date2, date1)</p>
		</blockquote>
		<p>The formula below would equal 0, if date1 is greater than date2:</p>
		<blockquote>
				<p>(date1 - date2) - abs(date1 - date2)</p>
		</blockquote>
		<hr />
		<p>
				<b>Question</b>:  I would like to know if it's possible to use decode for ranges of numbers, ie 1-10 = 'category 1', 11-20 = 'category 2', rather than having to individually decode each number.</p>
		<p>
				<b>Answer</b>: Unfortunately, you can not use the decode for ranges of numbers. However, you can try to create a formula that will evaluate to one number for a given range, and another number for the next range, and so on.</p>
		<p>For example:</p>
		<blockquote>
				<div align="left">
						<table class="sql_command" cellspacing="0" cellpadding="0" width="443" border="0">
								<tbody>
										<tr>
												<td width="398" colspan="3">SELECT supplier_id,</td>
										</tr>
										<tr>
												<td width="221">decode(trunc ((supplier_id - 1) / 10),</td>
												<td width="38">0,</td>
												<td width="178">'category 1',</td>
										</tr>
										<tr>
												<td width="221">
												</td>
												<td width="38">1,</td>
												<td width="178">'category 2',</td>
										</tr>
										<tr>
												<td width="221">
												</td>
												<td width="38">2,</td>
												<td width="178">'category 3',</td>
										</tr>
										<tr>
												<td width="221">
												</td>
												<td width="38">
												</td>
												<td width="178">'unknown') result</td>
										</tr>
										<tr>
												<td width="398" colspan="3">FROM suppliers;</td>
										</tr>
								</tbody>
						</table>
				</div>
		</blockquote>
		<p>In this example, based on the formula:</p>
		<blockquote>
				<p>trunc ((supplier_id - 1) / 10</p>
		</blockquote>
		<p>The formula will evaluate to 0, if the supplier_id is between 1 and 10.<br />The formula will evaluate to 1, if the supplier_id is between 11 and 20.<br />The formula will evaluate to 2, if the supplier_id is between 21 and 30.</p>
		<p>and so on...</p>
		<hr />
		<p>
				<b>Question</b>:  I need to write a decode statement that will return the following:</p>
		<blockquote>
				<p>If yrs_of_service &lt; 1 then return 0.04<br />If yrs_of_service &gt;= 1 and &lt; 5 then return 0.04<br />If yrs_of_service &gt; 5 then return 0.06</p>
		</blockquote>
		<p>How can I do this?</p>
		<p>
				<b>Answer</b>:  You will need to create a formula that will evaluate to a single number for each one of your ranges.</p>
		<p>For example:</p>
		<blockquote>
				<table class="sql_command" cellspacing="0" cellpadding="0" width="443" border="0">
						<tbody>
								<tr>
										<td width="398" colspan="3">SELECT emp_name,</td>
								</tr>
								<tr>
										<td width="235">decode(trunc (( yrs_of_service + 3) / 4),</td>
										<td width="24">0,</td>
										<td width="178">0.04,</td>
								</tr>
								<tr>
										<td width="235">
										</td>
										<td width="24">1,</td>
										<td width="178">0.04,</td>
								</tr>
								<tr>
										<td width="235">
										</td>
										<td width="24">
										</td>
										<td width="178">0.06) as perc_value</td>
								</tr>
								<tr>
										<td width="398" colspan="3">FROM employees;</td>
								</tr>
						</tbody>
				</table>
		</blockquote>
		<hr />
		<p>
				<b>Helpful Tip</b>: One of our viewers suggested combining the <a href="http://www.techonthenet.com/oracle/functions/sign.php"><font color="#002c99">SIGN function</font></a> with the DECODE function as follows:</p>
		<p>The date example above could be modified as follows:</p>
		<blockquote class="sql_command">
				<p>DECODE(SIGN(date1-date2), 1, date2, date1)</p>
		</blockquote>
		<p>The SIGN/DECODE combination is also helpful for numeric comparisons e.g. Sales Bonuses</p>
		<blockquote class="sql_command">
				<p>DECODE(SIGN(actual-target), -1, 'NO Bonus for you', 0,'Just made it', 1, 'Congrats, you are a winner')</p>
		</blockquote>
		<!-- InstanceEndEditable -->
<img src ="http://www.blogjava.net/huhu/aggbug/39124.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huhu/" target="_blank">似水流年</a> 2006-04-04 12:51 <a href="http://www.blogjava.net/huhu/articles/39124.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>To_Char Function【Oracle/PLSQL:】（转载）</title><link>http://www.blogjava.net/huhu/articles/39100.html</link><dc:creator>似水流年</dc:creator><author>似水流年</author><pubDate>Tue, 04 Apr 2006 02:33:00 GMT</pubDate><guid>http://www.blogjava.net/huhu/articles/39100.html</guid><wfw:comment>http://www.blogjava.net/huhu/comments/39100.html</wfw:comment><comments>http://www.blogjava.net/huhu/articles/39100.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huhu/comments/commentRss/39100.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huhu/services/trackbacks/39100.html</trackback:ping><description><![CDATA[
		<p>In Oracle/PLSQL, the <b>to_char</b> function converts a number or date to a string.</p>
		<p>The syntax for the <b>to_char</b> function is:</p>
		<blockquote>
				<blockquote class="definition">
						<p>to_char( value, [ format_mask ], [ nls_language ] )</p>
				</blockquote>
		</blockquote>
		<p>
				<i>value</i> can either be a number or date that will be converted to a string.</p>
		<p>
				<i>format_mask</i> is optional. This is the format that will be used to convert <i>value</i> to a string.</p>
		<p>
				<i>nls_language</i> is optional. This is the nls language used to convert <i>value</i> to a string.</p>
		<br />
		<h2>Examples - Numbers</h2>
		<p>The following are number examples for the <b>to_char</b> function.</p>
		<blockquote>
				<table cellspacing="0" cellpadding="3" width="432" border="0">
						<tbody>
								<tr>
										<td class="function_example" width="207">to_char(1210.73, '9999.9')</td>
										<td class="function_desc">would return '1210.7'</td>
								</tr>
								<tr>
										<td class="function_example">to_char(1210.73, '9,999.99')</td>
										<td class="function_desc">would return '1,210.73'</td>
								</tr>
								<tr>
										<td class="function_example">to_char(1210.73, '$9,999.00')</td>
										<td class="function_desc">would return '$1,210.73'</td>
								</tr>
								<tr>
										<td class="function_example">to_char(21, '000099')</td>
										<td class="function_desc">would return '000021'</td>
								</tr>
						</tbody>
				</table>
		</blockquote>
		<br />
		<h2>Examples - Dates</h2>
		<p>The following is a list of valid parameters when the <b>to_char</b> function is used to convert a date to a string. These parameters can be used in many combinations.</p>
		<blockquote>
				<table class="parm_values" cellspacing="0" cellpadding="3" width="500" border="1">
						<tbody>
								<tr class="th_left_top">
										<th width="93">Parameter</th>
										<th>Explanation</th>
								</tr>
								<tr class="tr_left_top">
										<td>YEAR</td>
										<td>Year, spelled out</td>
								</tr>
								<tr class="tr_left_top">
										<td>YYYY</td>
										<td>4-digit year</td>
								</tr>
								<tr class="tr_left_top">
										<td>YYY<br />YY<br />Y</td>
										<td>Last 3, 2, or 1 digit(s) of year.</td>
								</tr>
								<tr class="tr_left_top">
										<td>IYY<br />IY<br />I</td>
										<td>Last 3, 2, or 1 digit(s) of ISO year.</td>
								</tr>
								<tr class="tr_left_top">
										<td>IYYY</td>
										<td>4-digit year based on the ISO standard</td>
								</tr>
								<tr class="tr_left_top">
										<td>Q</td>
										<td>Quarter of year (1, 2, 3, 4; JAN-MAR = 1).</td>
								</tr>
								<tr class="tr_left_top">
										<td>MM</td>
										<td>Month (01-12; JAN = 01).</td>
								</tr>
								<tr class="tr_left_top">
										<td>MON</td>
										<td>Abbreviated name of month.</td>
								</tr>
								<tr class="tr_left_top">
										<td>MONTH</td>
										<td>Name of month, padded with blanks to length of 9 characters.</td>
								</tr>
								<tr class="tr_left_top">
										<td>RM</td>
										<td>Roman numeral month (I-XII; JAN = I).</td>
								</tr>
								<tr class="tr_left_top">
										<td>WW</td>
										<td>Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.</td>
								</tr>
								<tr class="tr_left_top">
										<td>W</td>
										<td>Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.</td>
								</tr>
								<tr class="tr_left_top">
										<td>IW</td>
										<td>Week of year (1-52 or 1-53) based on the ISO standard.</td>
								</tr>
								<tr class="tr_left_top">
										<td>D</td>
										<td>Day of week (1-7).</td>
								</tr>
								<tr class="tr_left_top">
										<td>DAY</td>
										<td>Name of day.</td>
								</tr>
								<tr class="tr_left_top">
										<td>DD</td>
										<td>Day of month (1-31).</td>
								</tr>
								<tr class="tr_left_top">
										<td>DDD</td>
										<td>Day of year (1-366).</td>
								</tr>
								<tr class="tr_left_top">
										<td>DY</td>
										<td>Abbreviated name of day.</td>
								</tr>
								<tr class="tr_left_top">
										<td>J</td>
										<td>Julian day; the number of days since January 1, 4712 BC.</td>
								</tr>
								<tr class="tr_left_top">
										<td>HH</td>
										<td>Hour of day (1-12).</td>
								</tr>
								<tr class="tr_left_top">
										<td>HH12</td>
										<td>Hour of day (1-12).</td>
								</tr>
								<tr class="tr_left_top">
										<td>HH24</td>
										<td>Hour of day (0-23).</td>
								</tr>
								<tr class="tr_left_top">
										<td>MI</td>
										<td>Minute (0-59).</td>
								</tr>
								<tr class="tr_left_top">
										<td>SS</td>
										<td>Second (0-59).</td>
								</tr>
								<tr class="tr_left_top">
										<td>SSSSS</td>
										<td>Seconds past midnight (0-86399).</td>
								</tr>
								<tr class="tr_left_top">
										<td>FF</td>
										<td>Fractional seconds.</td>
								</tr>
						</tbody>
				</table>
		</blockquote>
		<br />
		<p>The following are date examples for the <b>to_char</b> function.</p>
		<blockquote>
				<table cellspacing="0" cellpadding="3" width="460" border="0">
						<tbody>
								<tr>
										<td class="function_example" width="253">to_char(sysdate, 'yyyy/mm/dd');</td>
										<td class="function_desc">would return '2003/07/09'</td>
								</tr>
								<tr>
										<td class="function_example">to_char(sysdate, 'Month DD, YYYY');</td>
										<td class="function_desc">would return 'July 09, 2003'</td>
								</tr>
								<tr>
										<td class="function_example">to_char(sysdate, 'FMMonth DD, YYYY');</td>
										<td class="function_desc">would return 'July 9, 2003'</td>
								</tr>
								<tr>
										<td class="function_example">to_char(sysdate, 'MON DDth, YYYY');</td>
										<td class="function_desc">would return 'JUL 09TH, 2003'</td>
								</tr>
								<tr>
										<td class="function_example">to_char(sysdate, 'FMMON DDth, YYYY');</td>
										<td class="function_desc">would return 'JUL 9TH, 2003'</td>
								</tr>
								<tr>
										<td class="function_example">to_char(sysdate, 'FMMon ddth, YYYY');</td>
										<td class="function_desc">would return 'Jul 9th, 2003'</td>
								</tr>
						</tbody>
				</table>
		</blockquote>
		<br />
		<p>You will notice that in some examples, the <i>format_mask</i> parameter begins with "FM". This means that zeros and blanks are suppressed. This can be seen in the examples below.</p>
		<blockquote>
				<table cellspacing="0" cellpadding="3" width="460" border="0">
						<tbody>
								<tr>
										<td class="function_example" width="253">to_char(sysdate, 'FMMonth DD, YYYY');</td>
										<td class="function_desc">would return 'July 9, 2003'</td>
								</tr>
								<tr>
										<td class="function_example">to_char(sysdate, 'FMMON DDth, YYYY');</td>
										<td class="function_desc">would return 'JUL 9TH, 2003'</td>
								</tr>
								<tr>
										<td class="function_example">to_char(sysdate, 'FMMon ddth, YYYY');</td>
										<td class="function_desc">would return 'Jul 9th, 2003'</td>
								</tr>
						</tbody>
				</table>
		</blockquote>
		<p>The zeros have been suppressed so that the day component shows as "9" as opposed to "09".</p>
		<br />
		<h2>Frequently Asked Questions</h2>
		<hr />
		<p>
				<b>Question</b>:  Why doesn't this sort the day's of the week in order?</p>
		<blockquote>
				<p>select ename, hiredate, to_char((hiredate),'fmDay') "Day"<br />from emp<br />order by "Day";</p>
		</blockquote>
		<p>
				<b>Answer</b>:</p>
		<p>The fmDay parameter will return the name of the Day and not the numeric value of the day.<br />Try the following:</p>
		<blockquote class="sql_command">
				<p>select ename, hiredate, to_char((hiredate),'fmDD') "Day"<br />from emp<br />order by "Day";</p>
		</blockquote>
		<!-- InstanceEndEditable -->
<img src ="http://www.blogjava.net/huhu/aggbug/39100.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huhu/" target="_blank">似水流年</a> 2006-04-04 10:33 <a href="http://www.blogjava.net/huhu/articles/39100.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Coalesce Function【Oracle/PLSQL】（转载）</title><link>http://www.blogjava.net/huhu/articles/39094.html</link><dc:creator>似水流年</dc:creator><author>似水流年</author><pubDate>Tue, 04 Apr 2006 02:15:00 GMT</pubDate><guid>http://www.blogjava.net/huhu/articles/39094.html</guid><wfw:comment>http://www.blogjava.net/huhu/comments/39094.html</wfw:comment><comments>http://www.blogjava.net/huhu/articles/39094.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huhu/comments/commentRss/39094.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huhu/services/trackbacks/39094.html</trackback:ping><description><![CDATA[
		<p>In Oracle/PLSQL, the <b>coalesce</b> function returns the first non-null expression in the list. If all expressions evaluate to null, then the coalesce function will return null.</p>
		<p>The syntax for the <b>coalesce</b> function is:</p>
		<blockquote>
				<blockquote class="definition">
						<p>coalesce( expr1, expr2, ... expr_n )</p>
				</blockquote>
		</blockquote>
		<br />
		<p>
				<u>For Example:</u>
		</p>
		<p>You could use the coalesce function in an SQL statement as follows:</p>
		<blockquote class="sql_command">
				<p>SELECT coalesce( address1, address2, address3 ) result<br />FROM suppliers;</p>
		</blockquote>
		<br />
		<p>The above coalesce statement is equivalent to the following IF-THEN-ELSE statement:</p>
		<blockquote class="sql_command">
				<p>IF address1 is not null THEN<br />     result := address1;</p>
				<p>ELSIF address2 is not null THEN<br />    result := address2;</p>
				<p>ELSIF address3 is not null THEN<br />    result := address3;</p>
				<p>ELSE<br />    result := null;</p>
				<p>END IF;</p>
		</blockquote>
		<br />
		<p>The coalesce function will compare each value, one by one.</p>
		<!-- InstanceEndEditable -->
<img src ="http://www.blogjava.net/huhu/aggbug/39094.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huhu/" target="_blank">似水流年</a> 2006-04-04 10:15 <a href="http://www.blogjava.net/huhu/articles/39094.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>String Functions【Oracle】(转载)</title><link>http://www.blogjava.net/huhu/articles/39080.html</link><dc:creator>似水流年</dc:creator><author>似水流年</author><pubDate>Tue, 04 Apr 2006 01:25:00 GMT</pubDate><guid>http://www.blogjava.net/huhu/articles/39080.html</guid><wfw:comment>http://www.blogjava.net/huhu/comments/39080.html</wfw:comment><comments>http://www.blogjava.net/huhu/articles/39080.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huhu/comments/commentRss/39080.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huhu/services/trackbacks/39080.html</trackback:ping><description><![CDATA[
		<br />
		<table width="80%" bgcolor="#d8d8c4" border="1">
				<tbody>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>ASCII</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Get The ASCII Value Of A Character</font>
								</td>
								<td width="75%">
										<font face="Courier">ASCII(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">ASCII</font>('A') FROM dual;<br />SELECT <font color="#0000ff">ASCII</font>('Z') FROM dual;<br />SELECT <font color="#0000ff">ASCII</font>('a') FROM dual;<br />SELECT <font color="#0000ff">ASCII</font>('z') FROM dual;<br />SELECT <font color="#0000ff">ASCII</font>(' ') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>CASE Related Functions</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Upper Case</font>
								</td>
								<td width="75%">
										<font face="Courier">UPPER(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">UPPER</font>('Dan Morgan') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Lower Case</font>
								</td>
								<td width="75%">
										<font face="Courier">LOWER(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">LOWER</font>('Dan Morgan') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Initial Letter Upper Case</font>
								</td>
								<td width="75%">
										<font face="Courier">INITCAP(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">INITCAP</font>('DAN MORGAN') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">NLS Upper Case</font>
								</td>
								<td width="75%">
										<font face="Courier">NLS_UPPER(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">NLS_UPPER</font>('Dan Morgan', 'NLS_SORT = XDanish')<br />FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">NLS Lower Case</font>
								</td>
								<td width="75%">
										<font face="Courier">NLS_LOWER(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">NLS_LOWER</font>('Dan Morgan', 'NLS_SORT = XFrench')<br />FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">NLS Initial Letter Upper Case</font>
								</td>
								<td width="75%">
										<font face="Courier">NLS_INITCAP(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">NLS_INITCAP</font>('DAN MORGAN', 'NLS_SORT = XGerman')<br />FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>CHR</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Character</font>
								</td>
								<td width="75%">
										<font face="Courier">CHR(&lt;ascii_string_or_column&gt;&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT(<font color="#0000ff">CHR</font>(68) || <font color="#0000ff">CHR</font>(65) || <font color="#0000ff">CHR</font>(78)) FROM dual;<br /><br />SELECT(<font color="#0000ff">CHR</font>(68) || <font color="#0000ff">CHR</font>(97) || <font color="#0000ff">CHR</font>(110)) FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>COALESCE</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Returns the first non-null occurrence</font>
								</td>
								<td width="75%">
										<font face="Courier">COALESCE(&lt;value&gt;, &lt;value&gt;, &lt;value&gt;, ...)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">CREATE TABLE test (<br />col1  VARCHAR2(1),<br />col2  VARCHAR2(1),<br />col3  VARCHAR2(1));<br /><br />INSERT INTO test VALUES (NULL, 'B', 'C');<br />INSERT INTO test VALUES ('A', NULL, 'C');<br />INSERT INTO test VALUES (NULL, NULL, 'C');<br />INSERT INTO test VALUES ('A', 'B', 'C');<br /><br />SELECT <font color="#0000ff">COALESCE</font>(col1, col2, col3) FROM test;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>CONCAT</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Concatenate</font>
								</td>
								<td width="75%">
										<font face="Courier">CONCAT(&lt;first_string_or_column&gt;&gt;, &lt;second_string_or_column&gt;&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">CONCAT</font>('Dan ', 'Morgan') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>CONVERT</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Converts From One Character Set To Another</font>
								</td>
								<td width="75%">
										<font face="Courier">CONVERT(&lt;character&gt;,&lt;destination_character_set&gt;,<br />&lt;source_character_set&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">CONVERT</font>('?????A B C D E','US7ASCII','WE8ISO8859P1') <br />FROM dual; </font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>INSTR</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" size="2">See links at page bottom</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>LENGTH</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">String Length</font>
								</td>
								<td width="75%">
										<font face="Courier">LENGTH(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">LENGTH</font>('Dan Morgan') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>LPAD</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Left Pad</font>
								</td>
								<td width="75%">
										<font face="Courier">LPAD(&lt;string_or_column&gt;, &lt;final_length&gt;, &lt;padding_character&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">LPAD</font>('Dan Morgan', 25, 'x') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>LTRIM</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Left Trim</font>
								</td>
								<td width="75%">
										<font face="Courier">LTRIM(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">LTRIM</font>('   Dan Morgan   ') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>NLSSORT</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Returns the string of bytes used to sort a string.<br /><br />The string returned is of RAW data type</font>
								</td>
								<td width="75%">
										<font face="Courier">NLSSORT(&lt;column_name&gt;, 'NLS_SORT = &lt;NLS Parameter&gt;);</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">CREATE TABLE test (name VARCHAR2(15));<br />INSERT INTO test VALUES ('Gaardiner');<br />INSERT INTO test VALUES ('Gaberd');<br />INSERT INTO test VALUES ('G鈈erd');<br />COMMIT;<br /><br />SELECT * FROM test ORDER BY name;<br /><br />SELECT * FROM test<br />ORDER BY <font color="#0000ff">NLSSORT</font>(name, 'NLS_SORT = XDanish');</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>REPLACE</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" size="2">See links at page bottom</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>REVERSE</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Reverse</font>
								</td>
								<td width="75%">
										<font face="Courier">REVERSE(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">REVERSE</font>('Dan Morgan') FROM dual;<br /><br />SELECT DUMP('Dan Morgan') FROM dual;<br />SELECT DUMP(<font color="#0000ff">REVERSE</font>('Dan Morgan')) FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>RPAD</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Right Pad</font>
								</td>
								<td width="75%">
										<font face="Courier">RPAD(&lt;string_or_column&gt;, &lt;final_length&gt;, &lt;padding_character&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">RPAD</font>('Dan Morgan', 25, 'x') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>RTRIM</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Right Trim</font>
								</td>
								<td width="75%">
										<font face="Courier">RTRIM(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">RTRIM</font>('   Dan Morgan   ') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>SOUNDEX</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td valign="top" width="25%" rowspan="2">
										<font face="Arial" size="2">
												<br />Returns Character String Constaining The Phonetic Representation Of Another String</font>
								</td>
								<td width="75%">
										<font face="Courier">Rules:</font>
										<ul>
												<li>
														<font face="Courier">Retain the first letter of the string and remove all other occurrences of the following letters: a, e, h, i, o, u, w, y</font>
												</li>
												<li>
														<font face="Courier">Assign numbers to the remaining letters (after the first) as<br />follows:<br />b, f, p, v = 1<br />c, g, j, k, q, s, x, z = 2<br />d, t = 3<br />l = 4<br />m, n = 5<br />r = 6</font>
												</li>
												<li>
														<font face="Courier">If two or more letters with the same number were adjacent in the original name (before step 1), or adjacent except for any intervening h and w, then omit all but the first.</font>
												</li>
												<li>
														<font face="Courier">Return the first four bytes padded with 0.</font>
												</li>
										</ul>
										<p>
												<font face="Courier">SOUNDEX(&lt;string_or_column&gt;)</font>
										</p>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">CREATE TABLE test (<br />name VARCHAR2(15));<br /><br />INSERT INTO test VALUES ('Smith');<br />INSERT INTO test VALUES ('Smyth');<br />INSERT INTO test VALUES ('Smythe');<br />INSERT INTO test VALUES ('Smither');<br />INSERT INTO test VALUES ('Smidt');<br />INSERT INTO test VALUES ('Smick');<br />INSERT INTO test VALUES ('Smiff');<br />COMMIT;<br /><br />SELECT * FROM test;<br /><br />SELECT *<br />FROM test<br />WHERE <font color="#0000ff">SOUNDEX</font>(name) = SOUNDEX('SMITH');</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>SUBSTR</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" size="2">See links at page bottom</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>TRANSLATE</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" size="2">See links at page bottom</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>TREAT</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Changes The Declared Type Of An Expression</font>
								</td>
								<td width="75%">
										<font face="Courier">TREAT (&lt;expression&gt; AS REF schema.type)) </font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT name, TREAT(VALUE(p) AS employee_t).salary SALARY <br />FROM persons p;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>TRIM (variations are LTRIM and RTRIM)</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Trim Spaces</font>
								</td>
								<td width="75%">
										<font face="Courier">TRIM(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT '   Dan Morgan    ' FROM dual;<br /><br />SELECT <font color="#0000ff">TRIM</font>('   Dan Morgan   ') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Trim Other Characters</font>
								</td>
								<td width="75%">
										<font face="Courier">TRIM(&lt;character_to_trim&gt; FROM &lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">TRIM</font>('D' FROM 'Dan Morgan') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Trim By CHR value</font>
								</td>
								<td width="75%">
										<font face="Courier">TRIM(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT ASCII(SUBSTR('Dan Morgan',1,1)) FROM dual;<br /><br />SELECT <font color="#0000ff">TRIM</font>(<font color="#0000ff">CHR</font>(68) FROM 'Dan Morgan') FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>Vertical Bars</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Also known as Pipes</font>
								</td>
								<td width="75%">
										<font face="Courier" color="#000000">&lt;first_string&gt; <strong>||</strong> &lt;second_string&gt;</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT 'Dan' <font color="#0000ff"><b>||</b></font> ' ' <font color="#0000ff"><b>||</b></font> 'Morgan' FROM dual;<br /><br />with alias<br /><br />SELECT 'Dan' <font color="#0000ff"><b>||</b></font> ' ' <font color="#0000ff"><b>||</b></font> 'Morgan' NAME FROM dual;<br />or<br />SELECT 'Dan' <font color="#0000ff"><b>||</b></font> ' ' <font color="#0000ff"><b>||</b></font> 'Morgan' AS NAME FROM dual;</font>
								</td>
						</tr>
						<tr>
								<td width="25%" colspan="2"> </td>
						</tr>
						<tr>
								<td width="25%" colspan="2">
										<font face="Arial" color="#808000">
												<strong>VSIZE</strong>
										</font>
								</td>
						</tr>
						<tr>
								<td width="25%" rowspan="2">
										<font face="Arial" size="2">Byte Size</font>
								</td>
								<td width="75%">
										<font face="Courier">VSIZE(&lt;string_or_column&gt;)</font>
								</td>
						</tr>
						<tr>
								<td width="75%" bgcolor="#80ffff">
										<font face="Courier">SELECT <font color="#0000ff">VSIZE</font>('Dan Morgan') FROM dual;</font>
								</td>
						</tr>
				</tbody>
		</table>  
<table width="30%" bgcolor="#d8d8c4" border="1"><tbody><tr><td align="middle"><strong><font face="Arial">Related Topics</font></strong></td></tr><tr><td align="middle"><font face="Arial"><a href="http://www.psoug.org/reference/decode_case.html" target="topic">CASE</a></font></td></tr><tr><td align="middle"><font face="Arial"><a href="http://www.psoug.org/reference/dbms_lob.html" target="topic">DBMS_LOB</a></font></td></tr><tr><td align="middle"><font face="Arial"><a href="http://www.psoug.org/reference/decode_case.html" target="topic">Decode</a></font></td></tr><tr><td align="middle"><font face="Arial"><a href="http://www.psoug.org/reference/substr_instr.html" target="topic">Instring</a></font></td></tr><tr><td align="middle"><font face="Arial"><a href="http://www.psoug.org/reference/misc_func.html" target="_blank">Miscellaneous Functions</a></font></td></tr><tr><td align="middle"><font face="Arial"><a href="http://www.psoug.org/reference/ora_operators.html" target="_blank">Operators (Built-in)</a></font></td></tr><tr><td align="middle"><font face="Arial"><a href="http://www.psoug.org/reference/regexp.html" target="topic">Regular Expressions</a></font></td></tr><tr><td align="middle"><font face="Arial"><a href="http://www.psoug.org/reference/translate_replace.html" target="topic">Replace</a></font></td></tr><tr><td align="middle"><font face="Arial"><a href="http://www.psoug.org/reference/substr_instr.html" target="topic">Substring</a></font></td></tr><tr><td align="middle"><font face="Arial"><a href="http://www.psoug.org/reference/translate_replace.html" target="topic">Translate</a></font></td></tr><tr><td align="middle"><font face="Arial"><a href="http://www.psoug.org/reference/xml_functions.html" target="_blank">XML Functions</a></font></td></tr></tbody></table><img src ="http://www.blogjava.net/huhu/aggbug/39080.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huhu/" target="_blank">似水流年</a> 2006-04-04 09:25 <a href="http://www.blogjava.net/huhu/articles/39080.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Trim Function【Oracle/PLSQL】（转载）</title><link>http://www.blogjava.net/huhu/articles/39079.html</link><dc:creator>似水流年</dc:creator><author>似水流年</author><pubDate>Tue, 04 Apr 2006 01:24:00 GMT</pubDate><guid>http://www.blogjava.net/huhu/articles/39079.html</guid><wfw:comment>http://www.blogjava.net/huhu/comments/39079.html</wfw:comment><comments>http://www.blogjava.net/huhu/articles/39079.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huhu/comments/commentRss/39079.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huhu/services/trackbacks/39079.html</trackback:ping><description><![CDATA[
		<p>In Oracle/PLSQL, the <b>trim</b> function removes all specified characters either from the beginning or the ending of a string.</p>
		<p>The syntax for the <b>trim</b> function is:</p>
		<blockquote>
				<blockquote class="definition">
						<p>trim( [ leading | trailing | both  [ trim_character ]  ]   string1 )</p>
				</blockquote>
		</blockquote>
		<p>
				<i>leading</i> - remove <i>trim_string</i> from the front of <i>string1.</i></p>
		<p>
				<i>trailing</i> - remove <i>trim_string</i> from the end of <i>string1</i>.</p>
		<p>
				<i>both</i> - remove <i>trim_string</i> from the front and end of <i>string1</i>.</p>
		<p>If none of these are chosen (ie: leading, trailing, both), the <b>trim</b> function will remove <i>trim_string</i> from both the front and end of <i>string1</i>.</p>
		<br />
		<p>
				<i>trim_character</i> is the character that will be removed from <i>string1</i>. If this parameter is omitted, the <b>trim</b> function will remove all leading and trailing spaces from <i>string1</i>.</p>
		<p>
				<i>string1</i> is the string to trim.</p>
		<br />
		<p>
				<u>For example:</u>
		</p>
		<blockquote>
				<table cellspacing="0" cellpadding="3" width="432" border="0">
						<tbody>
								<tr>
										<td class="function_example" width="232">trim('   tech   ')</td>
										<td class="function_desc">would return 'tech'</td>
								</tr>
								<tr>
										<td class="function_example">trim(' '  from  '   tech   ')</td>
										<td class="function_desc">would return 'tech'</td>
								</tr>
								<tr>
										<td class="function_example">trim(leading '0' from '000123')</td>
										<td class="function_desc">would return '123'</td>
								</tr>
								<tr>
										<td class="function_example">trim(trailing '1' from 'Tech1')</td>
										<td class="function_desc">would return 'Tech'</td>
								</tr>
								<tr>
										<td class="function_example">trim(both '1' from '123Tech111')</td>
										<td class="function_desc">would return '23Tech'</td>
								</tr>
						</tbody>
				</table>
		</blockquote>
<img src ="http://www.blogjava.net/huhu/aggbug/39079.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huhu/" target="_blank">似水流年</a> 2006-04-04 09:24 <a href="http://www.blogjava.net/huhu/articles/39079.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CASE WHEN [Oracle SQL]（链接）</title><link>http://www.blogjava.net/huhu/articles/38977.html</link><dc:creator>似水流年</dc:creator><author>似水流年</author><pubDate>Mon, 03 Apr 2006 09:37:00 GMT</pubDate><guid>http://www.blogjava.net/huhu/articles/38977.html</guid><wfw:comment>http://www.blogjava.net/huhu/comments/38977.html</wfw:comment><comments>http://www.blogjava.net/huhu/articles/38977.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huhu/comments/commentRss/38977.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huhu/services/trackbacks/38977.html</trackback:ping><description><![CDATA[
		<a href="http://www.adp-gmbh.ch/ora/sql/case_when.html">http://www.adp-gmbh.ch/ora/sql/case_when.html</a>
<img src ="http://www.blogjava.net/huhu/aggbug/38977.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huhu/" target="_blank">似水流年</a> 2006-04-03 17:37 <a href="http://www.blogjava.net/huhu/articles/38977.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RPAD and LPAD in Oracle（链接）</title><link>http://www.blogjava.net/huhu/articles/38967.html</link><dc:creator>似水流年</dc:creator><author>似水流年</author><pubDate>Mon, 03 Apr 2006 09:10:00 GMT</pubDate><guid>http://www.blogjava.net/huhu/articles/38967.html</guid><wfw:comment>http://www.blogjava.net/huhu/comments/38967.html</wfw:comment><comments>http://www.blogjava.net/huhu/articles/38967.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huhu/comments/commentRss/38967.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huhu/services/trackbacks/38967.html</trackback:ping><description><![CDATA[
		<a href="http://www.adp-gmbh.ch/ora/sql/rpad.html">http://www.adp-gmbh.ch/ora/sql/rpad.html</a>
<img src ="http://www.blogjava.net/huhu/aggbug/38967.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huhu/" target="_blank">似水流年</a> 2006-04-03 17:10 <a href="http://www.blogjava.net/huhu/articles/38967.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>START WITH and CONNECT BY in Oracle SQL（链接）</title><link>http://www.blogjava.net/huhu/articles/38964.html</link><dc:creator>似水流年</dc:creator><author>似水流年</author><pubDate>Mon, 03 Apr 2006 09:00:00 GMT</pubDate><guid>http://www.blogjava.net/huhu/articles/38964.html</guid><wfw:comment>http://www.blogjava.net/huhu/comments/38964.html</wfw:comment><comments>http://www.blogjava.net/huhu/articles/38964.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huhu/comments/commentRss/38964.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huhu/services/trackbacks/38964.html</trackback:ping><description><![CDATA[
		<p>
				<a href="http://www.adp-gmbh.ch/ora/sql/connect_by.html">http://www.adp-gmbh.ch/ora/sql/connect_by.html</a>
		</p>
<img src ="http://www.blogjava.net/huhu/aggbug/38964.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huhu/" target="_blank">似水流年</a> 2006-04-03 17:00 <a href="http://www.blogjava.net/huhu/articles/38964.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>oracle trunc()函数的用法（转载）</title><link>http://www.blogjava.net/huhu/articles/38955.html</link><dc:creator>似水流年</dc:creator><author>似水流年</author><pubDate>Mon, 03 Apr 2006 08:24:00 GMT</pubDate><guid>http://www.blogjava.net/huhu/articles/38955.html</guid><wfw:comment>http://www.blogjava.net/huhu/comments/38955.html</wfw:comment><comments>http://www.blogjava.net/huhu/articles/38955.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/huhu/comments/commentRss/38955.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/huhu/services/trackbacks/38955.html</trackback:ping><description><![CDATA[ <span class="bold"><span class="smalltxt">TRUNC()函数分两种：<br /><br /></span></span>1.TRUNC(for dates)<br />        TRUNC函数为指定元素而截去的日期值。<br />        其具体的语法格式如下：<br />        TRUNC（date[,fmt]）<br />        其中：<br />        date        一个日期值<br />        fmt                日期格式，该日期将由指定的元素格式所截去。忽略它则由最近的日期截去<br />        下面是该函数的使用情况：<br />        TRUNC（TO_DATE(’24-Nov-1999 08:00 pm’,’dd-mon-yyyy hh:mi am’)）<br />                =’24-Nov-1999 12:00:00 am’<br />        TRUNC（TO_DATE(’24-Nov-1999 08:37 pm’,’dd-mon-yyyy hh:mi am’,’hh’)）        =’24-Nov-1999 08:00:00 am’<br /><br />2.TRUNC(for number)<br />        TRUNC函数返回处理后的数值，其工作机制与ROUND函数极为类似，只是该函数不对指定小数前或后的部分做相应舍入选择处理，而统统截去。<br />        其具体的语法格式如下<br />        TRUNC（number[,decimals]）<br />        其中：<br />        number        待做截取处理的数值<br />        decimals        指明需保留小数点后面的位数。可选项，忽略它则截去所有的小数部分<br />        下面是该函数的使用情况：<br />        TRUNC（89.985，2）=89.98<br />        TRUNC（89.985）=89<br />        TRUNC（89.985，-1）=80<br />        注意：第二个参数可以为负数，表示为小数点左边指定位数后面的部分截去，即均以0记。 <img src ="http://www.blogjava.net/huhu/aggbug/38955.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/huhu/" target="_blank">似水流年</a> 2006-04-03 16:24 <a href="http://www.blogjava.net/huhu/articles/38955.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>