當前位置:首頁 » 編程語言 » mysql動態sql

mysql動態sql

發布時間: 2022-10-07 08:57:08

1. Mysql觸發器怎麼變相使用動態SQL

一般mysql觸發器變相使用動態sql可以通過如下方法:
1、一個是直接調用存儲過程,因為mysql的存儲過程還是支持動態sql的
2、一個是通過MyBatis直接動態傳入參數包括表名、欄位名等等

2. 如何執行mysql動態SQL

連接字元串用CONCAT,在用
prepare s1 from @x;
execute s1;
執行

3. mysql 如何給變數賦一個動態sql執行的結果

DECLAREdt_idvarchar(32);
SET@sqls=CONCAT('SELECTid
FROM
w_volume_detail
WHERE
v_id="',dd_id,'"ANDuidISNULLLIMIT0,1');
executeimmediate@sqlsintodt_id;

4. MySQL觸發器怎麼變相使用動態SQL

MySQL觸發器動態sql: CREATE TRIGGER trigger1 after INSERT ON cdr FOR EACH ROW BEGIN DECLARE id BIGINT; DECLARE vname VARCHAR(200); DECLARE destination VARCHAR(200) DEFAULT 'null'; DECLARE rows1 BIGINT DEFAULT 0; DECLARE sql1 VARCHAR(2000); SELECT v.vendorid,v.name, ve.DestinationID INTO id, vname, destination FROM (select name, v.VendorID from vendor v natural join vendorendpoints where endpoint=NEW.Field27) v NATURAL JOIN (SELECT * FROM vendorextraction order by length desc) ve WHERE substr(NEW.Field8 , 1 ,ve.length)=substr(CONCAT(ve.Prefix,ve.OperatorList),1,ve.length) limit 0,1; SET @@sql_mode='ansi'; SET sql1 =CONCAT('insert into `',CONCAT(vname,id),'` values(',id,',"',vname,'","',NEW.Field5,'","',NEW.Field35,'","',NEW.Field12,'","',NEW.Field8,'","',NEW.Field0,'")'); IF (id >0) THEN call testing(sql1); ELSE SET sql1 =CONCAT('insert into `unknown` values(',id,',"',vname,'","',NEW.Field5,'","',NEW.Field35,'","',NEW.Field12,'","',NEW.Field8... MySQL觸發器動態sql:
CREATE TRIGGER trigger1 after INSERT ON cdr
FOR EACH ROW

BEGIN

DECLARE id BIGINT;
DECLARE vname VARCHAR(200);
DECLARE destination VARCHAR(200) DEFAULT 'null';
DECLARE rows1 BIGINT DEFAULT 0;
DECLARE sql1 VARCHAR(2000);

SELECT v.vendorid,v.name, ve.DestinationID INTO id, vname, destination
FROM (select name, v.VendorID from vendor v natural join vendorendpoints where endpoint=NEW.Field27) v NATURAL JOIN (SELECT * FROM vendorextraction order by length desc) ve
WHERE
substr(NEW.Field8 , 1 ,ve.length)=substr(CONCAT(ve.Prefix,ve.OperatorList),1,ve.length) limit 0,1;

SET @@sql_mode='ansi';
SET sql1 =CONCAT('insert into `',CONCAT(vname,id),'` values(',id,',"',vname,'","',NEW.Field5,'","',NEW.Field35,'","',NEW.Field12,'","',NEW.Field8,'","',NEW.Field0,'")');

IF (id >0) THEN
call testing(sql1);
ELSE
SET sql1 =CONCAT('insert into `unknown` values(',id,',"',vname,'","',NEW.Field5,'","',NEW.Field35,'","',NEW.Field12,'","',NEW.Field8,'","',NEW.Field0,'")');
call testing(sql1);
END IF;

5. MySQL中寫動態SQL語句出錯,請指正

set @str='select ? from ?';

修改為

set @str= CONCAT ( 'select Sno from ', str1) ;

後面的

set @a=Sno;
set @b=str1;

刪除。

execute stmt1 using @a,@b;
修改為
execute stmt1

6. MySQL存儲過程中實現執行動態SQL語句的方法

本文實例講述了MySQL存儲過程中實現執行動態SQL語句的方法。分享給大家供大家參考。具體實現方法如下:
mysql>
mysql>
delimiter
$$
mysql>
mysql>
CREATE
PROCEDURE
set_col_value
->
(in_table
VARCHAR(128),
->
in_column
VARCHAR(128),
->
in_new_value
VARCHAR(1000),
->
in_where
VARCHAR(4000))
->
->
BEGIN
->
DECLARE
l_sql
VARCHAR(4000);
->
SET
l_sql=CONCAT_ws('
',
->
'UPDATE',in_table,
->
'SET',in_column,'=',in_new_value,
->
'
WHERE',in_where);
->
SET
@sql=l_sql;
->
PREPARE
s1
FROM
@sql;
->
EXECUTE
s1;
->
DEALLOCATE
PREPARE
s1;
->
END$$
Query
OK,
0
rows
affected
(0.00
sec)
希望本文所述對大家的MySQL資料庫程序設計有所幫助。

7. MySQL中能執行動態SQL嗎

可以的。

set v_sql= '動態SQL';

set @v_sql=v_sql; --將動態SQL字元串賦值給一個變數(可以之前沒有定義,但要以@開頭)
prepare stmt from @v_sql; --預處理需要執行的動態SQL,其中stmt是一個變數
EXECUTE stmt; --執行SQL語句
deallocate prepare stmt; --釋放掉預處理段

8. MySQL中能執行動態SQL嗎

mysql> PREPARE stmt1 FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
mysql> SET @a = 3;
mysql> SET @b = 4;
mysql> EXECUTE stmt1 USING @a, @b;

http://dev.mysql.com/doc/refman/5.0/en/sqlps.html

9. MySQL觸發器怎麼變相使用動態SQL

1、一個是直接調用存儲過程,因為mysql的存儲過程還是支持動態sql的
2、一個是通過MyBatis直接動態傳入參數包括表名、欄位名等等

10. MySQL中能執行動態SQL嗎

存儲過程中可以!
drop PROCEDURE if exists my_procere;
create PROCEDURE my_procere()
BEGIN
declare my_sqll varchar(500);
set my_sqll='select * from aa_list';
set @ms=my_sqll;
PREPARE s1 from @ms;
EXECUTE s1;
deallocate prepare s1;
end;

熱點內容
循跡小車演算法 發布:2024-12-22 22:28:41 瀏覽:79
scss一次編譯一直生成隨機數 發布:2024-12-22 22:04:24 瀏覽:954
嫁接睫毛加密 發布:2024-12-22 21:50:12 瀏覽:972
linuxbin文件的安裝 發布:2024-12-22 21:46:07 瀏覽:796
vlcforandroid下載 發布:2024-12-22 21:45:26 瀏覽:662
電腦做網關把數據發送至伺服器 發布:2024-12-22 21:44:50 瀏覽:429
新華三代理什麼牌子的伺服器 發布:2024-12-22 21:33:21 瀏覽:340
歡太會員密碼是什麼 發布:2024-12-22 20:57:28 瀏覽:71
sqllocaldb 發布:2024-12-22 20:07:08 瀏覽:123
如何找到我的伺服器 發布:2024-12-22 19:52:14 瀏覽:299