<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://petersap.nl/SybaseWiki/index.php?action=history&amp;feed=atom&amp;title=User_defined_SQL_functions</id>
		<title>User defined SQL functions - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://petersap.nl/SybaseWiki/index.php?action=history&amp;feed=atom&amp;title=User_defined_SQL_functions"/>
		<link rel="alternate" type="text/html" href="http://petersap.nl/SybaseWiki/index.php?title=User_defined_SQL_functions&amp;action=history"/>
		<updated>2026-04-04T20:45:40Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.24.2</generator>

	<entry>
		<id>http://petersap.nl/SybaseWiki/index.php?title=User_defined_SQL_functions&amp;diff=1697&amp;oldid=prev</id>
		<title>Psap: /* Miscellaneous */</title>
		<link rel="alternate" type="text/html" href="http://petersap.nl/SybaseWiki/index.php?title=User_defined_SQL_functions&amp;diff=1697&amp;oldid=prev"/>
				<updated>2007-07-05T07:18:42Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Miscellaneous&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 07:18, 5 July 2007&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 64:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 64:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The basic definition of user defined SQL function is stored in sysobjects. The value of column type will be &amp;quot;SF&amp;quot;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The basic definition of user defined SQL function is stored in sysobjects. The value of column type will be &amp;quot;SF&amp;quot;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Internally, within ASE, user defined SQL functions behave the same as stored procedures. This means that there is a query plan for them and you can access tables in user defined SQL functions.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Since you can make these functions part of a where clause in a select statement, performance can really degrate since for each evaluation a stored procedure is executed.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:ASE]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:ASE]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key website-mw_:diff:version:1.11a:oldid:1695:newid:1697 --&gt;
&lt;/table&gt;</summary>
		<author><name>Psap</name></author>	</entry>

	<entry>
		<id>http://petersap.nl/SybaseWiki/index.php?title=User_defined_SQL_functions&amp;diff=1695&amp;oldid=prev</id>
		<title>Psap: /* Miscelaneous */</title>
		<link rel="alternate" type="text/html" href="http://petersap.nl/SybaseWiki/index.php?title=User_defined_SQL_functions&amp;diff=1695&amp;oldid=prev"/>
				<updated>2007-06-28T21:49:02Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Miscelaneous&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 21:49, 28 June 2007&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 61:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 61:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; drop function get_ip_part&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#160; drop function get_ip_part&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Miscelaneous&lt;/del&gt;==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Miscellaneous&lt;/ins&gt;==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The basic definition of user defined SQL function is stored in sysobjects. The value of column type will be &amp;quot;SF&amp;quot;.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The basic definition of user defined SQL function is stored in sysobjects. The value of column type will be &amp;quot;SF&amp;quot;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:ASE]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:ASE]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key website-mw_:diff:version:1.11a:oldid:1693:newid:1695 --&gt;
&lt;/table&gt;</summary>
		<author><name>Psap</name></author>	</entry>

	<entry>
		<id>http://petersap.nl/SybaseWiki/index.php?title=User_defined_SQL_functions&amp;diff=1693&amp;oldid=prev</id>
		<title>Psap at 21:47, 28 June 2007</title>
		<link rel="alternate" type="text/html" href="http://petersap.nl/SybaseWiki/index.php?title=User_defined_SQL_functions&amp;diff=1693&amp;oldid=prev"/>
				<updated>2007-06-28T21:47:18Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Introduction==&lt;br /&gt;
User defined SQL functions are a new feature in ASE 15.0.2. This document shows you how to work with them.&lt;br /&gt;
&lt;br /&gt;
This example demonstrates how to return a part of a string filled with an ip-address. The returned value should of the datatype tinyint. So for ip-address 192.138.151.104 and part 3 the returned value should be 151.&lt;br /&gt;
&lt;br /&gt;
==Create the function==&lt;br /&gt;
Goes like this:&lt;br /&gt;
 create function get_ip_part&lt;br /&gt;
        (@ip_address varchar(30), @part tinyint)&lt;br /&gt;
        returns tinyint&lt;br /&gt;
 as&lt;br /&gt;
 &lt;br /&gt;
 if     @part not between 1 and 4&lt;br /&gt;
 begin&lt;br /&gt;
        raiserror 20000 &amp;quot;Invalid value for @part, must be between 1 and 4&amp;quot;&lt;br /&gt;
        return&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 declare @j tinyint,&lt;br /&gt;
         @i tinyint&lt;br /&gt;
 &lt;br /&gt;
 select  @j = 1,&lt;br /&gt;
         @i = charindex(&amp;quot;.&amp;quot;,@ip_address)&lt;br /&gt;
 &lt;br /&gt;
 while   @i &amp;gt; 0&lt;br /&gt;
 begin&lt;br /&gt;
         if @j = @part&lt;br /&gt;
            return convert(tinyint,left(@ip_address,@i - 1))&lt;br /&gt;
 &lt;br /&gt;
         select @ip_address = substring(@ip_address,@i+1,255),&lt;br /&gt;
                @j          = @j + 1&lt;br /&gt;
         select @i          = charindex(&amp;quot;.&amp;quot;,@ip_address)&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 return  convert(tinyint,@ip_address)&lt;br /&gt;
&lt;br /&gt;
==Execute the function==&lt;br /&gt;
You can execute the function in the same manner as a Sybase supplied function:&lt;br /&gt;
&lt;br /&gt;
 select get_ip_part(&amp;quot;192.138.151.104&amp;quot;,3)&lt;br /&gt;
&lt;br /&gt;
However, in the pre-release of 15.0.2 you need to specify dbo in front of the name:&lt;br /&gt;
&lt;br /&gt;
 select dbo.get_ip_part(&amp;quot;192.138.151.104&amp;quot;,3)&lt;br /&gt;
&lt;br /&gt;
When you do not do so, you will get this error:&lt;br /&gt;
&lt;br /&gt;
 Msg 2847, Level 18, State 1:&lt;br /&gt;
 Server 'ASE1', Line 6:&lt;br /&gt;
 The object 'dbo.get_ip_part' is not a SQLJ function. If this is a SQL function, specify owner.objectname.&lt;br /&gt;
 Msg 14216, Level 16, State 1:&lt;br /&gt;
 Server 'ASE1', Line 6:&lt;br /&gt;
 Function 'get_ip_part' not found. If this is a SQLJ function or SQL function, use sp_help to check whether the object exists&lt;br /&gt;
 (sp_help may produce a large amount of output).&lt;br /&gt;
&lt;br /&gt;
Cross database execution is possible, as in my_database.dbo.get_ip_part&lt;br /&gt;
&lt;br /&gt;
==Drop a function==&lt;br /&gt;
Can be done with the drop statement:&lt;br /&gt;
&lt;br /&gt;
 drop function get_ip_part&lt;br /&gt;
&lt;br /&gt;
==Miscelaneous==&lt;br /&gt;
The basic definition of user defined SQL function is stored in sysobjects. The value of column type will be &amp;quot;SF&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[Category:ASE]]&lt;/div&gt;</summary>
		<author><name>Psap</name></author>	</entry>

	</feed>