Stored Procedure with no parameters

Source: Internet
Author: User
SQL call Stored Procedure statement: call procedure_name ();

Note: "()" is indispensable for calling, whether there are parameters or no parameters.

When calling a database Stored Procedure
1. No parameter stored procedure: {call procedure_name}
2. Stored Procedure with only input parameters: {call procedure_name (?,?...)}.
Here? Indicates input parameters. When a stored procedure is created, in indicates input parameters.
3. Stored Procedure with only output parameters: {call procedure_name (?,?...)}.
Here? Output Parameters. When a stored procedure is created, output parameters are expressed as out parameters.
4. Stored Procedure {call procedure_name (?,?...)} with both input and output parameters (?,?...)}.
Here? Either the output parameter or the input parameter

The following examples are provided for these four cases !!! 1. No parameter Stored Procedure

Create or replace procedure stu_proc
-- Declaration statement segment
V_name VARCHAR2 (20 );
BEGIN
-- Execution statement segment
SELECT o. sname INTO v_name FROM student o WHERE o. id = 4;
Dbms_output.put_line (v_name );
EXCEPTION
-- Exception Handling statement segment
WHEN NO_DATA_FOUND THEN dbms_output.put_line ('no _ DATA_FOUND ');
END;

2. Stored Procedure with only Parameters

Create or replace procedure stu_proc (v_id IN student. id % type)
-- Declaration statement segment
V_name varchar2 (20 );
BEGIN
-- Execution statement segment
SELECT o. sname INTO v_name FROM student o where o. id = v_id;
Dbms_output.put_line (v_name );
EXCEPTION
-- Exception Handling statement segment
WHEN NO_DATA_FOUND THEN dbms_output.put_line ('no _ DATA_FOUND ');
END;

3. Stored Procedure with only Parameters

-- This stored procedure cannot be called directly using call. In this case, the call will be described in the following oracle function call
Create or replace procedure stu_proc (v_name OUT student. sname % type)
-- Declaration statement segment
BEGIN
-- Execution statement segment
SELECT o. sname INTO v_name FROM student o where o. id = 1;
Dbms_output.put_line (v_name );
EXCEPTION
-- Exception Handling statement segment
WHEN NO_DATA_FOUND THEN dbms_output.put_line ('no _ DATA_FOUND ');
END;

4. Stored Procedure of Input and Output Parameters

-- This stored procedure cannot be called directly using call. In this case, the call will be described in the following oracle function call
Create or replace procedure stu_proc (v_id IN student. id % type, v_name OUT student. sname % type)
-- Declaration statement segment
BEGIN
-- Execution statement segment
SELECT o. sname INTO v_name FROM student o where o. id = v_id;
Dbms_output.put_line (v_name );
EXCEPTION
-- Exception Handling statement segment
WHEN NO_DATA_FOUND THEN dbms_output.put_line ('no _ DATA_FOUND ');
END;

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.