Four types of dynamic SQL statements

Source: Internet
Author: User
Tags prepare
1. Dynamic SQL Format 1
Execute immediate SQLStatement {USING TransactionObject };
Eg:
String Mysql
Mysql = "create table Employee "&
"(Emp_id integer not null ,"&
"Dept_id integer not null ,"&
"Emp_fname char (10) not null ,"&
"Emp_lname char (20) not null )"
Execute immediate: Mysql;
2. Dynamic SQL Format 2
PREPARE DynamicStagingArea FROM SQLStatement {USING TransactionObject };
EXECUTE DynamicStagingArea USING {ParameterList };
Eg:
INT Emp_id_var = 56
PREPARE SQLSA
FROM "delete from employee WHERE emp_id =? ";
Execute sqlsa using: Emp_id_var;
3. Dynamic SQL Format 3
DECLARE Cursor | Procedure dynamic cursor | procedure for DynamicStagingArea;
PREPARE DynamicStagingArea FROM SQLStatement {USING TransactionObject };
Open dynamic Cursor {USING ParameterList };
Execute dynamic Procedure {USING ParameterList };
FETCH Cursor | Procedure INTO HostVariableList;
CLOSE Cursor | Procedure;
Eg:
Integer Emp_id_var
DECLARE my_cursor dynamic cursor for sqlsa;
Prepare sqlsa from "SELECT emp_id FROM employee ";
Open dynamic my_cursor;
FETCH my_cursor INTO: Emp_id_var;
CLOSE my_cursor;
4. Dynamic SQL Format 4
DECLARE Cursor | Procedure dynamic cursor | procedure for DynamicStagingArea;
PREPARE DynamicStagingArea FROM SQLStatement {USING TransactionObject };
DESCRIBE DynamicStagingArea INTO DynamicDescriptionArea;
Open dynamic Cursor | Procedure using descriptor DynamicDescriptionArea;
Execute dynamic Cursor | Procedure using descriptor DynamicDescriptionArea;
FETCH Cursor | Procedure using descriptor DynamicDescriptionArea;
CLOSE Cursor | Procedure;
Eg:
String Stringvar, Sqlstatement
Integer Intvar
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.