<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Cool Undocumented SQL Function: REVERSE</title>
	<atom:link href="http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/feed/" rel="self" type="application/rss+xml" />
	<link>http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/</link>
	<description>News, views, tips and tricks on Oracle and other fun stuff</description>
	<pubDate>Wed, 20 Aug 2008 17:38:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
		<item>
		<title>By: Brian Tkatch</title>
		<link>http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/#comment-51824</link>
		<dc:creator>Brian Tkatch</dc:creator>
		<pubDate>Thu, 06 Dec 2007 15:56:56 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/#comment-51824</guid>
		<description>I just tried in 10g XE

INSERTing REVERSE(Date) has interesting results. UPDATing, however, seems to choose a valid DATE.</description>
		<content:encoded><![CDATA[<p>I just tried in 10g XE</p>
<p>INSERTing REVERSE(Date) has interesting results. UPDATing, however, seems to choose a valid DATE.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Spaanderman</title>
		<link>http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/#comment-50308</link>
		<dc:creator>Rob Spaanderman</dc:creator>
		<pubDate>Thu, 25 Jan 2007 00:43:40 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/#comment-50308</guid>
		<description>&lt;p&gt;CREATE OR REPLACE FUNCTION Fn_Sentence (pi_input_string   IN VARCHAR2 -- Any combination of words in a string 
                                       ,pi_skip_word_with IN VARCHAR2 DEFAULT NULL) -- optional extention for special words
RETURN VARCHAR2&lt;/p&gt;

&lt;p&gt;-- Purpose     : To return a string in conventional English language sentence format (letter case) (as opposed to INITCAP)
--               It will leave words that contain numbers, and a select range of characters, as they are
-- Usage       : Small scale data conversion and display 
-- Limitations : Does not use any dictionary - based purely on sentence conventions
--               Does not cope with Names and acronyms, but a special character (eg ^) 
--                 can be added to a word and subsequently removed to provide special formatting
-- Author      : Rob Spaanderman 25/01/07
-- Notes       : The lions share of the convoluted code is to accommodate special words - words with non-alpha's in them
--               It could be somewhat simplified if we were to ignore the IT potential for codes etc. 
--               This function can be modified to suit your particular situation
--               I have tried to make it easily modifiable - by just changing the lists of special characters to suit&lt;/p&gt;

&lt;p&gt;IS
    c_translate_mask    CONSTANT VARCHAR2(20) := '~~~~~~~~~~~~~~~~~~~';    -- works in tandem with the word skip list and the translate check
    c_translate_check   CONSTANT VARCHAR2(1)  := '~';      -- if this is changed, the translate mask must be changed
    c_upper_after_space CONSTANT VARCHAR2(20) := '.?!;:';  -- English language symbols denoting the end of a sentence (; and : are debateable)
    c_upper_after_char  CONSTANT VARCHAR2(20) := '"(';     -- Other characters that may preceed that start of a sentence or word with uppercase first letter 
    c_skip_word_with    CONSTANT VARCHAR2(20) := NVL(pi_skip_word_with,'0123456789_-&#38;$@%/\'); -- characters can be added or removed (or overridden) to change which words are ommitted from formatting&lt;/p&gt;

&lt;p&gt;v_length            NUMBER(4)      := LENGTH(pi_input_string); -- there are multiple refences to the length
v_first_blank_pos   NUMBER(4)      := 1;
v_next_blank_pos    NUMBER(4)      := INSTR(pi_input_string,' ');
v_previous_letter   VARCHAR2(1)    := SUBSTR(pi_input_string,1,1);
v_current_letter    VARCHAR2(1)    := v_previous_letter; -- when starting, we start at position 1, so everything starts with letter 1
v_next_letter       VARCHAR2(1)    := v_previous_letter;
v_result_string     VARCHAR2(2000); 
v_current_word      VARCHAR2(2000); -- used to determine whether we need to leave a special word alone or not&lt;/p&gt;

&lt;p&gt;BEGIN
    FOR v_position IN 1..v_length LOOP
        IF v_current_letter  = ' '      -- between words
        OR v_position = 1 THEN          -- first time around
           v_first_blank_pos := v_position;
           v_next_blank_pos  := INSTR(pi_input_string,' ',v_first_blank_pos + 1);
           IF v_next_blank_pos = 0 THEN -- probably the end of the sentence which will have no space
              v_next_blank_pos := v_length;
           END IF;
           -- Extract the next word in the sentence - used to determine if we need to leave it alone or not
           v_current_word := SUBSTR(pi_input_string, v_first_blank_pos, v_next_blank_pos - v_first_blank_pos);
        END IF;
        -- We check to see if there any special characters in the word - if not, do the formatting, else skip the formatting
        IF  INSTR(TRANSLATE(v_current_word, c_skip_word_with, c_translate_mask), c_translate_check) = 0 THEN 
            IF (v_current_letter  = ' ' 
            AND INSTR(c_upper_after_space,v_previous_letter) &#60;&#62; 0
            OR  v_position = 1) 
            OR  INSTR(c_upper_after_char, v_current_letter)  &#60;&#62; 0 THEN
                v_next_letter := UPPER(v_next_letter);
            ELSE
                v_next_letter := LOWER(v_next_letter);
            END IF;
        END IF;
        -- The "next letter" contains either the uppered, the lowered, or the left alone value
        v_result_string := v_result_string &#124;&#124; v_next_letter;
        -- Move the three operational letters along the sequence
        v_previous_letter := v_current_letter;
        v_current_letter  := v_next_letter;
        v_next_letter     := SUBSTR(pi_input_string,v_position + 1,1);
    END LOOP;
    RETURN (v_result_string);
END;
/&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>CREATE OR REPLACE FUNCTION Fn_Sentence (pi_input_string   IN VARCHAR2 &#8212; Any combination of words in a string<br />
                                       ,pi_skip_word_with IN VARCHAR2 DEFAULT NULL) &#8212; optional extention for special words<br />
RETURN VARCHAR2</p>
<p>&#8211; Purpose     : To return a string in conventional English language sentence format (letter case) (as opposed to INITCAP)<br />
&#8211;               It will leave words that contain numbers, and a select range of characters, as they are<br />
&#8211; Usage       : Small scale data conversion and display<br />
&#8211; Limitations : Does not use any dictionary - based purely on sentence conventions<br />
&#8211;               Does not cope with Names and acronyms, but a special character (eg ^)<br />
&#8211;                 can be added to a word and subsequently removed to provide special formatting<br />
&#8211; Author      : Rob Spaanderman 25/01/07<br />
&#8211; Notes       : The lions share of the convoluted code is to accommodate special words - words with non-alpha&#8217;s in them<br />
&#8211;               It could be somewhat simplified if we were to ignore the IT potential for codes etc.<br />
&#8211;               This function can be modified to suit your particular situation<br />
&#8211;               I have tried to make it easily modifiable - by just changing the lists of special characters to suit</p>
<p>IS<br />
    c_translate_mask    CONSTANT VARCHAR2(20) := &#8216;~~~~~~~~~~~~~~~~~~~&#8217;;    &#8212; works in tandem with the word skip list and the translate check<br />
    c_translate_check   CONSTANT VARCHAR2(1)  := &#8216;~&#8217;;      &#8212; if this is changed, the translate mask must be changed<br />
    c_upper_after_space CONSTANT VARCHAR2(20) := &#8216;.?!;:&#8217;;  &#8212; English language symbols denoting the end of a sentence (; and : are debateable)<br />
    c_upper_after_char  CONSTANT VARCHAR2(20) := &#8216;&#8221;(&#8217;;     &#8212; Other characters that may preceed that start of a sentence or word with uppercase first letter<br />
    c_skip_word_with    CONSTANT VARCHAR2(20) := NVL(pi_skip_word_with,&#8217;0123456789_-&amp;$@%/\&#8217;); &#8212; characters can be added or removed (or overridden) to change which words are ommitted from formatting</p>
<p>v_length            NUMBER(4)      := LENGTH(pi_input_string); &#8212; there are multiple refences to the length<br />
v_first_blank_pos   NUMBER(4)      := 1;<br />
v_next_blank_pos    NUMBER(4)      := INSTR(pi_input_string,&#8217; &#8216;);<br />
v_previous_letter   VARCHAR2(1)    := SUBSTR(pi_input_string,1,1);<br />
v_current_letter    VARCHAR2(1)    := v_previous_letter; &#8212; when starting, we start at position 1, so everything starts with letter 1<br />
v_next_letter       VARCHAR2(1)    := v_previous_letter;<br />
v_result_string     VARCHAR2(2000);<br />
v_current_word      VARCHAR2(2000); &#8212; used to determine whether we need to leave a special word alone or not</p>
<p>BEGIN<br />
    FOR v_position IN 1..v_length LOOP<br />
        IF v_current_letter  = &#8216; &#8216;      &#8212; between words<br />
        OR v_position = 1 THEN          &#8212; first time around<br />
           v_first_blank_pos := v_position;<br />
           v_next_blank_pos  := INSTR(pi_input_string,&#8217; &#8216;,v_first_blank_pos + 1);<br />
           IF v_next_blank_pos = 0 THEN &#8212; probably the end of the sentence which will have no space<br />
              v_next_blank_pos := v_length;<br />
           END IF;<br />
           &#8212; Extract the next word in the sentence - used to determine if we need to leave it alone or not<br />
           v_current_word := SUBSTR(pi_input_string, v_first_blank_pos, v_next_blank_pos - v_first_blank_pos);<br />
        END IF;<br />
        &#8212; We check to see if there any special characters in the word - if not, do the formatting, else skip the formatting<br />
        IF  INSTR(TRANSLATE(v_current_word, c_skip_word_with, c_translate_mask), c_translate_check) = 0 THEN<br />
            IF (v_current_letter  = &#8216; &#8216;<br />
            AND INSTR(c_upper_after_space,v_previous_letter) &lt;&gt; 0<br />
            OR  v_position = 1)<br />
            OR  INSTR(c_upper_after_char, v_current_letter)  &lt;&gt; 0 THEN<br />
                v_next_letter := UPPER(v_next_letter);<br />
            ELSE<br />
                v_next_letter := LOWER(v_next_letter);<br />
            END IF;<br />
        END IF;<br />
        &#8212; The &#8220;next letter&#8221; contains either the uppered, the lowered, or the left alone value<br />
        v_result_string := v_result_string || v_next_letter;<br />
        &#8212; Move the three operational letters along the sequence<br />
        v_previous_letter := v_current_letter;<br />
        v_current_letter  := v_next_letter;<br />
        v_next_letter     := SUBSTR(pi_input_string,v_position + 1,1);<br />
    END LOOP;<br />
    RETURN (v_result_string);<br />
END;<br />
/</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SudheerReddy</title>
		<link>http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/#comment-50249</link>
		<dc:creator>SudheerReddy</dc:creator>
		<pubDate>Sun, 17 Dec 2006 06:54:04 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/#comment-50249</guid>
		<description>&lt;p&gt;I Need FAQ's on Sql and Pl/Sql.If u have this info. plz farward to this mail.Thanking You.Bye&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I Need FAQ&#8217;s on Sql and Pl/Sql.If u have this info. plz farward to this mail.Thanking You.Bye</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sukhen kumar tiwari</title>
		<link>http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/#comment-50153</link>
		<dc:creator>sukhen kumar tiwari</dc:creator>
		<pubDate>Tue, 14 Nov 2006 07:23:26 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/#comment-50153</guid>
		<description>&lt;p&gt;I need reverse string.
Like I have put anil kumar but i want the Kumar anil&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>I need reverse string.<br />
Like I have put anil kumar but i want the Kumar anil</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eddie Awad</title>
		<link>http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/#comment-49965</link>
		<dc:creator>Eddie Awad</dc:creator>
		<pubDate>Thu, 31 Aug 2006 04:07:29 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/#comment-49965</guid>
		<description>&lt;p&gt;Or insert:&lt;/p&gt;

&lt;pre&gt;
SQL&gt; create table t (x date);

Table created.

SQL&gt; insert into t values (reverse(sysdate));

1 row created.

SQL&gt; select * from t;

X
---------
20-BINARY

SQL&gt; select to_char(x,'mm-dd-yyyy') y from t;

Y
----------
00-00-0000
&lt;/pre&gt;

&lt;p&gt;Since REVERSE preserves the datatype, you end up with a date that is not really a date. You are actually, in a way, bypassing datatype validation. Interesting!&lt;/p&gt;

&lt;p&gt;You're right Gary, no wonder it is still undocumented!&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Or insert:</p>
<pre>
SQL> create table t (x date);

Table created.

SQL> insert into t values (reverse(sysdate));

1 row created.

SQL> select * from t;

X
---------
20-BINARY

SQL> select to_char(x,'mm-dd-yyyy') y from t;

Y
----------
00-00-0000
</pre>
<p>Since REVERSE preserves the datatype, you end up with a date that is not really a date. You are actually, in a way, bypassing datatype validation. Interesting!</p>
<p>You&#8217;re right Gary, no wonder it is still undocumented!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: gamyers</title>
		<link>http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/#comment-49964</link>
		<dc:creator>gamyers</dc:creator>
		<pubDate>Wed, 30 Aug 2006 22:51:24 +0000</pubDate>
		<guid isPermaLink="false">http://awads.net/wp/2006/08/30/cool-undocumented-sql-function-reverse/#comment-49964</guid>
		<description>&lt;p&gt;Not only can you SELECT reverse(date_col), but you can&lt;/p&gt;

&lt;pre&gt;UPDATE table SET date_col = REVERSE(date_col) &lt;/pre&gt;

&lt;p&gt;and watch all the errors as people try to select the data.
There's a reason why somethings are best left undocumented.&lt;/p&gt;

&lt;p&gt;Seriously, I think the main use of this is behind the scenes for reverse key indexes.
http://asktom.oracle.com/pls/ask/f?p=4950:8:2175155135156691628::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:6163160472530
I'd be surprised if it is ever 'documented' for any other use.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Not only can you SELECT reverse(date_col), but you can</p>
<pre>UPDATE table SET date_col = REVERSE(date_col) </pre>
<p>and watch all the errors as people try to select the data.<br />
There&#8217;s a reason why somethings are best left undocumented.</p>
<p>Seriously, I think the main use of this is behind the scenes for reverse key indexes.<br />
<a href="http://asktom.oracle.com/pls/ask/f?p=4950:8:2175155135156691628::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:6163160472530" rel="nofollow">http://asktom.oracle.com/pls/ask/f?p=4950:8:2175155135156691628::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:6163160472530</a><br />
I&#8217;d be surprised if it is ever &#8216;documented&#8217; for any other use.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
