Tuesday, July 11, 2017

PL/SQL Procedure- Create the procedure add_jobs on the jobs table of HR schema.

PL/SQL Procedure-Insert data into Table
======================================================================

create or replace procedure add_jobs(v_job_id  jobs.job_id%type,v_job_title   jobs.job_title%type,v_max_salary   jobs.max_salary%type,v_min_salary  jobs.min_salary%type)
is
begin
insert into jobs(job_id, job_title,min_salary,max_salary) values(v_job_id ,v_job_title ,v_min_salary ,v_max_salary );
end;
/

=======================================================================
--Method 1-call the procedure  
========================================================================

begin
add_jobs('DM','Dupty Manager',11000,1000);
end;
/

--Verify the data inserted into the table jobs

SQL> select * from jobs where job_id='DM';

JOB_ID     JOB_TITLE                           MIN_SALARY MAX_SALARY
---------- ----------------------------------- ---------- ----------
DM         Dupty Manager                             1000      11000

SQL>
--========================================================================
Method 2 :Ask user to enter the  values  into jobs  table and verify the data
=============================================================

SQL> begin
  2  add_jobs( '&v_job_id' ,'&v_job_title' ,&v_min_salary ,&v_max_salary);
  3  end;
  4  /
Enter value for v_job_id: HR1
Enter value for v_job_title: HR Dept
Enter value for v_min_salary: 500
Enter value for v_max_salary: 3500
old   2: add_jobs( '&v_job_id' ,'&v_job_title' ,&v_min_salary ,&v_max_salary);
new   2: add_jobs( 'HR1' ,'HR Dept' ,500 ,3500);

PL/SQL procedure successfully completed.

--check the inserted data into the table 

SQL> select * from jobs where job_id='HR1';

JOB_ID     JOB_TITLE                           MIN_SALARY    MAX_SALARY
---------- ----------------------------------- ----------                       ----------
HR1        HR Dept                                    500                            3500

SQL>

No comments:

Post a Comment