<?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>PersonalBlog &#187; function syntax</title>
	<atom:link href="http://arimita.web.id/tag/function-syntax/feed/" rel="self" type="application/rss+xml" />
	<link>http://arimita.web.id</link>
	<description>Just another personal weblog</description>
	<lastBuildDate>Mon, 19 Jul 2010 08:31:10 +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>CREATE PROCEDURE and CREATE FUNCTION</title>
		<link>http://arimita.web.id/2010/06/create-procedure-and-create-function/</link>
		<comments>http://arimita.web.id/2010/06/create-procedure-and-create-function/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 07:13:59 +0000</pubDate>
		<dc:creator>mythworks</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[create function.]]></category>
		<category><![CDATA[create procedure]]></category>
		<category><![CDATA[function syntax]]></category>
		<category><![CDATA[procedur syntax]]></category>

		<guid isPermaLink="false">http://arimita.web.id/?p=232</guid>
		<description><![CDATA[CREATE PROCEDURE syntax
CREATE
[DEFINER = { user &#124; CURRENT_USER }]
PROCEDURE sp_name ([proc_parameter[,...]])
[characteristic ...] routine_body
proc_parameter:
[ IN &#124; OUT &#124; INOUT ] param_name type
CREATE FUNCTION syntax
CREATE
[DEFINER = { user &#124; CURRENT_USER }]
FUNCTION sp_name ([func_parameter[,...]])
RETURNS type
[characteristic ...] routine_body
func_parameter:
param_name type
CREATE PROCEDURE and CREATE FUNCTION require the CREATE ROUTINE privilege. They might also require the SUPER privilege, depending on the DEFINER [...]]]></description>
			<content:encoded><![CDATA[<p><strong>CREATE PROCEDURE syntax</strong><br />
CREATE<br />
[DEFINER = { user | CURRENT_USER }]<br />
PROCEDURE sp_name ([proc_parameter[,...]])<br />
[characteristic ...] routine_body</p>
<p>proc_parameter:<br />
[ IN | OUT | INOUT ] param_name type</p>
<p><strong>CREATE FUNCTION syntax</strong><br />
CREATE<br />
[DEFINER = { user | CURRENT_USER }]<br />
FUNCTION sp_name ([func_parameter[,...]])<br />
RETURNS type<br />
[characteristic ...] routine_body</p>
<p>func_parameter:<br />
param_name type</p>
<p>CREATE PROCEDURE and CREATE FUNCTION require the CREATE ROUTINE privilege. They might also require the SUPER privilege, depending on the DEFINER value.</p>
<p><strong>DROP PROCEDURE and DROP FUNCTION Syntax:</strong> this statement is used to drop a stored procedure or function.</p>
<p>DROP {PROCEDURE | FUNCTION} [IF EXISTS] procedure_or_function_name</p>
<p>Specifying a parameter as IN, OUT, or INOUT is valid only for a PROCEDURE. For a FUNCTION, parameters are always regarded as IN parameters. An IN parameter passes a value into a procedure. An OUT parameter passes a value from the procedure back to the caller. Its initial value is NULL within the procedure, and its value is visible to the caller when the procedure returns. An INOUT parameter is initialized by the caller, can be modified by the procedure, and any change made by the procedure is visible to the caller when the procedure returns.<br />
Lets see a simple stored procedure using OUT parameter:</p>
<pre class="brush: sql;">
CREATE PROCEDURE jumlah( out juml int ) BEGIN SELECT count( * )
INTO juml
FROM FUNCTIONS;
END
</pre>
<p>Note: The example uses the mysql client delimiter command to change the statement delimiter from ; to // while the procedure is being defined. This allows the ; delimiter used in the procedure body to be passed through to the server rather than being interpreted by mysql itself.<br />
And now how to CALL the procedure? Lets see this query:</p>
<pre class="brush: sql;">
CALL jumlah(@a);
SELECT @a ;
</pre>
<p>If you want to see the that procedure is exists on your server, you can try to Export as a sql and check the structure especially Add CREATE PROCEDURE / FUNCTION. On the bottom you will see the procedure you have been created:<br />
&#8211;<br />
&#8211; Procedures<br />
&#8211;<br />
DELIMITER $$<br />
&#8211;<br />
CREATE DEFINER=`root`@`localhost` PROCEDURE `jumlah`( out juml int )<br />
BEGIN SELECT count( * )<br />
INTO juml<br />
FROM FUNCTIONS;<br />
END$$</p>
<p>&#8211;<br />
DELIMITER ;<br />
&#8211;</p>
<p>And then the syntax to drop the procedure if you want to trash it:<br />
DROP PROCEDURE IF EXISTS jumlah</p>
<p>Lets see a simple function:</p>
<pre class="brush: sql;">
CREATE FUNCTION fungsi(
aCHAR( 10 )
) RETURNS CHAR( 20 ) DETERMINISTIC RETURN CONCAT( 'Fungsi, ', a, '.' ) ;
</pre>
<p>Then try to execute that query like this to see the result:</p>
<pre class="brush: sql;">
SELECT fungsi('test only');
</pre>
<p>Like procedure above you can see the function by Export as sql and the bottom look view:</p>
<p>CREATE DEFINER=`root`@`localhost` FUNCTION `fungsi`(a CHAR(10)) RETURNS char(20) CHARSET latin1<br />
DETERMINISTIC<br />
RETURN CONCAT(&#8216;Fungsi, &#8216;,a,&#8217;.')</p>
<p>And then the syntax to drop the procedure if you want to trash it:</p>
<pre class="brush: sql;">
DROP FUNCTION IF EXISTS fungsi
</pre>
<p>Well improve your self with aother case and develop yours.</p>
]]></content:encoded>
			<wfw:commentRss>http://arimita.web.id/2010/06/create-procedure-and-create-function/feed/</wfw:commentRss>
		<slash:comments>99</slash:comments>
		</item>
	</channel>
</rss>

