生成测试需要的大量数据的时候,需要使用到如循环语句这样的流程语句?Oracle可以直接在匿名块中使用流程语句,SQL server可以直接写流程语句,MySQL呢?
mysql> delimiter $
mysql> set @id=1;
-> if @id>0 then select @id;
-> end if;
-> $
Query OK, 0 rows 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 @id>0 then select @id;
end if' at line 1
必须在其他对象中使用;
mysql> create procedure testif()
-> begin
-> set @id=1;
-> if @id>0 then select @id;
-> end if;
-> end;
-> $
Query OK, 0 rows affected (0.00 sec)
mysql> call testif()$
+------+
| @id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
也许要多做对比才能不那么容易混淆。