traveler_assistance_package。对用户定义的记录和选择语句的过程find_region_and_currency修订

时间:2019-03-04 14:36:42

标签: oracle plsql-package

当前为pl / sql项目创建一个名为traveler_assistance_package的软件包。对于其中一个问题,我的任务是创建一个用户定义的记录,以查找特定国家的country_name region_name和currency_name。 关于我是否应该基于提供此信息的三个单独表格还是来自一个表格国家来创建此记录,这个问题尚不清楚。到目前为止,我已经将记录保存在一张表中,并且能够基于该表获得结果,但是,如果可以的话,我想尝试使用另一种方法。 代替下面的示例(从TYPE country_rec IS RECORD开始),我将尽可能构造这样的记录:

TYPE country_rec IS RECORD(
        country_name COUNTRIES.COUNTRY_NAME%TYPE,
        region REGION.REGION_NAME%TYPE,
        currency CURRENCY.CURRENCY_NAME%TYPE);

但是,我对如何更改程序包主体中的select语句以打印出所需结果有点不知所措。以下是到目前为止我的包裹和包裹主体的副本。任何和所有帮助将不胜感激。

    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 country_demographic
 (p_country_name IN countries.country_name%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 country_demographics

    procedure country_demographic

    (p_country_name IN countries.country_name%TYPE)

    IS
     TYPE ED_TYPE IS TABLE OF countries%ROWTYPE;
     p_country_demo_rec  ED_TYPE;

     BEGIN

SELECT * BULK COLLECT INTO p_country_demo_rec FROM countries
WHERE country_name = p_country_name;
IF SQL%NOTFOUND THEN
    RAISE_APPLICATION_ERROR(-20201, 'This country does not exist.');
END IF;
FOR i IN p_country_demo_rec.FIRST..p_country_demo_rec.LAST 
LOOP
DBMS_OUTPUT.PUT_LINE('Country Name:'||p_country_demo_rec(i).country_name || 
      'Location:' || p_country_demo_rec(i).location || 
      'Capitol:' || p_country_demo_rec(i).capitol || 
      'Population:' || p_country_demo_rec(i).population || 
      'Airports:' || p_country_demo_rec(i).airports || 
      'Climate:' || p_country_demo_rec(i).climate );
END LOOP;

END;

    --procedure find_region_and_currency
      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 个答案:

没有答案