PL/SQL:程序在包中无法正常工作

发布于 2024-07-17 07:46:54 字数 1867 浏览 4 评论 0原文

我正在开发一个包含一些程序的包,但我遇到了一些麻烦。 当我尝试测试将加仑转换为升的过程或其他过程时,它只是打印出未命名块中声明的内容,而不是转换数字。 有任何想法吗?

CREATE OR REPLACE PACKAGE eng_metric 
IS 
  PROCEDURE convert(degree_fahrenheit  IN OUT NUMBER,degree_celsius  IN OUT NUMBER,measure  IN VARCHAR2); 

  PROCEDURE convert(liters  IN OUT NUMBER,gallons  IN OUT NUMBER); 
END eng_metric; 
/ 

CREATE OR REPLACE PACKAGE BODY eng_metric 
AS 
  PROCEDURE Convert 
       (degree_fahrenheit  IN OUT NUMBER, 
        degree_celsius     IN OUT NUMBER, 
        measure            IN VARCHAR2) 
  IS 
    df         NUMBER; 
    dc         NUMBER; 
    convertf   NUMBER; 
    measurecf  VARCHAR2(4); 
  BEGIN 
    measurecf := measure; 

    df := degree_fahrenheit; 

    dc := degree_celsius; 

    IF measure = 'TEMP' THEN 
      IF dc = NULL THEN 
        convertf := ((df - 32) * .56); 

        degree_fahrenheit := convertf; 

        dbms_output.Put_line('The temperature in fahrenheit is ' 
                             ||To_char(degree_fahrenheit)); 
      ELSIF df = NULL THEN 
        convertf := (dc + 17.98) * 1.8; 

        degree_celsius := convertf; 
      END IF; 
    ELSE 
      dbms_output.Put_line('Invalid measure'); 
    END IF; 
  END convert; 

  PROCEDURE Convert 
       (liters   IN OUT NUMBER, 
        gallons  IN OUT NUMBER) 
  IS 
    lit        NUMBER; 
    gal        NUMBER; 
    convertlg  NUMBER; 
  BEGIN 
    lit := liters; 

    gal := gallons; 

    IF gal = NULL THEN 
      convertlg := (lit / 3.785); 

      liters := convertlg; 
    ELSIF lit = NULL THEN 
      convertlg := (gal * 3.785); 

      gallons := convertlg; 
    END IF; 
  END convert; 
END eng_metric; 
/ 

DECLARE 
  liters   NUMBER := 25; 
   gallons  NUMBER := 41; 
   nully    NUMBER := NULL; 
BEGIN 
  eng_metric.Convert(nully,gallons); 

  dbms_output.Put_line(To_char(gallons)); 
END; 
/ 

 

I'm working on a package with some procedures in them and I'm running into a bit of trouble. When I try to test the procedure to convert gallons to liters or the other procedures, it just prints out what was declared in the unnamed block instead of converting the numbers. Any ideas?

CREATE OR REPLACE PACKAGE eng_metric 
IS 
  PROCEDURE convert(degree_fahrenheit  IN OUT NUMBER,degree_celsius  IN OUT NUMBER,measure  IN VARCHAR2); 

  PROCEDURE convert(liters  IN OUT NUMBER,gallons  IN OUT NUMBER); 
END eng_metric; 
/ 

CREATE OR REPLACE PACKAGE BODY eng_metric 
AS 
  PROCEDURE Convert 
       (degree_fahrenheit  IN OUT NUMBER, 
        degree_celsius     IN OUT NUMBER, 
        measure            IN VARCHAR2) 
  IS 
    df         NUMBER; 
    dc         NUMBER; 
    convertf   NUMBER; 
    measurecf  VARCHAR2(4); 
  BEGIN 
    measurecf := measure; 

    df := degree_fahrenheit; 

    dc := degree_celsius; 

    IF measure = 'TEMP' THEN 
      IF dc = NULL THEN 
        convertf := ((df - 32) * .56); 

        degree_fahrenheit := convertf; 

        dbms_output.Put_line('The temperature in fahrenheit is ' 
                             ||To_char(degree_fahrenheit)); 
      ELSIF df = NULL THEN 
        convertf := (dc + 17.98) * 1.8; 

        degree_celsius := convertf; 
      END IF; 
    ELSE 
      dbms_output.Put_line('Invalid measure'); 
    END IF; 
  END convert; 

  PROCEDURE Convert 
       (liters   IN OUT NUMBER, 
        gallons  IN OUT NUMBER) 
  IS 
    lit        NUMBER; 
    gal        NUMBER; 
    convertlg  NUMBER; 
  BEGIN 
    lit := liters; 

    gal := gallons; 

    IF gal = NULL THEN 
      convertlg := (lit / 3.785); 

      liters := convertlg; 
    ELSIF lit = NULL THEN 
      convertlg := (gal * 3.785); 

      gallons := convertlg; 
    END IF; 
  END convert; 
END eng_metric; 
/ 

DECLARE 
  liters   NUMBER := 25; 
   gallons  NUMBER := 41; 
   nully    NUMBER := NULL; 
BEGIN 
  eng_metric.Convert(nully,gallons); 

  dbms_output.Put_line(To_char(gallons)); 
END; 
/ 

 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜巴黎 2024-07-24 07:46:54

而不是

IF gal = NULL THEN

你需要

IF gal IS NULL

Instead of

IF gal = NULL THEN

you need

IF gal IS NULL
水中月 2024-07-24 07:46:54

你必须记住的是 NULL 意味着“没有值”。 它永远不会等于或不等于任何内容,包括 NULL。 所以你需要使用IS NULL或IS NOT NULL,或者使用NVL函数将null更改为有值的东西。

What you have to remember is that NULL means "no value". It NEVER equals or fails to equal anything, including NULL. So you need to use IS NULL or IS NOT NULL, or use the NVL function to change the null to something that has a value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文