如何按照以下的内容写成SQL的存储过程?--------------------------------------------
1. Sequential read Loan Master (LN) next
2. If EOF then end program
3. Skip the inactive loan account (D.SCD=’A’)
4. Set an array with elements of due pay_principal and due_date.
5. Set install_no = 0 ,x integer
6. Total_paid_principal =WAM - WOS
7. Sequential read loan schedule master (LS) at end go to (13)
8. If loan no. (LN.REF) not match then go to (13)
9. Install_no = Install_no + 1
10. Pay_principal(install_no) = AMT
11. Due_date(install_no) = DAT
12. Go to (7)
13. If Install_no = 0 then
Set install_no = 1
Pay_principal(install_no) = WOS
Due_date(install_no) = MTD
Go to (16)
14. If Total_paid_principal = 0 then go to (16)
15. Do until x > install_no or Total_paid_principal = 0
If Total_paid_principal >= Pay_principal(x) then
Total_paid_principal = Total_paid_principal - Pay_principal(x)
Pay_principal(x) = 0 
Else
Pay_principal(x) = Pay_principal(x) - Total_paid_principal
Total_paid_principal = 0
Endif
End do
16. Do until x > install_no 
If Pay_principal(x) > 0 
REFERENCE NO. = loan no. || install_no
If x = 1 then
ACCRUE INTEREST = NAC
End-if
Write a record
Endif
End do
17. go to (1)