{"id":69099,"date":"2021-08-12T00:03:15","date_gmt":"2021-08-12T04:03:15","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/stored-procedure-in-mysql-5\/"},"modified":"2021-08-12T00:03:15","modified_gmt":"2021-08-12T04:03:15","slug":"stored-procedure-in-mysql-5","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=69099","title":{"rendered":"Stored Procedure in MySql #5"},"content":{"rendered":"<p>Starting from MySQL 5, you get Stored Procedure in Mysql<\/p>\n<p>What is a stored procedure: A stored procedure is simply a procedure that is stored on the database server like MySQL. In programming languages, you write procedures to execute a function\/logic. You can write similar procedure in SQL and store it in the database. From the front end application you can just call the procedure to get the functionality. Usually, you send series of sqls to the databases to execute a logic. A stored procedure is better as it needs one single call. But not every logic can\/should be implemented as stored procedures.<\/p>\n<p>Sample stored procedure<\/p>\n<p>CREATE PROCEDURE sp_hello() <br \/>SELECT &#8216;Hello World&#8217;;<\/p>\n<p>It just creates a procedure. To run the procedure, you have to type <\/p>\n<p>call sp_hello; <\/p>\n<p>You will see &#8216;Hello World&#8217; as output.<\/p>\n<p>Stored procedures can also take parameters and return values. Both needs to be mentioned as parameter. In the parameter list we can declare a variable as IN, OUT, or INOUT parameter. You can use SQLs[insert,select] inside procedure to perform database operations. Also, you can use to set\/unset session variables.<\/p>\n<p>Session variable example<\/p>\n<p>SET @X=100;<br \/>CREATE PROCEDURE sp_in(p VARCHAR(10))<br \/>SET @x = P;<\/p>\n<p>call sp_in(1000);<\/p>\n<p>You see 1000 in screen<\/p>\n<p>A more practical stored procedure with multiple statementsmysql&gt; DELIMITER |mysql&gt; CREATE PROCEDURE sp_declare (P INT)    -&gt; BEGIN    -&gt;  DECLARE x INT;    -&gt;  DECLARE y INT DEFAULT 10;    -&gt;  SET x = P*y;    -&gt;  INSERT INTO sp1(id,txt) VALUES(x,HEX(&#8216;DEF&#8217;));    -&gt; END|Query OK, 0 rows affected (0.00 sec) mysql&gt; DELIMITER ;mysql&gt; CALL sp_declare(4);<\/p>\n<p> please, note the use of | and DELIMETER. They provide support so that you can use ; in your procedures.<\/p>\n<h2>Some stored procedure related SQL commands<\/h2>\n<p>SHOW PROCEDURE STATUSSHOW CREATE PROCEDURE HelloSELECT * FROM INFORMATION_SCHEMA.ROUTINES [Ansi standard]ThanksSayed<\/p>\n<p>From: http:\/\/sitestree.com\/?p=4729<br \/> Categories:5<br \/>Tags:<br \/> Post Data:2012-06-17 13:50:57<\/p>\n<pre><code>    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\"&gt;https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    (Big Data, Cloud, Security, Machine Learning): Courses: &lt;a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"&gt; http:\/\/Training.SitesTree.com&lt;\/a&gt; \n    In Bengali: &lt;a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\"&gt;http:\/\/Bangla.SaLearningSchool.com&lt;\/a&gt;\n    &lt;a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\"&gt;http:\/\/SitesTree.com&lt;\/a&gt;\n    8112223 Canada Inc.\/JustEtc: &lt;a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\"&gt;http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) &lt;\/a&gt;\n    Shop Online: &lt;a href='https:\/\/www.ShopForSoul.com'&gt; https:\/\/www.ShopForSoul.com\/&lt;\/a&gt;\n    Medium: &lt;a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"&gt; https:\/\/medium.com\/@SayedAhmedCanada &lt;\/a&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Starting from MySQL 5, you get Stored Procedure in Mysql What is a stored procedure: A stored procedure is simply a procedure that is stored on the database server like MySQL. In programming languages, you write procedures to execute a function\/logic. You can write similar procedure in SQL and store it in the database. From &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=69099\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-69099","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":70095,"url":"http:\/\/bangla.sitestree.com\/?p=70095","url_meta":{"origin":69099,"position":0},"title":"Stored Procedure: PHP &amp; MySQL #16","author":"Author-Check- Article-or-Video","date":"August 25, 2021","format":false,"excerpt":"Stored Procedure: PHP & MySQL. Stored Procedures are new additions to MySQL 5. PHP has supports for Store Procedure as well (with some limitations). Using Stored procedure with mySQL and PHP CODE TUTORIAL: MySql Stored Procedures PHP Resources at JustETC MySQL Resources at JustETC From: http:\/\/sitestree.com\/?p=5263 Categories:16Tags: Post Data:2009-10-27 05:05:14\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":69107,"url":"http:\/\/bangla.sitestree.com\/?p=69107","url_meta":{"origin":69099,"position":1},"title":"MySQL New Features #5","author":"Author-Check- Article-or-Video","date":"August 12, 2021","format":false,"excerpt":"MySQL New Features Cursor Example:CREATE PROCEDURE p25 (OUT return_val INT)BEGINDECLARE a,b INT;DECLARE cur_1 CURSOR FOR SELECT s1 FROM t;DECLARE CONTINUE HANDLER FOR NOT FOUND < --SET b = 1; <--OPEN cur_1;REPEATFETCH cur_1 INTO a;UNTIL b = 1END REPEAT;CLOSE cur_1;SET return_val = a;END;\/\/ Stored procedure in MySQL http:\/\/www.mysqltutorial.org\/stored-procedures-loop.aspx Loop in stored\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":75827,"url":"http:\/\/bangla.sitestree.com\/?p=75827","url_meta":{"origin":69099,"position":2},"title":"MS SQL Server Dynamic SQl, T-SQL","author":"Sayed","date":"June 25, 2023","format":false,"excerpt":"MS SQL Server Dynamic SQl, T-SQL Mostly: Dynamic SQL Stored Procedure Trigger Cursor Function Sayed Ahmed What are the Most Important Most Used Design ERD Convert ERD to database Normalization Indexing SQL Stored Procedure Dynamic SQL These will come, not too frequent Function, User Defined Data Types, Temporary Table Trigger,\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65942,"url":"http:\/\/bangla.sitestree.com\/?p=65942","url_meta":{"origin":69099,"position":3},"title":"JDBC: Stored Procedure #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 18, 2021","format":false,"excerpt":"Sample stored procedure call using JDBC:Call stored procedure to change\/set a value in the database\/\/set birthday - supply professor nametry{ String professor= \"dylan thomas\"; CallableStatement proc = connection.prepareCall(\"{ call set_birth_date(?, ?) }\"); proc.setString(1, professor); proc.setString(2, '1950-01-01'); cs.execute();}catch (SQLException e){ \/\/ ....}Stored procedures can also return result\/data to the caller: like\/\/return\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":76092,"url":"http:\/\/bangla.sitestree.com\/?p=76092","url_meta":{"origin":69099,"position":4},"title":"Oracle Stored Procedure: Create a simple stored procedure","author":"Sayed","date":"May 20, 2024","format":false,"excerpt":"Ref: https:\/\/docs.oracle.com\/database\/121\/LNPLS\/create_procedure.htm#LNPLS01373","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2024\/05\/image-46.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":69426,"url":"http:\/\/bangla.sitestree.com\/?p=69426","url_meta":{"origin":69099,"position":5},"title":"Firebird Stored procedure delphi #2","author":"Author-Check- Article-or-Video","date":"August 20, 2021","format":false,"excerpt":"In firebird, the syntax to create TRIGGERs and Stored Procedures is as below:---SET TERM !! ; CREATE TRIGGER auto_update_1 FOR DBPATHS after INSERT POSITION 0 AS BEGIN insert into commission values (100,100); END !! SET TERM ; !! ---SET TERM !! ;CREATE PROCEDURE CountTo10 RETURNS (Cnt INTEGER) AS BEGIN Cnt\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/69099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=69099"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/69099\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=69099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=69099"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=69099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}