我尝试使用SQL在SQL中将两行合并为一个新ID号
ID Amount
------------
1 100
2 200
3 300
4 400
5 500
6 600
到
ID Amount
-------------
1 100
2 200
101 700
5 500
6 600
感谢您的帮助。
答案 0 :(得分:0)
结帐SQL Procedures。我不确定您的目标,但我认为您需要的是定义SQL过程。自从我这样做以来,我就是这样,但它应该像:
CREATE OR REPLACE PROCEDURE combine(
ID1 IN <TABLE_NAME>.ID%TYPE,
ID2 IN <TABLE_NAME>.ID%TYPE,
NEWID IN <TABLE_NAME>.ID%TYPE)
IS
BEGIN
INSERT INTO <TABLE_NAME> (ID, Amount) VALUES(NEWID, ((SELECT Amount FROM <TABLE_NAME> WHERE ID=ID1) + (SELECT Amount FROM <TABLE_NAME> WHERE ID=ID2)));
DELETE FROM <TABLE_NAME> WHERE ID = ID1;
DELETE FROM <TABLE_NAME> WHERE ID = ID2;
COMMIT;
END;
/
要获得您所描述的状态,您可以通过
调用例程combine(4, 5, 101);