存储过程未返回预期值

时间:2016-04-08 05:37:14

标签: oracle stored-procedures plsql

存储过程不会返回我期望的值。我不知道程序有什么问题。

以下是程序:

CREATE OR REPLACE procedure PRC_CUSTOMER_WITH_LOGIN
    (p_name_out out varchar2,
     p_count out int,
     p_all_records out SYS_REFCURSOR,
     p_mode in varchar2,
     p_id in varchar2,
     p_name_in in varchar2,
     p_contact_no in varchar2,
     p_email in varchar2,
     p_address in varchar2)
IS
BEGIN
IF p_mode='q' 
THEN
    select NAME into p_name_out from customer where id='1';
ELSIF p_mode='i' 
THEN
    INSERT into customer(id,name,contactNo,email,address)
    Values(p_id, p_name_in, p_contact_no , p_email , p_address);
ELSIF p_mode='u' 
THEN
    UPDATE customer set name=p_name_in, contactNo=p_contact_no, email=p_email, address=p_address
     where id=p_id;
ELSIF p_mode='d' 
THEN
    DELETE from customer where id=p_id;
ELSIF p_mode='a'
THEN
    OPEN p_all_records FOR
        select * from customer;
ELSIF p_mode='l'
THEN
    SELECT COUNT(*) into p_count from customer WHERE name=p_name_in AND id=p_id;
END IF;
END;
/

这是所有其他条件正常工作但最后一个条件无法正常工作的程序此条件一直返回0是否输入正确的ID和名称或错误。

我在这里调用此程序

cs = (OracleCallableStatement) con.prepareCall("{call TESTDB.PRC_CUSTOMER_WITH_LOGIN(?,?,?,?,?,?,null,null,null)}");
            cs.registerOutParameter(1, OracleTypes.VARCHAR);
            cs.registerOutParameter(2, OracleTypes.INTEGER);
            cs.registerOutParameter(3, OracleTypes.CURSOR);
            cs.setString(4, "l");
            cs.setString(5, password);
            cs.setString(6, name);

            cs.executeQuery();
            chk=cs.getInt(2);
            System.out.println(chk);

有人能告诉我,我在这里犯的错误是什么吗?我将感恩....:)

2 个答案:

答案 0 :(得分:1)

尝试使用UPPER,如果有任何区分大小写的名称,那么它将使它无效。

从客户WHERE upper(name)= upper(p_name_in)AND id = p_id;

将SELECT COUNT(*)转换为p_count

答案 1 :(得分:1)

使用id值设置password时,可能是您错了吗?

1-> p_name_out out varchar2,
2-> p_count out int,
3-> p_all_records out SYS_REFCURSOR,
4-> p_mode in varchar2,
5-> p_id in varchar2,      --- 5 is id, not password ??!?
6-> p_name_in in varchar2,
p_contact_no in varchar2,
p_email in varchar2,
p_address in varchar2

cs = (OracleCallableStatement) con.prepareCall(
"{call TESTDB.PRC_CUSTOMER_WITH_LOGIN(?,?,?,?,?,?,null,null,null)}");
        cs.registerOutParameter(1, OracleTypes.VARCHAR);
        cs.registerOutParameter(2, OracleTypes.INTEGER);
        cs.registerOutParameter(3, OracleTypes.CURSOR);
        cs.setString(4, "l");
        cs.setString(5, password);
        cs.setString(6, name);

另一种可能性是你的 id /密码是否存储为加密的东西?