Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
47
Добавлен:
16.04.2013
Размер:
5 Мб
Скачать
☆

Using Dynamic SQL in Languages Other Than PL/SQL

WHERE deptno = :deptno

RETURNING dname INTO :dname';

Table 6–4 shows sample code that accomplishes this operation using both the DBMS_SQL package and native dynamic SQL.

Table 6–4 DML Returning Operation Using the DBMS_SQL Package and Native Dynamic SQL

DBMS_SQL DML Returning Operation

Native Dynamic SQL DML Returning Operation

 

 

 

DECLARE

DECLARE

 

deptname_array dbms_sql.Varchar2_Table;

deptname_array dbms_sql.Varchar2_Table;

cur_hdl INT;

stmt_str

VARCHAR2(200);

stmt_str VARCHAR2(200);

location

VARCHAR2(20);

location VARCHAR2(20);

deptnumber NUMBER := 10;

deptnumber NUMBER := 10;

deptname

VARCHAR2(20);

rows_processed NUMBER;

BEGIN

 

BEGIN

stmt_str := 'UPDATE dept_new

stmt_str := 'UPDATE dept_new

SET loc = :newloc

SET loc = :newloc

WHERE deptno = :deptno

WHERE deptno = :deptno

RETURNING dname INTO :dname';

RETURNING dname INTO :dname';

EXECUTE IMMEDIATE stmt_str

 

USING location, deptnumber, OUT deptname;

cur_hdl := dbms_sql.open_cursor;

END;

 

dbms_sql.parse

/

 

(cur_hdl, stmt_str, dbms_sql.native);

 

 

-- supply binds

 

 

dbms_sql.bind_variable

 

 

(cur_hdl, ':newloc', location);

 

 

dbms_sql.bind_variable

 

 

(cur_hdl, ':deptno', deptnumber);

 

 

dbms_sql.bind_array

 

 

(cur_hdl, ':dname', deptname_array);

 

 

-- execute cursor

 

 

rows_processed := dbms_sql.execute(cur_hdl);

 

 

-- get RETURNING column into OUT bind array

 

 

dbms_sql.variable_value

 

 

(cur_hdl, ':dname', deptname_array);

 

 

dbms_sql.close_cursor(cur_hdl);

 

 

END;

 

 

/

 

 

 

 

 

Using Dynamic SQL in Languages Other Than PL/SQL

Although this chapter discusses PL/SQL support for dynamic SQL, you can call dynamic SQL from other languages:

6-20 Oracle Database Application Developer's Guide - Fundamentals

Using Dynamic SQL in Languages Other Than PL/SQL

■If you use C/C++, you can call dynamic SQL with the Oracle Call Interface (OCI), or you can use the Pro*C/C++ precompiler to add dynamic SQL extensions to your C code.

■If you use COBOL, you can use the Pro*COBOL precompiler to add dynamic SQL extensions to your COBOL code.

■If you use Java, you can develop applications that use dynamic SQL with JDBC.

If you have an application that uses OCI, Pro*C/C++, or Pro*COBOL to execute dynamic SQL, you should consider switching to native dynamic SQL inside PL/SQL stored procedures and functions. The network round-trips required to perform dynamic SQL operations from client-side applications might hurt performance. Stored procedures can reside on the server, eliminating the network overhead. You can call the PL/SQL stored procedures and stored functions from the OCI, Pro*C/C++, or Pro*COBOL application.

See Also: For information about calling Oracle Database stored procedures and stored functions from various languages:

■

■

■

Oracle Call Interface Programmer's Guide

Pro*C/C++ Programmer's Guide

Pro*COBOL Programmer's Guide

Coding Dynamic SQL Statements 6-21

Using Dynamic SQL in Languages Other Than PL/SQL

6-22 Oracle Database Application Developer's Guide - Fundamentals

Соседние файлы в папке Oracle 10g