PL SQL,错误(32,43):PLS-00201:标识符';人力资源';必须申报

PL SQL,错误(32,43):PLS-00201:标识符';人力资源';必须申报,sql,oracle,stored-procedures,plsql,execute-immediate,Sql,Oracle,Stored Procedures,Plsql,Execute Immediate,我正在尝试执行以下过程 EXECUTE StudentNames(12345, true) 我得到下面的错误 错误(32,43):PLS-00201:必须声明标识符“HR” 它链接到代码的这一部分: IF p_bool AND v_studid = 12345 THEN EXECUTE IMMEDIATE 'grant select on '||HR||'.'||STUDNAME_12345||' to student_12345'; END IF; 我希望将学生编号和

我正在尝试执行以下过程

EXECUTE StudentNames(12345, true)    
我得到下面的错误

错误(32,43):PLS-00201:必须声明标识符“HR”

它链接到代码的这一部分:

 IF p_bool AND v_studid = 12345 THEN
    EXECUTE IMMEDIATE 'grant select on '||HR||'.'||STUDNAME_12345||' to student_12345';
  END IF;
我希望将学生编号和布尔值传递给过程。 如果通过->代码将授予表hr.studname\u 12345上的学生选择权限

我可以看出这个问题与人力资源有关,只是想知道如何解决它

提前谢谢

CREATE OR REPLACE PROCEDURE StudentNames
  (p_studnumber IN students.student_id%TYPE,
   p_bool IN BOOLEAN)
IS
  v_stud          students.student_id%TYPE := p_studnumber;
  v_studid        students.student_id%TYPE;
  v_firstname     students.firstname%TYPE;
  v_lastname      students.lastname%TYPE;

  e_no_test_returned    EXCEPTION;
  e_no_table            EXCEPTION;
  PRAGMA EXCEPTION_INIT (e_no_table, -942);


  CURSOR  c_stud_cursor (p_studno NUMBER)IS
  SELECT  firstname, lastname 
  FROM    students  
  WHERE   student_id = p_studno;

BEGIN

  EXECUTE IMMEDIATE
  'SELECT student_id 
  FROM students
  WHERE student_id = :v_stud'
  INTO v_studid
  USING v_stud;
  DBMS_OUTPUT.PUT_LINE(v_studid);
  DBMS_OUTPUT.PUT_LINE('  ');

  IF p_bool AND v_studid = 12345 THEN
    EXECUTE IMMEDIATE 'grant select on '||HR||'.'||STUDNAME_12345||' to student_12345';
  END IF;

  OPEN c_stud_cursor(v_studid);
  LOOP
    FETCH c_stud_cursor INTO v_firstname, v_lastname;
    EXIT WHEN c_stud_cursor%NOTFOUND;

------NAMES--------------------
      IF    v_studid = 12345 THEN        
            INSERT INTO studname_12345(first_name, last_name)
            VALUES ( v_firstname, v_lastname);
            COMMIT;


      ELSIF v_studid = 12346 THEN        
            INSERT INTO studname_12346(first_name, last_name)
            VALUES ( v_firstname, v_lastname);
            COMMIT;

      ELSIF v_studid IS NULL THEN
        RAISE e_no_test_returned;

    END IF;

  END LOOP;


  CLOSE c_stud_cursor;



EXCEPTION
--The value passed to the student_id parameter is not an integer. 
  WHEN INVALID_NUMBER THEN 
    DBMS_OUTPUT.PUT_LINE('The value passed to the student_id parameter is not an integer');

  WHEN TOO_MANY_ROWS THEN 
    DBMS_OUTPUT.PUT_LINE('More than one student with same id');

--The value passed to the student_id parameter does not exist in the student tables. 
--The value passed to the student_id parameter is null.
  WHEN NO_DATA_FOUND THEN 
    DBMS_OUTPUT.PUT_LINE('Student ID does not exist in the student table');  

--There are no test results for the Student.  
  WHEN e_no_test_returned THEN
    DBMS_OUTPUT.PUT_LINE('There are no results for Student - '||v_stud);

  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Some other error occurred.');


END StudentNames;
/
创建学生/角色/将帐户添加到角色

CREATE USER student_12345
IDENTIFIED BY pw1234;

--Create a Student Role 12345
CREATE ROLE student1;

--Adding the account to the student role
GRANT student1
TO student_12345;


--Allow accounts access the database
GRANT create session 
TO student_12345;
创建表

CREATE TABLE studname_12345
  (first_name   VARCHAR2(30),
   last_name    VARCHAR2(30)
   );

您的代码中没有名为
HR
的变量,这正是Oracle所抱怨的

您可能想要什么而不是这个:

EXECUTE IMMEDIATE 'grant select on '||HR||'.'||STUDNAME_12345||' to student_12345';
这是:

EXECUTE IMMEDIATE 'grant select on HR.STUDNAME_12345 to student_12345';

您的代码中没有名为
HR
的变量,这正是Oracle所抱怨的

您可能想要什么而不是这个:

EXECUTE IMMEDIATE 'grant select on '||HR||'.'||STUDNAME_12345||' to student_12345';
这是:

EXECUTE IMMEDIATE 'grant select on HR.STUDNAME_12345 to student_12345';

谢谢你,弗兰克,现在开始跑步。@saggart,不客气。如果这修正了你的问题,请考虑将我的答案标记为“接受”(点击旁边的复选标记)。谢谢弗兰克-现在运行。@ SGARTARE不客气。如果这修正了你的问题,请考虑把我的答案标记为接受(点击旁边的复选标记)。