Go Oracle Execution string

Source: Internet
Author: User

Declare v_out    varchar2 (a); begin     Execute ' Select P_guid from C_itcomp   '    into    v_out;     Dbms_output.put_line (v_out); End;

Database version must be > =oracle 8i

The direct SELECT statement is useless, guess because select returns multiple rows and columns
can perform DML,DDL, etc.
such as INSERT, UPDATE, CREATE, etc.
You can also bind variables
such as strsql:= ' UPDATE tname SET col1=:variable1 WHERE colx=:variable2 ';
Excute IMMEDIATE strSQL USING value1,value2;

This article was reproduced from: http://blog.sina.com.cn/s/blog_5421dfd20100r29j.html

Executes a dynamic SQL statement or a PL/SQL block that is not created at runtime. Dynamically create and Execute SQL statements

EXECUTE IMMEDIATE--usage examples

1. Running DDL statements in PL/SQL

Begin
Execute immediate ' set role all ';
End

2. Passing a value to a dynamic statement (USING clause)

Declare
L_depnam varchar2 (): = ' testing ';
L_loc Varchar2 (Ten): = ' Dubai ';
Begin
Execute immediate ' INSERT INTO Dept values (: 1,: 2,: 3) '
Using, L_depnam, L_loc;
Commit
End

3. Retrieving values from dynamic statements (INTO clause)

Declare
l_cnt varchar2 (20);
Begin
Execute immediate ' SELECT COUNT (1) from EMP '
into l_cnt;
Dbms_output.put_line (L_CNT);
End

Go Oracle Execution string

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.