Oracle inside (7)

Source: Internet
Author: User
Tags sql using
There are two ways to execute dynamic SQL: dbms_ SQL package and local dynamic SQL.
7.1 dbms_ SQL package
Powerful functions and a large number of functions are rarely used.
7.2 local dynamic SQL
7.2.1 execute DDL statements
Begin
Advanced PL/SQL programming
29th pages 29 pages
Execute immediate 'create table yang_test (Eid varchar2 (30) primary key )';
Execute immediate 'alter table yang_test add (ephoto clob )';
Execute immediate 'alter table yang_test modify (Eid number )';
Execute immediate 'drop table yang_test ';
End;
/
7.2.2 bind a variable
Declare
L_ SQL varchar2 (200 );
Rochelle photo yang_test.ephoto % type;
Rochelle ID yang_test.eid % type;
Begin
Rochelle SQL: = 'insert into yang_test values (: 1,: 2 )';
Execute immediate l_ SQL using 10, 'Welcome to our couty ';
Commit;
Rochelle SQL: = 'select ephoto, Eid from yang_test where eid =: 1 ';
Execute immediate l_ SQL into l_photo, l_id using 10;
Dbms_output.put_line (l_id );
Dbms_output.put_line (l_photo );
End;
/
Note: run the above Code to view the result !!!
7.2.3 execute PL/SQL Blocks
Declare
Rochelle ID number;
L_ SQL varchar2 (200): = 'in in select Eid into: 1 from yang_test; end ;';
Begin
Execute immediate l_ SQL into l_id;
Dbms_output.put_line (to_char (l_id ));
End;
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.