我需要将DB2中的for语句转换为MYSQL,但到目前为止我还不知道。有人可以给我一些提示或告诉我如何在MYSQL中编写它吗? 下面的代码是我在IBM网站上找到的声明的示例。
BEGIN
DECLARE fullname CHAR(40);
FOR v1 AS
c1 CURSOR FOR
SELECT firstname, midinit, lastname FROM employee
DO
SET fullname =
lastname CONCAT ', '
CONCAT firstname
CONCAT ' '
CONCAT midinit;
INSERT INTO TNAMES VALUES ( fullname );
END FOR;
END;
答案 0 :(得分:0)
也许这
MariaDB [sandbox]> select title,firstname,middlename,lastname from awperson limit 10;
+-------+-----------+------------+------------+
| title | firstname | middlename | lastname |
+-------+-----------+------------+------------+
| | Ken | J | Sánchez |
| | Terri | Lee | Duffy |
| | Roberto | | Tamburello |
| | Rob | | Walters |
| Ms. | Gail | A | Erickson |
| Mr. | Jossef | H | Goldberg |
| | Dylan | A | Miller |
| | Diane | L | Margheim |
| | Gigi | N | Matthew |
| | Michael | | Raheem |
+-------+-----------+------------+------------+
10 rows in set (0.00 sec)
MariaDB [sandbox]>
MariaDB [sandbox]> drop table if exists t;
Query OK, 0 rows affected (0.19 sec)
MariaDB [sandbox]> create table t (fullname varchar(100));
Query OK, 0 rows affected (0.42 sec)
MariaDB [sandbox]> insert into t(fullname)
-> select trim(concat(ifnull(title,''),' ',ifnull(firstname,''),' ',ifnull(middlename,''),' ',ifnull(lastname,'')))
-> from awperson
-> limit 10;
Query OK, 10 rows affected (0.17 sec)
Records: 10 Duplicates: 0 Warnings: 0
MariaDB [sandbox]>
MariaDB [sandbox]> select * from t;
+-----------------------+
| fullname |
+-----------------------+
| Ken J Sánchez |
| Terri Lee Duffy |
| Roberto Tamburello |
| Rob Walters |
| Ms. Gail A Erickson |
| Mr. Jossef H Goldberg |
| Dylan A Miller |
| Diane L Margheim |
| Gigi N Matthew |
| Michael Raheem |
+-----------------------+
10 rows in set (0.00 sec)