Oracle - Function not working

前端 未结 1 332
轻奢々
轻奢々 2021-01-27 00:17

Oracle - Function not working

So I got no idea what i\'m doing wrong. I\'ve been at it for hours and i\'d really appreciate some help.

So basically I have 2 tabl

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-27 00:39

    What is the data type of the student_no column? The column name implies that it is a NUMBER. But the fact that you're calling lower on it and comparing it to the session user implies that it is a VARCHAR2.

    Assuming student_no is a VARCHAR2, one problem is that your predicate is missing single quotes around the value. If v_student_no is, for example, "jcave", your out_string would be

    1=2 or student_no = jcave
    

    Since "jcave" isn't quoted, Oracle assumes that it must be an identifier so it looks for a column in the table named jcave. Finding no such column, it throws an error. You'd have more luck if you put single quotes around the string

    out_string := out_string||'or student_no = '''||v_student_no||''' ';
    

    There may be additional errors as well. Have you tried calling the function manually to see exactly what it returns? If you had called the function manually when session_user was set to "jcave", you should have seen the result that is lacking the single quotes. If you copy and paste the return value and add that to the end of your SELECT statement, you'd see the error straight away. You can also query v$vpd_policy to see the particular policy predicate(s) that have been added to a particular SQL statement if you want to avoid calling the function manually-- this is very useful when you're trying to debug VPD problems with session state that you can't easily reproduce.

    0 讨论(0)
提交回复
热议问题