MYSQL 動態sql語句

2021-04-26 09:49:15 字數 1936 閱讀 1496

直接執行sql宣告(sqlstatement)

例程:stringmysql

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 ;

準備sql宣告(sqlsa)

執行sql宣告(sqlsa)

例程:intemp_id_var = 56

prepare sqlsa

from "delete from employee where emp_id=?" ;

execute sqlsa using :emp_id_var ;

為動態傳輸區 宣告 游標|程序動態游標|程序

根據sql宣告(sqlca)準備動態傳輸區

開啟動態游標

取出游標程序值

關閉游標

例程: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 ;

為動態傳輸區 宣告 游標|程序動態游標|程序

根據sql宣告(sqlca)準備動態傳輸區

寫入動態描述區

開啟動態游標

取出游標程序值

關閉游標

例程:string stringvar, sqlstatement

integer intvar

sqlstatement = "select emp_id from employee"

prepare sqlsa from :sqlstatement ;

describe sqlsa into sqlda ;

declare my_cursor dynamic cursor for sqlsa ;

open dynamic my_cursor using descriptor sqlda ;

fetch my_cursor using descriptor sqlda ;

// if the fetch is successful, the output

// descriptor array will contain returned

// values from the first row of the result set.

// sqlda.numoutputs contains the number of

// output descriptors.

// the sqlda.outparmtype array will contain

// numoutput entries and each entry will contain

// an value of the enumerated data type parmtype

// (such as typeinteger!, or typestring!).

choose case sqlda.outparmtype[1]

case typestring!

stringvar = getdynamicstring(sqlda, 1)

case typeinteger!

intvar = getdynamicnumber(sqlda, 1)

end choose

close my_cursor ;

mysql動態sql語句

直接執行sql宣告 sqlstatement 例程 string mysql mysql create table employee emp id integer not null,dept id integer not null,emp fname char 10 not null,emp lna...

mysql執行動態sql語句

今天oracle群上有人問mysql可不可以執行動態的sql語句,搜了一下,居然可以。set tsql select from companyinfo prepare stmt1 from tsql execute stmt1 set fid fid set table1 companyinfo s...

動態SQL語句

動態使用sql語句的幾點技巧 動態sql語句,就是sql語句中引數會變化的sql語句,一般在程式中要根據使用者的需要隨時改變其引數值,對於動態sql語句必須注意以下幾點 先呼叫close方法,關閉query元件。如果query元件已經關閉,呼叫close方法不會出錯,也沒有其它影響。再呼叫clear...