我正在尝试存储字符串并使用我的sql代码中的变量进行连接,但我一直在收到错误。这就是我试过的:
DECLARE
ENV VARCHAR(9999);
MV VARCHAR(999);
MVNAME VARCHAR(999) := 'TEST2';
BEGIN
-- GET ENVIRONMENT
SELECT sys_context('USERENV','DB_NAME')
INTO ENV
FROM DUAL;
MV := 'CREATE MATERIALIZED VIEW' || MVNAME ||
'COMPRESS
NOLOGGING
PARTITION BY HASH (DATAID)
PARTITIONS 16
PARALLEL
BUILD IMMEDIATE
USING INDEX
REFRESH
NEXT trunc(SYSDATE, ''hh'') + 1/24
FAST
WITH ROWID
USING DEFAULT LOCAL ROLLBACK SEGMENT
ENABLE QUERY REWRITE AS ';
IF ENV = 'CSTMP' THEN
execute immediate MV || 'SELECT count(m.work_ownerid)
FROM MV_WWORK_SHRUNK m
WHERE WORK_STATUS = 2';
ELSIF ENV = 'PROD' THEN
execute immediate MV || 'SELECT count(m.work_ownerid)
FROM MV_WWORK_SHRUNK m
WHERE WORK_STATUS = 2';
ELSE
execute immediate MV || 'SELECT count(m.work_ownerid)
FROM MV_WWORK_SHRUNK m
WHERE WORK_STATUS = 2';
END IF;
END;
答案 0 :(得分:1)
如果显示连接结果而不是执行连接,则可以得到如下结果:
CREATE MATERIALIZED VIEWTEST2" COMPRESS
NOLOGGING
PARTITION BY HASH (DATAID)
PARTITIONS 16
PARALLEL
BUILD IMMEDIATE
USING INDEX
REFRESH
NEXT trunc(SYSDATE, 'hh') + 1/24
FAST
WITH ROWID
USING DEFAULT LOCAL ROLLBACK SEGMENT
ENABLE QUERY REWRITE AS SELECT count(m.work_ownerid)
FROM MV_WWORK_SHRUNK m
WHERE WORK_STATUS = 2
更正错误并重试。