Variable binding in Oracle PL/SQL

Source: Internet
Author: User

From the design of the Oracle shared pool and the PL/SQL writing method recommended by Oracle, we can see that variable binding has a great impact on performance, how to bind variables in PL/SQL?

First, let's take a look at the usage of not using variable binding:

Declare

Cursor cur_temp (ID number) is
Select * From table_a where a = ID;

C_temp cur_temp % rowtype;

Beign

Open cur_temp (1 );

Loop

Fetch cur_temp into c_temp;

Exit when cur_temp % notfound;

Insert into B values (c_temp.a );

End loop;

Close cur_temp;

Commit;

End;

No variable binding is used above, including the cursor and operation statement.

Let's look at the usage of variable binding below:

First

Type cursortype is ref cursor;

Then:

Declare

Cur_temp cursortype;

C_temp table_a % rowtype;

Begin

Open cur_temp for 'select * From table_a where a =: 1 'using 91;

Loop

Fetch cur_temp into c_temp;

Exit when cur_temp % notfound;

Execute immediate 'insert into B values (: 1) 'using c_temp.a;

End loop;

Close cur_temp;

Commit;

End;

The above is written in PL/SQL blocks. This method is also applicable to stored procedures, triggers, functions, packages, and other places where PL/SQL can be used.

To use into, you can use the following:

I number (6 );

Execute immediate 'select count (*) from table_a where a =: 1 'into I using 89;

After execution, the retrieved values are stored in variable I.

In PL/SQL, the common usage of variable binding is basically as shown above. We recommend that you bind all variables.

Related Article

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.