Plsql 从早上开始就把我的头发拔出来。从那时起,我一定已经25岁了。我想我一个人永远也抓不到这个。 CREATE OR REPLACE PROCEDURE SPLIT_STOCK (p_stock_id IN NUMBER,p_split_factor IN NU

Plsql 从早上开始就把我的头发拔出来。从那时起,我一定已经25岁了。我想我一个人永远也抓不到这个。 CREATE OR REPLACE PROCEDURE SPLIT_STOCK (p_stock_id IN NUMBER,p_split_factor IN NU,plsql,Plsql,从早上开始就把我的头发拔出来。从那时起,我一定已经25岁了。我想我一个人永远也抓不到这个。 CREATE OR REPLACE PROCEDURE SPLIT_STOCK (p_stock_id IN NUMBER,p_split_factor IN NUMBER) AS l_multiplied_shares NUMBER; l_new_shares NUMBER; l_current_shares NUMBER; l_number_of_shareholders NUMBER; l_com

从早上开始就把我的头发拔出来。从那时起,我一定已经25岁了。我想我一个人永远也抓不到这个。
CREATE OR REPLACE PROCEDURE SPLIT_STOCK (p_stock_id IN NUMBER,p_split_factor IN NUMBER)
AS
l_multiplied_shares  NUMBER;
l_new_shares NUMBER;
l_current_shares NUMBER;
l_number_of_shareholders NUMBER;
l_company_id NUMBER;
l_shares_authorized NUMBER;
SPLIT_FACTOR_LESS_THAN_1_EXC EXCEPTION;
SHARES_EXCEEDED_EXC EXCEPTION;
BEGIN
IF p_split_factor <=1 THEN  RAISE SPLIT_FACTOR_LESS_THAN_1_EXC ;  END IF; --Share split factor has to be > 1.

SELECT sum(CShSh.shares) * p_split_factor into l_multiplied_shares from Current_Shareholder_Shares CShSh where CShSh.stock_id = p_stock_id;  --Getting the new total shares after the split
select authorized into l_shares_authorized from shares_authorized sa where sa.stock_id = p_stock_id; --getting number of authorized shares into local variable
select sum(shares) INTO l_current_shares from Current_Shareholder_Shares CShSh where CShSh.stock_id = p_stock_id; --getting the current total shares for this stock
if l_multiplied_shares > l_current_shares THEN RAISE SHARES_EXCEEDED_EXC; END IF; --Did we exceed allowed shares? Raise exception if so.
l_new_shares := l_multiplied_shares - l_current_shares; --This is the new amount of shares to be split evenly among current Shareholders.
Select count(shareholder_id) into l_number_of_shareholders from Current_Shareholder_Shares CShSh where CShSh.stock_id = p_stock_id; --This is the number of shareholders, we need to divide by this number to issue everyone their share of the split shares.
select com.company_id into l_company_id from company com where com.stock_id = p_stock_id; -- getting the company id of the company that is doing the split.

INSERT INTO trade -- (trade_id, stock_id, transaction_time,shares,stock_ex_id,price_total,buyer_id,seller_id,buy_broker_id,sell_broker_id)

               SELECT  trade_id_seq.nextval, p_stock_id, SYSDATE, (l_new_shares/l_number_of_shareholders), NULL, NULL, CShSh.shareholder_id , l_company_id, 
               NULL, NULL
               FROM Current_Shareholder_Shares CShSh;
EXCEPTION
WHEN SPLIT_FACTOR_LESS_THAN_1_EXC THEN dbms_output.put_line ('Please enter a split factor greater than 1. Decimals are also allowed.');
WHEN SHARES_EXCEEDED_EXC THEN dbms_output.put_line ('Number of Authorized shares has been exceeded. split factor needs to be smaller.');
END
;
/



EXEC SPLIT_STOCK(6,100001); -- this should throw my specific defined exception
EXEC SPLIT_STOCK(6,0.5); -- this should throw my specific defined exception
EXEC SPLIT_STOCK(6,100001); -- this should throw my specific defined exception
BEGIN SPLIT_STOCK(6,100001); -- this should throw my specific defined exception; END;
EXEC SPLIT_STOCK(6,100001) /* this should throw my specific defined exception */