Simple examples of storage functions and stored procedures in MySQL, mysql stored procedures

Source: Internet
Author: User

Simple examples of storage functions and stored procedures in MySQL, mysql stored procedures
Storage Function Definition

Create function 'fn _ Sum' ('A' int, 'B' int) RETURNS int (11)

BEGIN

RETURN a + B;

END

 

Call the call in Navicat

 

 

Running result:

 

 

SQL call

SELECT fn_sum (1, 2 );

Running result:

 

 

Calls in Java

Abbreviation :"{? = Call fn_sum (?,?)} "

 

Stored Procedure Definition with input parameters

Create procedure 'in _ param' (in p_in int)

BEGIN

SELECT p_in;

END

 

Call the call in Navicat

 

 

Running result:

 

 

SQL call

CALL in_param (2 );

Running result:

 

 

Calls in Java

Abbreviation: "{call in_param (?)} "

 

Stored Procedure Definition with output parameters

Create procedure 'out _ param' (out p_out int)

BEGIN

SELECT p_out;

SET p_out = 2;

SELECT p_out;

END

 

Call the call in Navicat

 

 

Running result:

 

 

 

SQL call

CALL out_param (@ p_out );

Running result:

 

 

 

Calls in Java

Abbreviation: "{call out_param (?)} "

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.