--创建一个表
create table salary_details
(
empcode varchar2(10) not null,
workdays number,
salary number,
constraints salary_details_empcode_pk primary key(empcode)
);
这是我写的函数
--利用在问题1种创建的salary_details表,创建work_days函数,
--接受EMPCODE雇员编号,并检查所有雇员的工作天数。
--标准工作天数为22天,雇员每少工作一天从其工资中扣除50元。
--函数输出雇员最后的工资,工作天数多于标准天数不加工资,
--工资扣完为止,不可为负值。
create or replace function xn_calday1(code varchar2)
return number is v_sal number;
v_days number;
begin
select workdays into v_days from salary_details where empcode=code;
if v_days>=22 then
select salary into v_sal from salary_details where empcode=code;
--dbms_output.put_line(code||'工作了'||v_days||'天,工资是:'||v_sal);
elsif v_days<22 then
select salary into v_sal from salary_details where empcode=code;
v_sal:=v_sal-(22-v_days)*50;
if v_sal<=0 then
v_sal:=0;
--dbms_output.put_line(code||'工作了'||v_days||'天,工资是:'||'0');
end if;
--dbms_output.put_line(code||'工作了'||v_days||'天,工资是:'||v_sal);
end if;
dbms_output.put_line(code||'工作了'||v_days||'天,工资是:'||v_sal);
return v_sal;
end;
为什么最后没有在窗口中打印出“code||'工作了'||v_days||'天,工资是:'||v_sal”?
create table salary_details
(
empcode varchar2(10) not null,
workdays number,
salary number,
constraints salary_details_empcode_pk primary key(empcode)
);
这是我写的函数
--利用在问题1种创建的salary_details表,创建work_days函数,
--接受EMPCODE雇员编号,并检查所有雇员的工作天数。
--标准工作天数为22天,雇员每少工作一天从其工资中扣除50元。
--函数输出雇员最后的工资,工作天数多于标准天数不加工资,
--工资扣完为止,不可为负值。
create or replace function xn_calday1(code varchar2)
return number is v_sal number;
v_days number;
begin
select workdays into v_days from salary_details where empcode=code;
if v_days>=22 then
select salary into v_sal from salary_details where empcode=code;
--dbms_output.put_line(code||'工作了'||v_days||'天,工资是:'||v_sal);
elsif v_days<22 then
select salary into v_sal from salary_details where empcode=code;
v_sal:=v_sal-(22-v_days)*50;
if v_sal<=0 then
v_sal:=0;
--dbms_output.put_line(code||'工作了'||v_days||'天,工资是:'||'0');
end if;
--dbms_output.put_line(code||'工作了'||v_days||'天,工资是:'||v_sal);
end if;
dbms_output.put_line(code||'工作了'||v_days||'天,工资是:'||v_sal);
return v_sal;
end;
为什么最后没有在窗口中打印出“code||'工作了'||v_days||'天,工资是:'||v_sal”?
把输出打开
在sql/developer中
var aaa number;
call calday1('xn001')into:aaa;
这个时候回车 不打印
print aaa;
的时候还是没有dbms的串
但你可以在sql*plus中国执行呀!
向上面说的那样:执行前设置一下:
set serveroutput on;
然后再执行相应的函数即可!
var aaa number;
select calday1('xn001') into :aaa from dual;
print aaa;
set serveroutput on;
然后执行你的函数。
dbms_output.put_line主要用作调试。
把输出打开
set serveroutput on