【问题标题】:PLS-00201 identifier 'PACKAGENAME.PROCEDURENAME' must be declaredPLS-00201 必须声明标识符“PACKAGENAME.PROCEDURENAME”
【发布时间】:2017-05-31 09:30:33
【问题描述】:

我正在开发聊天系统的后端,使用了 Django 服务器。 我在 SQL-Developer 中为 Oracle 数据库编写了一个过程,它应该向端点提供最近的消息。当我在 SQL-Developer 中运行过程时,它运行顺利。但是,如果我在端点中运行程序,则会出现以下错误消息:

b'{"ERROR_NO": 6550, "ERROR_MSG": "ORA-06550: line 1, column 7:\\nPLS-00201: identifier \'P_CHAT.GET_MESSAGES\' must be declared\\nORA-06550: line 1, column 7:\\nPL/SQL: Statement ignored\\n"}'

Views.py

    #getmessage
@need_get_parameters([PARAM_SENDING_USER_ID, PARAM_LAST_ID])
def get(self, request, *args, **kwargs):
    uid = request.GET.get(PARAM_SENDING_USER_ID)
    last_id = request.GET.get(PARAM_LAST_ID)

    #ToDo validate Data
    try:
        params = {"i_lastId": last_id}
        results = db_execute_procedure_ajax_response("p_chat.get_messages", params, uid)
        return HttpResponse(json.dumps(results))

    except Exception as a:
        return HttpResponse(error_json(ERR_MSG_NO_RECENT_MESSAGE))

自制 db.py 方法(适用于所有其他端点)

@trace_db_ajax def db_execute_procedure_ajax_response(procedure_name, params, uid): params["o_data"] = {"type": cx_Oracle.CLOB} try: rparams = db_execute_procedure_lro(procedure_name, params, uid) except DBExecuteLogicalException as e: return ajax_response_bad_request(error_response(e.error_code, e.error_msg, e.error_info)) except DBExecutePhysicalException as e: return ajax_response_server_error(error_response(e.error_code, e.error_msg)) return ajax_response(rparams["o_data"])

程序

create or replace PACKAGE BODY P_CHAT AS
PROCEDURE get_messages
(
    i_userId    in   number,
    i_lastId    in   number,
    o_retCode   out  number,
    o_json      out  clob
)IS
    m_retCode   number := STD_C.retCode_ok;
BEGIN
    apex_json.initialize_clob_output;
    apex_json.open_array();
    if i_userId IS NULL then
        m_retCode := STD.error(P_C.ERR_USER_ID_MISSING);
    else
        for cs in(
            SELECT id, message, sender_id, gendate
            FROM Message
            WHERE (id>i_lastId OR i_lastId IS NULL)
            AND RECEIVER_ID=i_userId) loop
                apex_json.open_object();
                apex_json.write(P_C.JSON_MSG_ID, cs.id);
                apex_json.write(P_C.JSON_MSG_MESSAGE, cs.message);
                apex_json.write(P_C.JSON_MSG_SENDER_ID, cs.sender_id);
                apex_json.write(P_C.JSON_MSG_GENDATE, cs.gendate, std_c.iso_date_format);
                apex_json.close_object;
            end loop;
        apex_json.close_array();
        o_json := apex_json.get_clob_output;
    end if;

    o_retCode := m_retCode;

END get_messages;

结束 P_CHAT;

我不必在Procedure中声明Procedure名称还是?

感谢您的回答!

【问题讨论】:

  • 可能是架构问题?您在哪个架构中创建了包,您可以尝试在从 python 访问它时给出架构名称吗
  • 没有工作......我也没有在其他端点中使用它,所以我认为它不需要。不过还是谢谢^^

标签: django database oracle stored-procedures plsql


【解决方案1】:

PLS-00201: identifier must be declared 表示任一

  1. 真的不存在,或者
  2. 存在但调用者无权执行,或
  3. 它存在于调用方默认以外的某些模式中,调用方需要指定哪一种。

在 #2 的情况下,您需要将包的执行权限授予调用者(或调用者拥有的角色)。

在 #3 的情况下,您需要指定架构,或者将其设置为会话的默认架构,或者创建同义词。

【讨论】:

  • 我发现了错误。它不是代码或架构。我正在为端点运行 Django 测试,而 Django 在 TEST-Database 中运行测试,但程序在 DEV-Database 上,所以 django 找不到它。逻辑,但我已经监督了这一点。还是谢谢^^。
猜你喜欢
  • 2014-06-24
  • 1970-01-01
  • 1970-01-01
  • 2019-12-17
  • 2021-12-22
  • 2016-07-25
  • 2018-08-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多