无法运行oracle存储过程

时间:2013-03-22 10:16:58

标签: sql oracle plsql oracle11g

我是oracle的新手,并编写了一个复杂的存储过程,以根据不同的条件选择不同的数据。我无法运行我的存储过程,它会出现以下错误:

ORA-06550: line2, column 3:
PLS-00905: object SAURAV.LOG_DETAIL is invalid
ORA-06550: line 2, column 3:
PL/SQL: Statement Ignored
ORA-06512: at line 58

我的代码如下:

CREATE OR REPLACE
PROCEDURE LOG_DETAIL(
    startIndex IN INT
    ,pageSize IN INT
    ,branchId IN varchar2
    ,customerId IN varchar2
    ,fromDate IN DATE
    ,toDate IN DATE
    ,withDate IN INT
    ,p_cursor OUT sys_refcursor
    ) AS
BEGIN
IF withDate = 1 then
        IF branchId = NULL then
            IF customerId = 'All' then
                OPEN p_cursor
                FOR SELECT * FROM (
        SELECT ROW_NUMBER() OVER (
                ORDER BY id
                ) AS MyRows
            ,log_info.branch_id
            ,branch_name
            ,customer_id
            ,in_time
            ,out_time
            ,date_time
            ,ip
            ,(
                SELECT COUNT(id)
                FROM log_info
                WHERE date_time BETWEEN fromDate || '%' AND toDate || '%'
                ) AS RowNumber  FROM log_info,branch_info
        WHERE date_time BETWEEN fromDate || '%' AND toDate || '%'
            AND branch_info.branch_id = log_info.branch_id
        )
    WHERE MyRows BETWEEN startIndex AND startIndex + pageSize - 1;
            ELSE
            OPEN p_cursor 
            FOR SELECT * FROM (
        SELECT ROW_NUMBER() OVER (
                ORDER BY id
                ) AS MyRows
            ,log_info.branch_id
            ,branch_name
            ,customer_id
            ,in_time
            ,out_time
            ,date_time
            ,ip
            ,(
                SELECT COUNT(id)
                FROM log_info
                WHERE customer_id = customerId
                    AND date_time BETWEEN fromDate || '%'
                        AND toDate || '%'
                ) AS RowNumber
        FROM log_info,branch_info
        WHERE customer_id = customerId
            AND date_time BETWEEN fromDate || '%'
                AND toDate || '%'
            AND log_info.branch_id = branch_info.branch_id
        )
    WHERE MyRows BETWEEN startIndex
            AND startIndex + pageSize - 1;
END IF;
ELSE
    IF customerId = 'All' then
        OPEN p_cursor
        FOR SELECT * FROM (
    SELECT ROW_NUMBER() OVER (
            ORDER BY id
            ) AS MyRows
        ,log_info.branch_id
        ,branch_name
        ,customer_id
        ,in_time
        ,out_time
        ,date_time
        ,ip
        ,(
            SELECT COUNT(id)
            FROM log_info
            WHERE branch_id = branchId
                AND date_time BETWEEN fromDate || '%'
                    AND toDate || '%'
            ) AS RowNumber
    FROM log_info
        ,branch_info
    WHERE log_info.branch_id = branchId
        AND date_time BETWEEN fromDate || '%'
            AND toDate || '%'
        AND branch_info.branch_id = log_info.branch_id
    )
WHERE MyRows BETWEEN startIndex
        AND startIndex + pageSize - 1;
        ELSE
        OPEN p_cursor
        FOR SELECT * FROM (
    SELECT ROW_NUMBER() OVER (
            ORDER BY id
            ) AS MyRows
        ,log_info.branch_id
        ,branch_name
        ,customer_id
        ,in_time
        ,out_time
        ,date_time
        ,ip
        ,(
            SELECT COUNT(id)
            FROM log_info
            WHERE branch_id = branchId
                AND customer_id = customerId
                AND date_time BETWEEN fromDate || '%'
                    AND toDate || '%'
            ) AS RowNumber
    FROM log_info
        ,branch_info
    WHERE log_info.branch_id = branchId
        AND customer_id = customerId
        AND date_time BETWEEN fromDate || '%'
            AND toDate || '%'
        AND log_info.branch_id = branch_info.branch_id
    )
WHERE MyRows BETWEEN startIndex
        AND startIndex + pageSize - 1;
        END IF ;
        END IF ;
        ELSE
        IF customerId = 'All' then
            IF branchId = NULL then
                OPEN p_cursor
                FOR SELECT * FROM (
    SELECT ROW_NUMBER() OVER (
            ORDER BY id
            ) AS MyRows
        ,log_info.branch_id
        ,branch_name
        ,customer_id
        ,in_time
        ,out_time
        ,date_time
        ,ip
        ,(
            SELECT COUNT(id)
            FROM log_info
            ) AS RowNumber
    FROM log_info
        ,branch_info
    WHERE branch_ingo.branch_id = log_info.branch_id
    )
WHERE MyRows BETWEEN startIndex
        AND startIndex + pageSize - 1;
        ELSE
        OPEN p_cursor
        FOR SELECT * FROM (
    SELECT ROW_NUMBER() OVER (
            ORDER BY id
            ) AS MyRows
        ,log_info.branch_id
        ,branch_name
        ,customer_id
        ,in_time
        ,out_time
        ,date_time
        ,ip
        ,(
            SELECT COUNT(id)
            FROM log_info
            WHERE branch_id = branchId
            ) AS RowNumber
    FROM log_info
        ,branch_info
    WHERE log_info.branch_id = branchId
        AND log_info.branch_id = branch_info.branch_id
    )
WHERE MyRows BETWEEN startIndex
        AND startIndex + pageSize - 1;
        END IF ;
        ELSE
        IF branchId = NULL then
        OPEN p_cursor
        FOR SELECT * FROM (
    SELECT ROW_NUMBER() OVER (
            ORDER BY id
            ) AS MyRows
        ,log_info.branch_id
        ,branch_name
        ,customer_id
        ,in_time
        ,out_time
        ,date_time
        ,ip
        ,(
            SELECT COUNT(id)
            FROM log_info
            WHERE customer_id = customerId
            ) AS RowNumber
    FROM log_info
        ,branch_info
    WHERE customer_id = customerId
        AND branch_info.branch_id = log_info.branch_id
    )
WHERE MyRows BETWEEN startIndex
        AND startIndex + pageSize - 1;
        ELSE
        OPEN p_cursor
        FOR SELECT * FROM (
    SELECT ROW_NUMBER() OVER (
            ORDER BY id
            ) AS MyRows
        ,log_info.branch_id
        ,branch_name
        ,customer_id
        ,in_time
        ,out_time
        ,date_time
        ,ip
        ,(
            SELECT COUNT(id)
            FROM log_info
            WHERE customer_id = customerId
                AND branch_id = branchId
            ) AS RowNumber
    FROM log_info
        ,branch_info
    WHERE customer_id = customerId
        AND log_info.branch_id = branchId
        AND log_info.branch_id = branch_info.branch_id
    )
WHERE MyRows BETWEEN startIndex
        AND startIndex || pageSize - 1;
        END IF ;
    END IF ;
END IF ;
END LOG_DETAIL;

我正在使用以下命令执行程序:

 variable z refcursor;
 LOG_DETAIL(1,20,null,'All',null,null,0,z);

执行以下查询后:

select * from all_errors where name='LOG_DETAIL' order by sequence

我得到了以下结果:

OWNER   NAME            TYPE         SEQUENCE  LINE    POSITION       TEXT                                       ATTRIBUTE  MESSAGE_NUMBER
SAURAV  LOG_DETAIL  PROCEDURE   1   30  49  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   2   30  57  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   3   30  29  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   4   30  39  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   5   32  47  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   6   32  55  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   7   32  27  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   8   32  37  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   9   54  11  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   10  54  19  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   11  53  28  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   12  53  38  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   13  59  9   PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   14  59  17  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   15  58  26  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   16  58  36  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   17  84  10  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   18  84  18  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   19  83  27  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204
SAURAV  LOG_DETAIL  PROCEDURE   20  83  37  PLW-07204: conversion away from column type may result in sub-optimal query plan    WARNING  7204

请帮我解决这个问题。

编辑:添加了堆栈跟踪。

2 个答案:

答案 0 :(得分:1)

警告消息是由包含此类表达式的字符串引起的:

date_time BETWEEN fromDate || '%' AND toDate || '%'

为什么要附加百分号?尝试删除它们并重新创建程序以使其有效。

答案 1 :(得分:1)

至少有一个问题是读取的行

ELSE
  IF customerId = 'All' then

这应该是

ELSIF customerId = 'All' then

我没有查看此代码中是否再出现ELSE IF。如果有,请更正并重新编译。

分享并享受。