【发布时间】:2020-09-21 22:45:01
【问题描述】:
创建一个名为 'find_company' 的函数,它接受一个字符并显示公司名称以使用光标输入的给定字符开头。 提示: 程序名称:find_company 输入参数:alpha,数据类型为 varchar 输出参数:company_name,数据类型为 varchar 设计规则: 1) 如果作为输入传递的字符(即 alpha)匹配,则返回公司名称。 2) 如果作为输入传递的字符(即 alpha)不匹配,则使用 'cursorname%notfound' 返回带有文本为 'No such Companies with the given Character' 的 company_name。
我编码如下
create or replace procedure find_company (alpha IN varchar2)
AS
cursor test_cur(alpha IN VARCHAR2)
IS
select name from company where name like alpha||'%';
ret _company_name company.name%TYPE;
begin
OPEN test_cur(alpha);
LOOP
FETCH test_cur into ret_company_name;
dbms_output.put_line(ret_company_name);
EXIT WHEN test_cur%NOTFOUND THEN ret_company_name:='No Such Companies with the given Character';
close test_cur;
end;
/
出现以下错误: 警告:创建的过程存在编译错误。 d := find_company('C'); * 第 7 行的错误: ORA-06550:第 7 行,第 9 列: PLS-00905:对象 P10456.FIND_COMPANY 无效 ORA-06550:第 7 行,第 4 列: PL/SQL:语句被忽略
我哪里做错了?我没有使用“显示错误”命令的选项
【问题讨论】:
-
在我的脑海中,没有
end loop,你不能在exit when声明中使用then。 -
如果多个公司名称匹配输入怎么办?输出需要什么? Varchar 或 cursor 或 UDT?
-
回答 ORA_Dentist - 输出参数:数据类型为 varchar 的公司名称
标签: oracle