How to check for valid oracle table name using sql/plsql
oracle
Solution
Oracle has a built-in that's useful for checking whether a SQL Name is valid. That's especially useful when building dynamic queries where you need to prevent SQL Injection.
Check out the dbms_assert.simple_sql_name built-in, and see the Oracle white paper at How to Write Injection Proof PL/SQL for more details.
v$reserved_words is also useful, as others have noted.
Problem
I need to check if a string contains a valid Oracle table name using sql/plsql. The criteria I found for a Oracle table name are these: - The table name must begin with a letter. - The table name can not be longer than 30 characters. - The table name must be made up of alphanumeric characters or the following special characters: $, _, and #. - The table name can not be a reserved word. Criteria 1,2,3 don't seem so hard to tackle. But what about point 4? What are my options without trying to actually create a table with the given name and then see if it succeeds or fails.