Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
pl/sql中的过程_Sql_Oracle_Stored Procedures_Plsql - Fatal编程技术网

pl/sql中的过程

pl/sql中的过程,sql,oracle,stored-procedures,plsql,Sql,Oracle,Stored Procedures,Plsql,我在这个问题上遇到了一个小问题。。我已经做了我所知道的 如果可以的话,请帮忙 创建一个“插入历史”过程,将新记录插入“历史”表。 b编写一个小型PL/SQL程序,调用insert_History过程,根据以下事实插入三条记录: 一,。Mark jackop于2009年5月1日被聘用为“SH-CLERK”,并于2009年6月4日获得了一个销售代表的新职位。假设前一职位的结束日期为“2009年5月31日” 表:历史-->环境管理标识、开始日期、结束日期、作业标识、部门标识 表:员工-->员工id、姓

我在这个问题上遇到了一个小问题。。我已经做了我所知道的 如果可以的话,请帮忙

创建一个“插入历史”过程,将新记录插入“历史”表。 b编写一个小型PL/SQL程序,调用insert_History过程,根据以下事实插入三条记录:

一,。Mark jackop于2009年5月1日被聘用为“SH-CLERK”,并于2009年6月4日获得了一个销售代表的新职位。假设前一职位的结束日期为“2009年5月31日”

表:历史-->环境管理标识、开始日期、结束日期、作业标识、部门标识 表:员工-->员工id、姓名、职务id、部门id

这就是我所做的

create or replace
procedure insert_History(emp_id in integer , job_id in number) 
is 
begin 
update History
set ?????? = insert into history(.....) 
where employees.emp_id= emp_id;
end;

首先,我会把你的工作打包,因为这样可以使事情井然有序,更容易阅读/调用,并且更容易返回并记住事情是如何工作的,因为我知道在几个月没有看一个程序之后,我会忘记它到底做了什么。我可以想象这样一个噩梦:试图对某人的代码进行反向工程,而代码只是堆积在过程中,几乎没有解释它是如何工作的。您不会只在一个类中创建一个java/oop程序

另外,使用包只是一个很好的习惯,可以养成这样做的习惯,并确保对代码中的垃圾进行注释以解释它的功能

注意它似乎和纠正我,如果我错了方向要你插入而不是更新3记录。此外,它似乎需要的不仅仅是emp_id和job_id的开始和结束日期以及dep_id。因此,这些值需要通过过程获得

  create or replace
    PACKAGE "history" AS 
       procedure insert_history(pEmp_id integer, pstart_date date, pend_date date, pJob_id number, pdep_id);
    end history;

create or replace 
package body "history" as 
 procedure insert_history(pEmp_id in integer, pstart_date in date, pend_date in date,               pJob_id in number, pdep_id in number)
 is 
 begin
   insert into history(emp_id , start_date , end_date , job_id, dep_id)
   values(pEmp_id, pstart_date, pend_date, pJob_id, pdep_id );
   commit;
 end insert_history;
create or replace procedure call_insert_history(Pemp_name in varchar2(256), varchar2(256), Pstart_date in date, Pend_date in date)
is
Vemp_id number;
Vdep_id number;
Vjob_id number;
begin
--first get the emp_id, dep_id, job_id
select emp_id, dep_id, job_id into Vemp_id, Vdep_id, Vjob_id from employees where emp_name = Pemp_name;
--now call the insert_history procedure using the obtained variables.
history.insert_history(Vemp_id, Pstart_date, Pend_date, Vjob_id, Vdep_id);
end call_insert_history;
这就是插入过程的基本内容。现在你需要一个叫做这个过程的东西。在这里,我假设您从应用程序或应用程序中的更高级别获取这些日期,因此开始和结束日期以及emp名称作为参数输入。 所以我们将创建一个出色的过程

  create or replace
    PACKAGE "history" AS 
       procedure insert_history(pEmp_id integer, pstart_date date, pend_date date, pJob_id number, pdep_id);
    end history;

create or replace 
package body "history" as 
 procedure insert_history(pEmp_id in integer, pstart_date in date, pend_date in date,               pJob_id in number, pdep_id in number)
 is 
 begin
   insert into history(emp_id , start_date , end_date , job_id, dep_id)
   values(pEmp_id, pstart_date, pend_date, pJob_id, pdep_id );
   commit;
 end insert_history;
create or replace procedure call_insert_history(Pemp_name in varchar2(256), varchar2(256), Pstart_date in date, Pend_date in date)
is
Vemp_id number;
Vdep_id number;
Vjob_id number;
begin
--first get the emp_id, dep_id, job_id
select emp_id, dep_id, job_id into Vemp_id, Vdep_id, Vjob_id from employees where emp_name = Pemp_name;
--now call the insert_history procedure using the obtained variables.
history.insert_history(Vemp_id, Pstart_date, Pend_date, Vjob_id, Vdep_id);
end call_insert_history;
应该是这样

注:

这只是我最好的猜测,我还没有测试过。我只是偏离了我所理解的相当模糊的方向。如果您没有从应用程序中获取这些值,那么您必须存储每个值,然后在不使用参数的情况下调用上述过程的其余部分


希望这对你有所帮助,或者至少为你指明了正确的方向

请在家庭作业问题上加上标签,因为家庭作业不是家庭作业。这只是一个复习问题,请解释一下你所说的复习问题是什么意思。请原谅我对你的怀疑,但从你迄今为止的帖子来看,你在这个网站上提出的每个问题似乎都与学校作业有关。问家庭作业问题是可以的,但A最好不要试图掩饰它;这里的人都是专业的开发者;在我们的时代,我们已经完成了我们的家庭作业问题,当我们看到这些问题时,我们会识别它们。B你必须发布一些你确实尝试过的东西,而不仅仅是一些没有机会运行的假装代码。[家庭作业]指的是任何来自教育目的的问题,这一定义显然延伸到了修订。就我个人而言,我认为在SO上张贴家庭作业问题比那些无法从湿纸袋中编码出来的人从雇主那里拿钱来写程序更不道德。然而,如果你依赖我们来写一个解决方案,而不是自己去解决,你将永远学不到任何东西。