Create a process to add a new record to the table dept

1. Create a process to add a new record to the table dept. (In parameters)

  • Creation process:
create or replace procedure Insert_dept

	( num_dept in number

	,v_ename in varchar3)is

begin

	insert into dept

	values(num_dept,v_ename);

	commit;

end insert_dept;
  • transfer:
begin

	insert_dept(66,'人事');

end;

2. Query from scott.emp given in the table staff (Hint: Use & to input employee number) names and salaries of employees. (Requirements: out mode using parameter values ​​to the caller.)

  • Creation process:
create or replace procedure query_emp

	(num_empno in emp.empno%type

	,emp_name out emp.ename%type

	,emp_salary out emp.sal%type)is

begin

	select ename,sal into emp_name,emp_salary
	from emp where empno = num_empno;

exception

	when no_data_found then

       	dbms_output.put_line('查询错误');

end query_emp;
  • transfer:
declare

	(var_ename emp.ename%type

	,var_salary emp.sal%type)is

begin

	query_emp(&职工号,var_ename,var_salary);

	if var_ename is not null then

	dbms_output.put_line(var_ename||' '||var_salary);

	end if;

end;

3. Create a process, in the implementation of the calling process, randomly enter the name of an employee in the emp table, according to the employee's name, the return value of the employee's salary, and output. (Out parameters)

  • Creation process:
create or replace procedure select_emp 

	(emp_name in emp.ename%type

	,emp_salary out emp.sal%type) is

begin

	select sal into emp_salary from emp
	where ename = emp_name;

exception 

	when no_data_found then

	dbms_output.put_line(‘查询错误’);

end select_emp;
  • transfer:
declare

	v_sal number(5);

begin

	select_emp('&雇员姓名',v_sal);

	dbms_output.put_line(v_sal);

end;

4. The preparation process, implement the functions of the exchange value of two variables. Two output values ​​before and after the switching and exchange. (In out parameters)

  • Creation process:
create or replace procedure swap_number

	(num1 in out number

	,num2 in out number)is 

	temp number(5);

begin

	temp:=num1;

	num1:=num2;

	num2:=temp;

end swap_number;
  • transfer:
declare

	a number:=666;

	b number:=999;

begin

	dbms_output.put_line('Befor:'||a||'  '||b);

	swap_number(a,b);

	dbms_output.put_line('Now:'||a||'  '||b);

end;

5. Create a stored procedure, remove scott.emp table records the employee number. (Hint: employee number provided by the caller statement to delete records, requires that employee numbers be random input.).

  • Creation process:
create
or replace procedure delete_emp

(emp_no dept.empno%type) is

begin
	Delete from dept where empno = emp_no;
end delete_emp;
  • transfer:
execute
	delete_emp('&员工编号');
Published 15 original articles · won praise 25 · views 3651

Guess you like

Origin blog.csdn.net/JXAU_LCY/article/details/104967689