1

我是 oracle 的新手,我正在做一个项目

错误的绑定变量。

我该怎么办?任何帮助将不胜感激

代码:

DECLARE
  U_ID VOTERS.V_ID%TYPE;
  PASS VOTERS.PASSWORD%TYPE;
  CURSOR LOGIN_CUR IS
  SELECT V_ID,PASSWORD FROM VOTERS;

BEGIN
  SELECT W_ID INTO :WID FROM VOTERS WHERE V_ID=:V_ID;
  BEGIN
    OPEN LOGIN_CUR;
    LOOP
      FETCH LOGIN_CUR INTO U_ID,PASS;
      IF :V_ID=U_ID AND :PASSWORD=PASS THEN
        OPEN_FORM ('........');
        EXIT WHEN LOGIN_CUR%FOUND;

      END IF;
    END LOOP;
    CLOSE LOGIN_CUR;
  END;
END;
4

1 回答 1

0

“错误绑定变量”的原因在这里:

IF :V_ID=U_ID AND :PASSWORD=PASS

所以要解决你的问题,你应该删除':'所以你的查询应该是这样的

IF V_ID=U_ID AND PASSWORD=PASS

您已经将数据插入到变量中,因此无需再次使用“:”。

DECLARE
U_ID VOTERS.V_ID%TYPE;
PASS VOTERS.PASSWORD%TYPE;
CURSOR LOGIN_CUR IS
SELECT V_ID,PASSWORD FROM VOTERS;

  BEGIN
  SELECT W_ID INTO WID FROM VOTERS WHERE V_ID=V_ID;
  BEGIN
 OPEN LOGIN_CUR;
 LOOP
 FETCH LOGIN_CUR INTO U_ID,PASS;
IF V_ID=U_ID AND PASSWORD=PASS THEN
OPEN_FORM ('........');
EXIT WHEN LOGIN_CUR%FOUND;

END IF;
 END LOOP;
CLOSE LOGIN_CUR;
END;
END;

编辑 - -

你的光标应该和这个类似,这个没有错误,如果你有任何问题,请问:


  DECLARE
   U_ID NUMBER(20);
  PASS VARCHAR2(30);
  WID NUMBER(20);
  A NUMBER(20);
  CURSOR LOGIN_CUR IS
    SELECT id INTO A FROM voters;


 BEGIN
 SELECT T_ID INTO WID FROM voters WHERE T_ID = A;
   BEGIN
   OPEN LOGIN_CUR;
  LOOP
  FETCH LOGIN_CUR INTO U_ID;
 IF WID=U_ID THEN
  OPEN_FORM ('........');
   EXIT WHEN LOGIN_CUR%FOUND;

 END IF;
END LOOP;
CLOSE LOGIN_CUR;
END;
 END;
于 2013-09-17T11:48:10.243 回答