我怎样才能在解码功能中查询?
how can i put a query in decode function?
create table ss( no number, filepath varchar2(300) )
我想在此 table
中包含 5 个或更少的 'no' 重复值
当select count(no) from ss where no=#{no} <5
、insert into ss values({no},{filepath})
所以 'no' 的重复值不能超过 5。
我该怎么做?
您可以创建一个类似的触发器来实现此逻辑:
CREATE OR REPLACE TRIGGER set_no_ss_tbl_trg
BEFORE INSERT ON ss_tbl
FOR EACH ROW
BEGIN
DECLARE
l_cnt_no NUMBER;
BEGIN
SELECT COUNT(1)
INTO l_exceeding
FROM g_piece
WHERE refdoss = :new.no;
IF l_cnt_no > 5 THEN
SELECT MIN(no)
INTO :new.no
FROM (SELECT COUNT(1), no
FROM ss_tbl
GROUP BY no
HAVING COUNT(1) + 1 <= 5);
END IF;
END;
END;
create table ss( no number, filepath varchar2(300) )
我想在此 table
中包含 5 个或更少的 'no' 重复值当select count(no) from ss where no=#{no} <5
、insert into ss values({no},{filepath})
所以 'no' 的重复值不能超过 5。 我该怎么做?
您可以创建一个类似的触发器来实现此逻辑:
CREATE OR REPLACE TRIGGER set_no_ss_tbl_trg
BEFORE INSERT ON ss_tbl
FOR EACH ROW
BEGIN
DECLARE
l_cnt_no NUMBER;
BEGIN
SELECT COUNT(1)
INTO l_exceeding
FROM g_piece
WHERE refdoss = :new.no;
IF l_cnt_no > 5 THEN
SELECT MIN(no)
INTO :new.no
FROM (SELECT COUNT(1), no
FROM ss_tbl
GROUP BY no
HAVING COUNT(1) + 1 <= 5);
END IF;
END;
END;