我是sql的初学者.. 我希望make程序在oracle中表现得像序列一样 制作程序,我遇到错误:1242 ...请帮帮我〜
目标表
CREATE TABLE id_generator(
seq_currval INT(8) UNSIGNED NOT NULL, org_code varchar(4) not null
);
程序
delimiter $$
如果存在sp_seq $$
,则删除程序CREATE PROCEDURE sp_seq(IN org_code varchar(4),OUT parma1 VARCHAR(11))
BEGIN
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);
END $$
分隔符;
在通话程序后,我找到了错误:1242:
CALL sp_seq('1234');
- >错误:错误代码:1242。子查询返回超过1行
答案 0 :(得分:0)
此查询
SET seq_current = (select seq_currval
from id_generator
where org_code = org_code);
返回多条记录,不能存储在单个变量中。
where org_code = org_code
总是如此。将输入参数重命名为列名以外的值。否则,DB无法区分它们。
答案 1 :(得分:0)
此查询
select seq_currval
from id_generator
where org_code = org_code
始终返回与1 = 1相似的所有行
将其更改为:
select seq_currval
from id_generator
where id_generator.org_code = org_code