当前位置:首页 » 编程语言 » 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 浏览:80
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