我是sql初学者..我想让程序像oracle中的序列一样
制作程序,我遇到错误:1242...请帮助我~
目标表
创建表 id_generator (
seq_currval INT(8) UNSIGNED NOT NULL, org_code varchar(4) not null
);
程序
分隔符 $$
如果存在则删除过程 sp_seq$$
创建过程 sp_seq(IN org_code varchar(4), OUT parma1 VARCHAR(11))
开始
DECLARE year VARCHAR(1); DECLARE month VARCHAR(2); DECLARE seq_current int; SET year = '5'; SET month = '01'; SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
START TRANSACTION; SET seq_current = (select seq_currval from id_generator where org_code = org_code); update id_generator set seq_currval = seq_current + 1 where org_code = org_code; COMMIT; SET seq_current = seq_current + 1; select CONCAT(year, month ,seq_current);
结束 $$
分隔符;
调用程序后,我发现错误:1242:
调用 sp_seq('1234');
--> 错误:错误代码:1242。子查询返回多于 1 行