不完整/格式错误的光标

Posted

技术标签:

【中文标题】不完整/格式错误的光标【英文标题】:Incomplete/Malformed cursor 【发布时间】:2015-08-19 14:52:29 【问题描述】:

我有一个 PL/SQL 脚本来执行一些聚合任务。我遇到了编译错误,此时逻辑不是首要任务,因为一旦解决了错误,就可以更改它。脚本如下:

SET SERVEROUTPUT ON;
ALTER SESSION SET NLS_DATE_FORMAT = 'dd-MON-yy';
CREATE OR REPLACE PROCEDURE updateFeaturePerformanceTable
    (noOfDays IN NUMBER, runDate IN DATE, timeSpan IN VARCHAR2)
AS
    CURSOR c_feature_performance IS 
        SELECT distinct mkt_id,dow,device_type,feature_name 
        FROM gfmdev.feature_performance 
        WHERE timespan = 'ONE_DAY' 
        AND feature_performance_day >= TO_DATE('17-AUG-15','dd-MON-yy');
    rowsExtracted c_feature_performance%ROWTYPE;
    extractDate DATE;
    timespan_test varchar2(20);
BEGIN
    OPEN c_feature_performance;
    extractDate := runDate - noOfDays;
    timespan_test := timeSpan;
    LOOP
        FETCH c_feature_performance INTO rowsExtracted;
        EXIT WHEN c_feature_performance%NOTFOUND;

        dbms_output.put_line(extractDate || ' ' || timespan_test);

        INSERT INTO gfmdev.feature_performance
        SELECT  
            rowsExtracted.mkt_id,
            rowsExtracted.dow,
            rowsExtracted.device_type,
            rowsExtracted.feature_name,
            SUM(OPS),
            SUM(GV_COUNT),
            runDate,
            timespan_test
    FROM    gfmdev.feature_performance   
    WHERE   feature_performance_day BETWEEN extractDate AND runDate 
    AND timespan = 'ONE_DAY'
    AND mkt_id = rowsExtracted.mkt_id
    AND dow = rowsExtracted.dow
    AND device_type = rowsExtracted.device_type
    AND feature_name = rowsExtracted.feature_name
    group by mkt_id, dow, device_type, feature_name, timespan;      

END LOOP;
CLOSE c_feature_performance;
EXCEPTION
    WHEN TOO_MANY_ROWS THEN
        dbms_output.put_line('Trying to insert too many rows in SELECT...INTO');
        ROLLBACK;
    WHEN NO_DATA_FOUND THEN
        dbms_output.put_line('No rows returned in SELECT...INTO');
        ROLLBACK;
    WHEN STORAGE_ERROR THEN
        dbms_output.put_line('Too much data to handle! Storage error');
        ROLLBACK;
    WHEN OTHERS THEN
        dbms_output.put_line('Oops! Something went wrong');
        ROLLBACK;
        RAISE;      

END updateFeaturePerformanceTable;

显示编译错误:

SHOW ERRORS PROCEDURE updateFeaturePerformanceTable;

运行程序:

DECLARE
    runDate DATE;
BEGIN
FOR j IN 0 .. 5 LOOP
    SELECT (TO_DATE('17-AUG-15','dd-MON-yy') + j) INTO runDate FROM dual;
    updateFeaturePerformanceTable(6,runDate, 'ONE_WEEK');
END LOOP;
DBMS_OUTPUT.PUT_LINE(' WEEKLY RECORDS UPDATED ');
FOR j IN 0 .. 28 LOOP
    SELECT (TO_DATE('17-AUG-15','dd-MON-yy') + j) INTO runDate FROM dual;
    updateFeaturePerformanceTable(29,runDate, 'ONE_MONTH');
END LOOP;
DBMS_OUTPUT.PUT_LINE(' MONTHLY RECORDS UPDATED ');
COMMIT;
END;
/

当我执行它时,我收到以下错误消息:

Errors for PROCEDURE UPDATEFEATUREPERFORMANCETABLE:

LINE/COL ERROR
-------- -----------------------------------------------------------------
4/9      PLS-00341: declaration of cursor 'C_FEATURE_PERFORMANCE' is
     incomplete or malformed

5/3      PL/SQL: SQL Statement ignored
6/15     PL/SQL: ORA-00942: table or view does not exist
8/16     PL/SQL: Item ignored
16/3     PL/SQL: SQL Statement ignored
16/36    PLS-00320: the declaration of the type of this expression is
     incomplete or malformed

21/3     PL/SQL: SQL Statement ignored

LINE/COL ERROR
-------- -----------------------------------------------------------------
36/22    PL/SQL: ORA-00904: "ROWSEXTRACTED"."FEATURE_NAME": invalid
     identifier

36/22    PLS-00320: the declaration of the type of this expression is
     incomplete or malformed

            updateFeaturePerformanceTable(6,runDate, 'ONE_WEEK');
            *

非常感谢任何关于我哪里出错的帮助?

【问题讨论】:

使用行号并调试您的代码。谷歌查看具体错误代码。 【参考方案1】:

PL/SQL 是一个以编程方式运行 SQL 语句的框架。所以我们经常发现PL/SQL错误是由我们代码中的SQL错误引起的。

这里就是这样。您有几个 PL/SQL 错误表明游标声明无效。为什么它无效?这条线拥有答案:

6/15     PL/SQL: ORA-00942: table or view does not exist

所以问题是,UPDATEFEATUREPERFORMANCETABLE 过程的所有者(顺便说一下,名字很难看)没有gfmdev.feature_performance 的权限。

为解决此问题,表所有者 GFMDEV 需要将 SELECT 和 INSERT 直接授予拥有此过程的帐户。

SQL>  conn gfmdev/password
SQL>  grant select, insert on feature_performance to whoever;

请注意,通过视图授予权限不会削减它。 Oracle 安全模型只允许我们构建对象 - PL/SQL 程序、视图 - 直接授予我们用户的权限。

【讨论】:

以上是关于不完整/格式错误的光标的主要内容,如果未能解决你的问题,请参考以下文章

如何在python中将光标列表转换为JSON格式?

怎么把图片变成光标的格式

jQuery 可拖动错误(元素不符合光标)

光标转换错误?

android光标未关闭错误

使用jQuery实现图片循环滚动效果,当把光标移动图上,停止滚动;当把光标从图上移出后,图片继续滚动