在select语句中不能使用过程?

时间:2016-03-08 18:02:36

标签: plsql procedure

以下是我创建类型和表格的代码。一切都正确:

CREATE TYPE shape_typ AS OBJECT (
l   INTEGER, -- length
w   INTEGER, -- width
h   INTEGER, -- height
MEMBER FUNCTION area RETURN INTEGER,
MEMBER FUNCTION volume RETURN INTEGER,
MEMBER PROCEDURE display (SELF IN OUT NOCOPY shape_typ) );

CREATE TYPE BODY shape_typ AS 
MEMBER FUNCTION volume RETURN INTEGER IS
BEGIN
   RETURN l * w * h;
-- same as previous line RETURN SELF.l * SELF.w * SELF.h; 
END;
MEMBER FUNCTION area RETURN INTEGER IS
BEGIN -- not necessary to include SELF in following
    RETURN 2 * (l * w + l * h + w * h);
END;
MEMBER PROCEDURE display (SELF IN OUT NOCOPY shape_typ) IS
  BEGIN
   DBMS_OUTPUT.PUT_LINE('Length: ' || l || ' - ' || 
                        'Width: ' || w || ' - ' ||
                        'Height: ' || h );
   DBMS_OUTPUT.PUT_LINE('Volume: ' || volume || ' - ' || 
                        'Area: ' || area );
  END;
END;

CREATE TABLE shapes (
shape       shape_typ,
create_date DATE );

INSERT INTO shapes VALUES (
shape_typ (3,3,3), '17-MAR-2008' );

INSERT INTO shapes VALUES (
shape_typ (1,8,2), '17-FEB-2008' );

INSERT INTO shapes VALUES (
shape_typ (1,1,1), '27-MAR-2008' );

SELECT s.shape.l,s.shape.w,s.shape.h,s.shape.area() FROM shapes s;

DECLARE
shap shapes%rowtype;
BEGIN -- PL/SQL block for selecting-displaying a student
  SELECT * INTO shap
    FROM shapes s 
    WHERE s.shape.l=1 and s.shape.w=1 and s.shape.h=1;
  shap.shape.display;
END;

但是,当我尝试在以下语句中执行该过程时,它会给我一条错误消息。

SELECT s.shape.l,s.shape.w,s.shape.h,s.shape.display() FROM shapes s;

错误信息是:

  

ORA-06553:PLS-222:没有名称' DISPLAY'存在于此范围内       06553. 00000 - " PLS-%s:%s"       *原因:
      *行动:       行错误:49列:38

我想知道是否因为我不能在select语句中使用该过程?

1 个答案:

答案 0 :(得分:2)

不,您无法在SQL语句中使用过程。

过程DISPLAY只能在PL / SQL上下文中使用。

请参阅Oracle文档:Coding PL/SQL Subprograms and Packages