大家好我正在尝试在Oracle DB上创建一个程序,但我得到2个Erros:
Error(5,5): PL/SQL: SQL Statement ignored
Error(6,20): PL/SQL: ORA-00923: FROM keyword not found where expected
这是我的代码:
create or replace PROCEDURE Nir2
IS
BEGIN
select DISTINCT AREP.CATALOG_TAG as REPOSITORY, UPPER(AREP.maindb), UPPER(MREP.SCHEMANAME), MREP.MACHINE, ctime AS CREATEDATE, TO_CHAR(MREP.LOGON_TIME, 'DD-MON-YYYY') AS LASTLOGON,
IF UPPER(a2i_xcat_dbs.a2i_serverstatus.CATALOG_TAG ) IS UPPER( a2i_xcat_dbs.a2i_catalogs.CATALOG_TAG)
THEN
'LOAD' AS MATCH
ELSE IF UPPER(MREP.SCHEMANAME) IS UPPER(AREP.maindb)
THEN
'MOUNT' AS MATCH
END
from a2i_xcat_dbs.a2i_serverstatus LREP, v$session MREP, a2i_xcat_dbs.a2i_catalogs AREP, SYS.USER$ S
where UPPER(MREP.SCHEMANAME) = UPPER(AREP.maindb) AND MREP.SCHEMANAME <> 'SYSMAN'
AND MREP.LOGON_TIME >= ALL (select MREP1.LOGON_TIME FROM v$session MREP1 where MREP.SCHEMANAME=MREP1.SCHEMANAME )
ORDER BY REPOSITORY, CREATEDATE;
END;
修改
这是我的新代码:
create or replace PROCEDURE Nir2
IS
BEGIN
select DISTINCT AREP.CATALOG_TAG as REPOSITORY, UPPER(AREP.maindb), UPPER(MREP.SCHEMANAME), MREP.MACHINE, ctime AS CREATEDATE, TO_CHAR(MREP.LOGON_TIME, 'DD-MON-YYYY') AS LASTLOGON,
CASE WHEN ( UPPER(a2i_xcat_dbs.a2i_serverstatus.CATALOG_TAG ) = UPPER( a2i_xcat_dbs.a2i_catalogs.CATALOG_TAG) )
THEN
'LOAD'
WHEN ( UPPER(MREP.SCHEMANAME) = UPPER(AREP.maindb))
THEN
'MOUNT'
END AS MATCH
from a2i_xcat_dbs.a2i_serverstatus LREP, v$session MREP, a2i_xcat_dbs.a2i_catalogs AREP, SYS.USER$ S
where UPPER(MREP.SCHEMANAME) = UPPER(AREP.maindb) AND MREP.SCHEMANAME <> 'SYSMAN'
AND MREP.LOGON_TIME >= (select MREP1.LOGON_TIME FROM v$session MREP1 where MREP.SCHEMANAME=MREP1.SCHEMANAME )
ORDER BY REPOSITORY, CREATEDATE;
END;
我仍然遇到以下错误:
Error(5,5): PL/SQL: SQL Statement ignored
Error(6,82): PL/SQL: ORA-00904: "A2I_XCAT_DBS"."A2I_CATALOGS"."CATALOG_TAG": invalid identifier
答案 0 :(得分:2)
您无法在SQL中执行“IF”。相反,做:
Case
when UPPER(a2i_xcat_dbs.a2i_serverstatus.CATALOG_TAG ) = UPPER( a2i_xcat_dbs.a2i_catalogs.CATALOG_TAG)
THEN 'LOAD'
when UPPER(MREP.SCHEMANAME) = UPPER(AREP.maindb)
THEN 'MOUNT'
END MATCH
http://docs.oracle.com/cd/E11882_01/server.112/e26088/expressions004.htm#SQLRF20037
编辑:
这......
MREP.LOGON_TIME >= ALL (select MREP1.LOGON_TIME FROM v$session MREP1 where MREP.SCHEMANAME=MREP1.SCHEMANAME )
......可能会更好......
MREP.LOGON_TIME >= (select MAX(MREP1.LOGON_TIME) FROM v$session MREP1 where MREP.SCHEMANAME=MREP1.SCHEMANAME )
答案 1 :(得分:1)
您的程序中至少有两个错误。
IF
语句。请改用CASE
。
您必须在select语句中包含INTO
子句,例如:
create or replace my_procedure
IS
l_value1 varchar2(200);
l_value2 varchar2(200);
BEGIN
select 'value 1', 'value 2'
into l_value1, l_value2
from dual;
END;