Input and Output Parameters

Input and Output Parameters

In SQL database management systems, the input and output parameters method is used to pass data information between the calling program and the database in a stored procedure created in a database table.

Input and Output Parameters

The input and output parameters method helps make stored procedures created in an existing database table accessible, flexible, and efficient for multiple uses.

There are three main types of stored procedure parameters in SQL databases.

  • IN parameter – This parameter is used to pass stored procedure value information to the SQL database system.
  • OUT parameter – This parameter is used to return a value from a stored procedure in the SQL database system.
  • INOUT parameter – This inout parameter method is used to pass procedure values ​​to the SQL database system and return updated data values.

IN parameter (input parameter) concept in stored procedures.

In SQL database management systems, the INPUT IN parameter is used to provide input values ​​to a stored procedure in a user-defined database table.

It uses these input values ​​to apply the stored procedure operation task to the database table.

Example of an INPUT parameter in a SQL database management system.

DELIMITER //

CREATE PROCEDURE DetailsEmployeeData(

IN emp_id INT

)

BEGIN

SELECT *

FROM Employee

WHERE EmployeeID = emp_id;

END //

DELIMITER ;

Calling a procedure in the database.

CALL GetEmployeeData(4343);

Explanation of the IN parameter stored procedures.

  • Here, emp_id is an input parameter value containing data information in the EMPLOYEE database table.
  • In which the user input value 4343 is passed to the stored procedure.
  • The stored procedure retrieves data information for the employee whose employee ID is defined as 4343.

Input IN parameters point to a database table. IN parameters pass user-initiated values ​​from the calling program to the current stored procedure.

OUT parameters (output parameters) concept in stored procedures.

In SQL database management systems, the OUT parameter method is used to return a value from a stored procedure to the calling program.

The OUT parameter method is used in database tables when the database user wants to retrieve a calculated result or specific data or information.

Example of output parameters in a SQL database management system.

DELIMITER //

CREATE PROCEDURE DetailsEmployeeCount(

OUT salary INT

)

BEGIN

SELECT COUNT(*)

INTO salary

FROM Employee;

END //

DELIMITER;

Calling a procedure with output parameters.

CALL DetailsEmployeeCount (@salary);

SELECT @salary;

Explanation of the OUT parameters stored procedures.

  • Here salary is an output parameter method in the EMPLOYEE database table.
  • In which the stored procedure counts the total salary value of employees.
  • The result is stored and displayed in the OUT parameter.
  • The statement SELECT @salary displays the returned value.

Output OUT parameters point to the database table. OUT parameters output or return a particular value from the stored procedure.

INOUT parameter concept in stored procedures.

In SQL database management systems, INOUT parameters are used to accept user input values, modify or update them within a stored procedure in an existing database table, and return the updated stored procedure value.

Example of INOUT parameters in a SQL database management system.

DELIMITER //

CREATE PROCEDURE IncreameantSalary(

INOUT emp_salary DECIMAL(10,2)

)

BEGIN

SET emp_salary = emp_salary + 9000;

END //

DELIMITER ;

Calling the INOUT parameter procedure.

SET @emp_salary = 41000;

CALL IncreameantSalary (@emp_salary);

SELECT @emp_salary;

Output of the INOUT parameter procedure.

50000

Explanation of the INOUT parameters in stored procedures.

  • • Here, the starting employee salary in the EMPLOYEE database table is ₹41,000.
  • • The INOUT procedure increases the employee salary by ₹9,000.
  • • The updated new employee salary is returned as ₹50,000.

Input/Output: The INOUT parameter’s point is that the INOUT parameter in the database table is used to execute both input and output stored procedure database operations.

Main Difference Between IN, OUT, and INOUT Stored Parameters

#IN Database ParameterOUT Database ParameterINOUT Database Parameter
1.It passes values into a user define procedure.It returns values from a user created procedure.It passes and returns procedure values.
2.It used for input parameter procedure value.It used for output parameter procedure value.It used for both input and output parameter procedure value.
3.It receives an initial parameter value.Does not require an initial parameter value.It receives an initial parameter value.
4.It used for searching and filtering procedure.It used for returning calculated procedure results.It used for modifying existing procedure values.

Real-life uses of IN, OUT, and INOUT parameters in stored procedures.

Input and output parameters in SQL database management systems are commonly used to perform the following database task operations.

  • Banking systems – Passing a user’s customer account number and returning the balance value from the user’s account.
  • Employee management – Passing the employee ID to the employee database table and returning employee detail information.
  • E-commerce – Passing the product ID to the e-commerce inventory system and returning product prices.
  • Inventory management – Passing the product quantity to the inventory system and returning the updated stock value.
  • Payroll systems – Passing the salary to the employee database table and returning the calculated salary.

Advantages of input and output parameters in SQL database management systems.

  • Making stored procedures usable multiple times in database tables.
  • Reducing code duplication tasks in the database.
  • Allowing for efficient communication between your user application and database data.
  • Simplifying data processing in the system.
  • Supporting flexible database table task operations.
  • Helping you output calculated result values ​​from stored procedures to database tables.

Conclusion of Input and Output Parameters.

Input and output parameters are important built-in functions or features of stored procedures in SQL database management systems. While the IN parameters method is used to pass input values, the OUT parameters method is used to return results, and the INOUT parameters method is used to accept and return modified values.

Input and output parameters make stored procedures more flexible, reusable multiple times, and efficient.

In the end, IN, OUT, and INOUT parameters provide an effective method of exchanging data between your application interface and the database, which helps simplify database operations and make this code more reusable.

Leave a Reply