调用该过程时出现此错误。我正在尝试这样做。
创建一个名为find_region_and_currency的过程,以获取并返回一个国家所在的货币和地区。 传递COUNTRY_NAME作为IN参数,并使用用户定义的记录作为OUT参数,以返回国家/地区名称,其地区和货币。
我从这里尝试了旧答案,但我没有这样做。你能帮我吗?
CREATE OR REPLACE PACKAGE traveler_assistance_package
IS
TYPE country_rec IS RECORD (
country_name COUNTRIES.COUNTRY_NAME%TYPE,
region COUNTRIES.REGION_ID%TYPE,
currency COUNTRIES.CURRENCY_CODE%TYPE);
PROCEDURE find_region_and_currency
(p_country_name IN COUNTRIES.country_name%TYPE,
p_country_rec OUT country_rec);
END traveler_assistance_package;
CREATE OR REPLACE package body traveler_assistance_package
IS
PROCEDURE find_region_and_currency
(p_country_name IN countries.country_name%TYPE,
p_country_rec OUT country_rec)
IS
BEGIN
SELECT country_name, region_id, currency_code INTO p_country_rec
FROM COUNTRIES
where COUNTRY_NAME = p_country_name;
DBMS_OUTPUT.PUT_LINE('Country Name:'||p_country_rec.country_name ||
'Region:' || p_country_rec.region ||
'Currency:' || p_country_rec.currency);
END;
END traveler_assistance_package;
答案 0 :(得分:2)
您没有发布出错的地方(代码的哪一部分);无论如何,你去这里。
样品表:
SQL> create table countries
2 (country_name varchar2(20),
3 region_id varchar2(20),
4 currency_code varchar2(20));
Table created.
SQL> insert into countries values ('Croatia', 'A', 'kn');
1 row created.
包装:
SQL> CREATE OR REPLACE PACKAGE traveler_assistance_package
2 IS
3 TYPE country_rec IS RECORD (
4 country_name COUNTRIES.COUNTRY_NAME%TYPE,
5 region COUNTRIES.REGION_ID%TYPE,
6 currency COUNTRIES.CURRENCY_CODE%TYPE);
7 PROCEDURE find_region_and_currency
8 (p_country_name IN COUNTRIES.country_name%TYPE,
9 p_country_rec OUT country_rec);
10 END traveler_assistance_package;
11 /
Package created.
包装体:
SQL> CREATE OR REPLACE package body traveler_assistance_package
2 IS
3 PROCEDURE find_region_and_currency
4 (p_country_name IN countries.country_name%TYPE,
5 p_country_rec OUT country_rec)
6 IS
7 BEGIN
8 SELECT country_name, region_id, currency_code INTO p_country_rec
9 FROM COUNTRIES
10 where COUNTRY_NAME = p_country_name;
11
12 --dbms_output.put_line('Printing from FIND_REGION_AND_CURRENCY');
13 --DBMS_OUTPUT.PUT_LINE('Country Name:'||p_country_rec.country_name ||
14 -- ' Region:' || p_country_rec.region ||
15 -- ' Currency:' || p_country_rec.currency);
16 END;
17 END traveler_assistance_package;
18 /
Package body created.
测试:
SQL> set serveroutput on;
SQL> declare
2 l_out traveler_assistance_package.country_rec;
3 begin
4 traveler_assistance_package.find_region_and_currency ('Croatia', l_out);
5
6 dbms_output.put_line('Printing from anonymous PL/SQL block');
7 dbms_output.put_line(l_out.country_name ||', '|| l_out.currency);
8 end;
9 /
Printing from anonymous PL/SQL block
Croatia, kn
PL/SQL procedure successfully completed.