如何将变量值传递给存储过程

时间:2013-12-17 17:20:09

标签: stored-procedures oracle11g

我创建了一个变量className,并为其分配了值。 我在oracle中有另一个程序向我发送电子邮件。 如何将此值传递到我的电子邮件的标题和正文中?

VARIABLE className varchar2(30)
    :classname := 0;
    BEGIN
     FOR i IN 
     (
        SELECT CLASS_INSTANCE_COUNT , CLASS_NAME
        FROM MODEL_CLASS_COUNTS 
        WHERE TRUNC(COUNT_DATETIME) = TRUNC(SYSDATE)
     )
        LOOP    
          IF i.CLASS_INSTANCE_COUNT = 0 
          THEN 
              :className := i.CLASS_NAME;
              EMAIL('myemail@col.com',  'email header: &className is 0', 'body: count for &className is 0');
          END IF;
        END LOOP;
    END;
    /

1 个答案:

答案 0 :(得分:1)

我的猜测是你不想拥有SQL * Plus变量或替换变量。我猜你只想要

BEGIN
 FOR i IN 
   (
      SELECT CLASS_INSTANCE_COUNT , CLASS_NAME
        FROM MODEL_CLASS_COUNTS 
       WHERE TRUNC(COUNT_DATETIME) = TRUNC(SYSDATE)
   )
 LOOP    
   IF i.CLASS_INSTANCE_COUNT = 0 
   THEN 
     EMAIL('myemail@col.com',  
           'email header: ' || i.class_name || ' is 0', 
           'body: count for ' || i.class_name || ' is 0');
   END IF;
 END LOOP;
END;