nemp表 id number(6) not null,name varchar2(20),hiredate date not null,job varchar2(10) not null,sal number(8,2),mgr number(6),deptno number(4)问题;建立函数get_sal,根据输入的雇员号返回雇员名和工资,不存在则显示消息“该雇员不存在”
我的答案;
create or replace function get_sal(eno number)
return varchar2,number
is
name nemp.name%type;
salary nemp.sal%type;
flag int;
begin
select count(id) into flag from nemp;
if flag>0 then
select sal into salary from nemp where id=eno;
return name,salary;
else
dbms_output.put_line('该雇员不存在');
end if;
end;
/
结果说带有编辑错误,
我的答案;
create or replace function get_sal(eno number)
return varchar2,number
is
name nemp.name%type;
salary nemp.sal%type;
flag int;
begin
select count(id) into flag from nemp;
if flag>0 then
select sal into salary from nemp where id=eno;
return name,salary;
else
dbms_output.put_line('该雇员不存在');
end if;
end;
/
结果说带有编辑错误,
解决方案 »
- 11gr2恢复 11g导出的数据 提示不是有效的导出文件 求助 在线等
- PLSQL问题请帮忙 谢谢!
- Oracle里有个表存放的是sql语句,有没有办法每天将这里面的sql导成excel?
- 按时间降序排序,只显示降序排序的第一行.
- 不存在列问题,请来点破一下,死活没看出来
- 看书时遇到的一个问题!
- 如何建立、运行一个在0点调用存储过程proc_insert的trigger?
- 怎样把从ORACLE9中导出的DMP文件,导入到ORACLE8中???
- 那里有Oracle9i for OleDB 驱动的下载
- 请推荐oracle store procedure的书籍(下载),谢谢!
- 帮忙解决一个有问题的sql语句
- 帮我写条sql
不能这样用吧?
多个返回值的情况,可以使用out的参数来解决。
SQL> ed
已写入 file afiedt.buf 1 create or replace procedure
2 tpro(v_no in emp.empno%type,v_name out varchar2,v_sal out number)
3 as
4 flag number;
5 begin
6 select count(*) into flag from emp where empno=v_no;
7 if flag>0 then
8 select ename,sal into v_name,v_sal from emp where empno=v_no;
9 else
10 dbms_output.put_line('该员工不存在');
11 end if;
12 exception
13 when others then
14 dbms_output.put_line('执行出错');
15* end;
SQL> /过程已创建。SQL> declare
2 name varchar2(100);
3 sal number;
4 begin
5 tpro('7369',name,sal);
6 dbms_output.put_line(name||to_char(sal));
7 end;
8 /
SMITH800PL/SQL 过程已成功完成。
create or replace function get_sal(eno number) return varchar2,number
改为
create or replace function get_sal(eno in number, sName out varchar2, sSalary out varchar2) return number
create or replace function get_sal(eno number,name out varchar2,salary out number)
return number
is
name nemp.name%type;
salary nemp.sal%type;
flag int;
begin
select count(id) into flag from nemp;
if flag>0 then
select sal into salary from nemp where id=eno;
else
dbms_output.put_line('该雇员不存在');
end if;
end;
/
还是有编辑错误,
return number
is
salary nemp.sal%type;
flag int;
begin
select count(id) into flag from nemp;
if flag>0 then
select sal into salary from nemp where id=eno;
return salary;
else
dbms_output.put_line('该雇员不存在');
end if;
end;
/新的,没有编辑错误,但调用不行,你试下,
is
flag int;
name_sal varchar2(50);
begin
select count(id) into flag from nemp;
if flag>0 then
select name||','||sal into name_sal from nemp where id=eno;
return name_sal;
else
dbms_output.put_line('该雇员不存在');
end if;
end;--
select get_sal('员工号') from nemp
is
flag int;
name_sal varchar2(50);
begin
select count(id) into flag from nemp where id=eno; --where id=eno加个这个
if flag>0 then
select name||','||sal into name_sal from nemp where id=eno;
return name_sal;
else
dbms_output.put_line('该雇员不存在');
end if;
end;