if(@newtag<>'',(insert into A(text,tag) values('test',@newtag)),(insert into A(text,tag) values('test',concat(@tag,'01'))));@newtag和@tag分别是两个查询得到的结果,是没有什么问题的,上面判断@newtag=''为真我就执行第一个插入语句,否则我就插入地2个,但我执行的时候这里有错误,是不是不可以这样写,如果不可以这样写我应该怎么改呢?高手指教!
解决方案 »
- 纠结中,Ubuntu版本和mysql源代码版本选择问题??
- 安装mysqldb时遇到问题
- 关于MYSQL CLUSTER均衡负载的问题
- win2k +j2sdk1.4.2_01+MySQL Server 4.1+Tomcat 4.1 配置出错?
- >>>建立表格时将多个字段设置为主键的sql语句怎么写??<<<<
- 热情讨论MySQL的全文搜索
- SQL server 中同一个数据库中的两个表合成一个表?在线等待?
- 上亿条记录,数据库建立和使用应如何操作?求解
- mysql存储过程能不能直接执行拼接的sql语句
- 数据库优化 FIND_IN_SET 逻辑问题
- Mysql 初学分页问题
- group by 两个条件按的问题
if @newtag<>'' then
insert into A(text,tag) values('test',@newtag))
else
insert into A(text,tag) values('test',concat(@tag,'01'))
end if
BEGIN
select tag from A where text = inpass into @tag;
set @newtag='';
select tag+1 from A where tag like concat(@tag,'__') order by tag desc limit 1 into @newtag;
if @newtag <>'' then
insert into A(text,tag) values('test',@newtag));return true;
else
insert into A(text,tag) values('test',concat(@tag,'01'));return false;
end if;
END
mysql> source /root/Desktop/ietm_proc.txt结果就是:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3
Query OK, 0 rows affected (0.00 sec)Query OK, 1 row affected (0.00 sec)ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if @newtag <>'' then
insert into treeview(nodetext,tag) values('test',@newtag))' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'return true' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'else
insert into treeview(nodetext,tag) values('test',concat(@tag,'01'))' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'return false' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'end if' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 1
Maybe this is what you expected.delimiter ||
CREATE procedure sp_insertRow(
inpass varchar(200)
)
BEGIN
select tag from A where `text` = inpass into @tag;
set @newtag='';
set @s=concat('select tag+1 from A where tag like ''',@tag,'__'' order by tag desc limit 1 into @newtag');
prepare s1 from @s;
execute s1;
drop prepare s1;
set @s = NULL;
if @newtag <>'' then
insert into A(`text`,tag) values('test',@newtag);
select true;
else
insert into A(`text`,tag) values('test',concat(@tag,'01'));
select false;
end if;
set @newtag = NULL;
set @tag = NULL;
END||
delimiter ;