如何将数组类型参数和普通参数传递给pl / sql中的过程? [英] How to pass an array type parameter and normal parameter into a procedure in pl/sql ?
问题描述
我不想如何从过程的参数传递数组类型参数以及如何将该参数数组值与同一过程体中的现有游标值进行比较。
示例:
i希望在该过程中传递{1,2,3,4,5} varchar类型。它将与现有游标值c_abc {1,2,4,9}进行比较。
I want to no how to pass array type parameter from a procedure's parameter and how i will compare that parameter array value with an existing cursor value in a same procedure body.
example:
i want to pass a{1,2,3,4,5} varchar type in that procedure. and it will compare with the existing cursor value c_abc {1,2,4,9}.
推荐答案
如上所述,您需要使用Microsoft SQL Server 2008或更高。
然后你可以使用表值参数通过一个参数传递多个数据值。
这是一个例子。
步骤1:你需要创建表值参数类型根据需要。
As mentioned in above answer you need to use Microsoft SQL Server 2008 or higher.
Then you can use table-valued parameters to pass the multiple data values through a single parameter.
Here is an example.
Step 1: you need to create the table-valued parameter type as you need.
CREATE TYPE dbo.Products AS TABLE
( ID int, Description varchar(50) )
第2步:然后创建一个存储的程序
Step 2: Then create a Stored Prcedure
CREATE PROCEDURE getProductDetails
(@itemIDs dbo.Products)
AS
BEGIN
SELECT * FROM @Products
END
第3步:为了从c#或代码中传递数据,创建一个DataTable当我们传递给普通参数时,将对象传递给存储过程。
Step 3: In order to pass the data from c# or what ever the code, create a DataTable object and pass it to the Stored Procedure as we pass to the normal parameters.
假设您使用的是Microsoft SQL Server 2008或更高版本,请使用表值参数:
表值参数 [ ^ ]
表值参数(数据库引擎) [ ^ ]
Assuming you're using Microsoft SQL Server 2008 or higher, use table-valued parameters:
Table-Valued Parameters[^]
Table-Valued Parameters (Database Engine)[^]
这篇关于如何将数组类型参数和普通参数传递给pl / sql中的过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!