Oracle variable binding ORA-00903 error: Invalid table name

Source: Internet
Author: User

During Development today, my following requirements: I need to find data from different tables, but the SQL statements are relatively fixed:

Select count (*) CNT from table_a where code = codevalue;

In the preceding SQL statement, only table_a and codevalue change. Therefore, we use the variable binding method:

As follows:

Select count (*) CNT from: 1 where code =: 2

The entire call is as follows:

Create or replace procedure Test (scode in varchar2, icount out number) is
Begin
Execute immediate 'select count (*) CNT from: 1 where code =: 2'
Into icount
Using 'gd _ side', scode;
End test;

But an ORA-00903 error was reported during execution: Invalid table name.

After the method is changed to the following, everything is normal:

Create or replace procedure Test (scode in varchar2, icount out number) is
Begin
Execute immediate 'select count (*) CNT from' | table_name | 'where code =: 1'
Into icount
Using scode;
End test;

The difference is that the table name does not use the binding method, but the | method.

Finally, find the resource and find that the table name cannot be bound, because during SQL parsing, you must first know which table to operate and check whether the user has the permission for this table, there may be other reasons, so the table name cannot be bound.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.