【问题标题】:Procedure to return first name when inputting last name输入姓氏时返回名字的过程
【发布时间】:2014-01-21 17:12:02
【问题描述】:
create or replace procedure p_inout
(v_emp_lname in varchar2(25))
as
v_first_name varchar2(20);
begin
select first_name into v_first_name
from employees
where last_name=v_emp_lname;
dbms_output.put_line(v_first_name);
end;

我得到 错误(2,25):PLS-00103:在预期以下之一时遇到符号“(”::=。),@%默认字符符号“:=”被替换为“(”以继续。

【问题讨论】:

  • 您的问题标题似乎具有误导性...请具体

标签: oracle plsql procedure


【解决方案1】:

varchar2 等参数参数类型没有大小属性​​,因此将“varchar2(25)”替换为“varchar2”。

请参阅Oracle docs 了解参数用法。具体来说:

**Parameter Datatypes**
The datatype of a formal parameter consists of one of the following:

An unconstrained type name, such as NUMBER or VARCHAR2.

A type that is constrained using the %TYPE or %ROWTYPE attributes

【讨论】:

  • 酷它工作。一些员工的姓氏相同,因此结果将返回多于 1 条记录。我收到此错误 ORA-01422:精确提取返回超过请求的行数 ORA-06512:在“HR.P_INOUT”第 6 行 ORA-06512:在第 1 行 01422.00000 -“精确提取返回超过请求的行数rows" *原因:exact fetch 中指定的数量小于返回的行数。 *操作:重写查询或更改请求的行数如何返回超过 1 条记录?
  • 请将其作为一个不同的问题发布。这与手头的问题无关。
【解决方案2】:
To fetch more than more record you have to use cursor. The code above needs some modification to fetch more than one record.

create or replace procedure p_inout
(v_emp_lname in varchar2)
as
v_first_name varchar2(20);
begin
for rec in (select first_name
from employees
where last_name=v_emp_lname)
loop
dbms_output.put_line('First name/s'||' '||rec.first_name);
end loop;
end;

【讨论】:

    猜你喜欢
    • 2021-07-22
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    • 2013-01-07
    • 1970-01-01
    相关资源
    最近更新 更多