%ROWTYPE相当于在SQL Server

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了%ROWTYPE相当于在SQL Server相关的知识,希望对你有一定的参考价值。

我对存储过程从PL / SQL转换到SQL Server。该过程通过一个select查询的结果使用游标循环。有没有SQL服务器相当于给ORACLE rowtype构建?

答案

这是一个巨大的原因相比,甲骨文的时候不喜欢的SQL Server。

我很失望,SS不必%TYPE和%ROWTYPE。这些节省工时当最初编写代码,并在一列的类型需要改变,它省去了回去事件重新工作的所有代码。

在Oracle我以前写的东西,如:

DECLARE @MyRowVar AS ATable%ROWTYPE;

在SQL Server中,我不得不写这本:

DECLARE @External_ID                AS BIGINT = NULL;
DECLARE @PlatformID                 AS INT = NULL;
DECLARE @ActorIDOfReseller          AS INT = NULL;
DECLARE @ActorIDOfClient            AS INT = NULL;
DECLARE @ActorIDOfExtension         AS INT = NULL;
DECLARE @CallType                   AS NCHAR (10) = NULL;
DECLARE @CallInitiatedDate          AS DATE = NULL;
DECLARE @CallInitiatedTimeHH24MI    AS TIME (0) = NULL;
DECLARE @TimePeriodID               AS INT = NULL;
DECLARE @CallAnswered               AS DATETIME = NULL;
DECLARE @CallAnsweredYN             AS BIT = NULL;
DECLARE @CallDispositionID          AS INT = NULL;
DECLARE @CountryID                  AS INT = NULL;
DECLARE @CallPrefixID               AS INT = NULL;
DECLARE @FromNumber                 AS VARCHAR (32) = NULL;
DECLARE @ToNumber                   AS VARCHAR (80) = NULL;
DECLARE @CallDuration               AS INT = NULL;
DECLARE @CallCostToExtension        AS DECIMAL (10, 6) = NULL;
DECLARE @CallCostToClient           AS DECIMAL (10, 6) = NULL;
DECLARE @CallCostToReseller         AS DECIMAL (10, 6) = NULL;
DECLARE @CallCostToAdmin            AS DECIMAL (10, 6) = NULL;
DECLARE @Flow                       AS VARCHAR (3) = NULL;
DECLARE @CallStart                  AS DATETIME = NULL;
DECLARE @MoneyUnit                  AS VARCHAR (32) = NULL;
DECLARE @Prefix                     AS VARCHAR (32) = NULL;
DECLARE @External_CallID            AS VARCHAR (255) = NULL;

这让我很伤心。

哈维

另一答案

下面使用的光标的SQL方式被示出

DECLARE @colA varchar(50), @colB varchar(50)

DECLARE myCursor CURSOR FOR
Select columnA, columnB From table

OPEN myCursor

FETCH NEXT FROM myCursor INTO @colA, @colB

WHILE @@FETCH_STATUS = 0
BEGIN

--do something with @colA and @colB

FETCH NEXT FROM myCursor INTO @colA, @colB

END

CLOSE myCursor
DEALLOCATE myCursor

reference link

另一答案

由于@HarveyFrench回应没有@rowtype。要生成所有列变量您可以使用此选择和复制的结果粘贴:

SELECT 'DECLARE @customPrefix' + COLUMN_NAME  + '  ' +  DATA_TYPE + ';'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE 
TABLE_NAME = 'Your_table' 

以上是关于%ROWTYPE相当于在SQL Server的主要内容,如果未能解决你的问题,请参考以下文章

Oracle PL/SQL Developer:从包过程中返回 %RowType

JDBC 中的 Pl/sql %RowType

oracle type is table of rowtype和rowtype的区别

Oracle PL SQL ref cursor%ROWTYPE 此表达式的类型声明不完整或格式错误

pl/sql 中的 ROWTYPE 定义

SQL Server 2005相当于OFFSET / FETCH [重复]