如何在PL / SQL中执行此操作?我试过但我有一些错误。
select * from account
acc_locked
表格DECLARE
CURSOR T IS
SELECT CUST_ID,A_NO ,TYPE, BALANCE,STATUS
FROM ACCOUNT
where STATUS=('نشط')
order by BALANCE desc;
CURSOR D IS
SELECT CUST_ID,A_NO ,TYPE, BALANCE,STATUS
FROM ACC_LOCKED
order by BALANCE desc;
ci ACC_LOCKED.CUST_ID%TYPE;
an ACCOUNT.A_NO%TYPE;
ty ACCOUNT.TYPE%TYPE;
ba ACCOUNT.BALANCE%TYPE;
st ACCOUNT.STATUS%TYPE;
BEGIN
OPEN T ;
FOR p IN 1..3 LOOP
FETCH T INTO ci , an ,ty , ba ,st ;
DBMS_OUTPUT.PUT_LINE( ci ||' '|| an||' '||ty||' '||ba ||' '||st);
END LOOP ;
CLOSE T ;
INSERT INTO ACC_LOCKED (CUST_ID,A_NO ,TYPE, BALANCE,STATUS)
select CUST_ID,A_NO ,TYPE, BALANCE,STATUS
from ACCOUNT
where STATUS=('موقوف')
order by BALANCE desc;
END;
答案 0 :(得分:0)
您还有3个步骤,您还列出了什么。
第1步=你做的光标,光标'T',看起来很好。
第2步=循环通过光标'T',看起来很好。
第3步=不起作用,因为你已经关闭了光标'T'。
也许这个更简单的例子会给你一个想法:
DECLARE
CURSOR T IS
SELECT CUST_ID,A_NO ,TYPE, BALANCE,STATUS
FROM ACCOUNT
WHERE STATUS='Available'
ORDER BY BALANCE DESC;
BEGIN
FOR recT IN T LOOP
-- You can print every value form cursor T this way.
DBMS_OUTPUT.PUT_LINE(recT.Cust_Id);
--Insert in table, add every column to insert here.
INSERT INTO Acc_Locked (Cust_Id, A_No)
VALUES(recT.Cust_Id, recT.A_No);
END LOOP;
-- Save what you just inserted.
COMMIT;
END;