IF ELSIF有什么问题?

时间:2016-06-17 18:17:36

标签: oracle

    DECLARE DBName VARCHAR(100); ApplicationURL VARCHAR(100);

BEGIN
select NAME into DBName FROM v$database;  

  IF DBName = 'WAMDEV' THEN ApplicationURL := 'http://srpwam10:9080/maximo';
      ELSIF  DBName ='WAMDEVPJ' THEN ApplicationURL := 'http://srpwam10:9080/maximo';
      ELSIF  DBName = 'WAMTST' THEN ApplicationURL := 'http://wamtest/maximo'
      ELSIF  DBName = 'WAMTSTPJ' THEN ApplicationURL := 'http://wamtest/maximo'
      ELSIF  DBName = 'WAMQA' THEN ApplicationURL := 'http://wamqa/maximo'
      ELSIF  DBName = 'WAMQAPJ'  THEN ApplicationURL := 'http://wamqa/maximo'
      ELSE  DBName = 'WAMP' THEN ApplicationURL := 'http://wam/maximo'
    END IF ;
    DBMS_OUTPUT.PUT_LINE(ApplicationURL)
    END

它给了我错误: ORA-06550:第9行,第7栏: PLS-00103:遇到以下任何一种情况时遇到符号“ELSIF”:

  • &安培; = - +; < />在in是mod余数而不是rem  <>或!=或〜=> =< =<>或者喜欢喜欢2 like | likec之间的|| multiset成员submultiset
    1. 00000 - “行%s,列%s:\ n%s” *原因:通常是PL / SQL编译错误。

1 个答案:

答案 0 :(得分:1)

添加了您缺少的半冒号

DECLARE
  DBNAME         VARCHAR(100);
  APPLICATIONURL VARCHAR(100);

BEGIN
  SELECT NAME INTO DBNAME FROM V$DATABASE;

  IF DBNAME = 'WAMDEV' THEN
    APPLICATIONURL := 'http://srpwam10:9080/maximo';
  ELSIF DBNAME = 'WAMDEVPJ' THEN
    APPLICATIONURL := 'http://srpwam10:9080/maximo';
  ELSIF DBNAME = 'WAMTST' THEN
    APPLICATIONURL := 'http://wamtest/maximo';
  ELSIF DBNAME = 'WAMTSTPJ' THEN
    APPLICATIONURL := 'http://wamtest/maximo';
  ELSIF DBNAME = 'WAMQA' THEN
    APPLICATIONURL := 'http://wamqa/maximo';
  ELSIF DBNAME = 'WAMQAPJ' THEN
    APPLICATIONURL := 'http://wamqa/maximo';
  ELSE
    DBNAME := 'WAMP';
    APPLICATIONURL := 'http://wam/maximo';
  END IF;
  DBMS_OUTPUT.PUT_LINE(APPLICATIONURL);
END;

也可以使用CASE声明,在某些人看来,它看起来更干净。