简体   繁体   English

存储过程中参数的动态数据类型

[英]Dynamic Data Type of Parameters in Stored procedure

I have a table Customer which has 3 columns 我有一个表Customer ,其中有3列

CCode varchar(100),
CName varchar(200),
Address varchar(500)

I want to create a procedure to insert data, I want that datatype of parameter should be selected automatically according to the table columns, so that for example if i need to change the CCode datatype from varchar to int in the table, it should be automatically change the datatype of parameter CCode . 我想创建一个插入数据的过程,我希望根据表列自动选择参数的数据类型,例如,如果我需要在表中将CCode数据类型从varchar更改为int,则应自动更改参数CCode的数据类型。

Like oracle provide % type attribute, as you can see in below link: 就像oracle提供%type属性一样,您可以在下面的链接中看到:

https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/type_attribute.htm https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/type_attribute.htm

I want same functionality as mentioned in above link. 我想要与上述链接中提到的功能相同的功能。

SQL Server doesn't support the %TYPE functionality that Oracle has. SQL Server不支持Oracle具有的%TYPE功能。 You could use sql_variant , but that has drawbacks around knowing what type it's supposed to be. 您可以使用sql_variant ,但这在知道它应该是哪种类型方面有缺点。 You could also try having a variety of optional parameters, and then using whichever is actually going to be used in your situation. 您还可以尝试使用各种可选参数,然后使用适合您情况的任何参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM