儲存過程示例

2021-07-11 02:39:56 字數 1083 閱讀 8603

@orderid nvarchar(50),--訂單號

@userid int,--使用者編號

@address nvarchar(255),--收貨人位址

@totalmoney money output --總金額

asbegin

declare @error int

set @error=0

--計算總金額

begin transaction

select @totalmoney=sum(unitprice*[count]) from books inner join cart on

books.id=cart.bookid where cart.userid=@userid

set @error=@@error+@error

--向訂單主表中插入資料.

insert into dbo.orders(orderid, orderdate, userid, totalprice, postaddress, state) values(@orderid,getdate(),@userid,@totalmoney,@address,0)

set @error=@@error+@error

--向明細表中插入資料

insert into dbo.orderbook(orderid, bookid, quantity, unitprice)select @orderid,bookid,[count],unitprice from books inner join cart on

books.id=cart.bookid where cart.userid=@userid

set @error=@@error+@error

--刪除購物車表中當前使用者的資料

delete from cart where userid=@userid

set @error=@@error+@error

if @error>0

begin

rollback transaction

endelse

begin

commit transaction

endend

儲存過程示例

1.輸入乙個引數,要求判斷表內容中欄位存在的5,非5,所有等三種情況 方案1 create or replace package body allan is procedure insert test imput varchar2 cur out mytype is begin open cur f...

儲存過程示例

建立測試資料 create table book 編號 number 10 書名 varchar2 20 varchar2 20 insert into book values 100,aa 88.77 select from book 建立儲存過程 create or replace proced...

儲存過程示例

create or replace procedure cmpp submit remove procedure isdendtime date 每次處理是時間點 取得要處理的資料id cursor c cmpp submit endtime date is select id from cmpp ...