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;