mysql 輸出引數 sql 儲存過程輸出引數

2021-10-20 22:37:15 字數 1253 閱讀 2355

在本教程中,將學習如何使用輸出引數將資料返回給呼叫程式。

建立輸出引數

若要為儲存過程建立輸出引數,請使用以下語法:

parameter_name data_type output

儲存過程可以具有許多輸出引數。 另外,輸出引數可以是任何型別,例如:整數,日期和變化的字元。

例如,以下儲存過程按型號年份查詢產品,並通過

create procedure uspfindproductbymodel (

@model_year smallint,

@product_count int output

) as

begin

select

product_name,

list_price

from

production.products

where

model_year = @model_year;

select @product_count = @@rowcount;

end;

在此儲存過程中:

首先,建立了乙個名為

@product_count int output

其次,在select語句之後,將查詢返回的行數(

執行上面的create procedure語句後,將編譯uspfindproductbymodel儲存過程並將其儲存在資料庫目錄中。

如果一切正常,sql server會發出以下輸出:

命令已成功完成。

使用輸出引數呼叫儲存過程

要使用輸出引數呼叫儲存過程,請按照下列步驟操作:

首先,宣告變數以儲存輸出引數返回的值。

其次,在儲存過程呼叫中使用這些變數。

例如,以下語句執行uspfindproductbymodel儲存過程:

declare @count int;

exec uspfindproductbymodel

@model_year = 2018,

@product_count = @count output;

select @count as '產品總數量:';

執行上面查詢語句,得到以下結果:

¥ 我要打賞

糾錯/補充

收藏加qq群啦,易百教程官方技術學習群

注意:建議每個人選自己的技術方向**,同乙個qq最多限加 3 個群。

Oracle執行引數化SQL語句和儲存過程

using system using system.collections.generic using system.text using system.data.oracleclient using system.data namespace oracleopdemo private static...

儲存過程輸出引數

呼叫方法 sqldatabase db new sqldatabase db.dbconn.open db.dbcmd.commandtype commandtype.storedprocedure db.dbcmd.commandtext eip reportmt1 db.dbcmd.parame...

mysql儲存過程now mysql儲存過程

建立清除過期積分儲存過程 delimiter drop procedure if exists reporturl create procedure reporturl begin 定義變數 declare s int default 0 declare sum integral varchar 2...