0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Azure Data Factory にて Azure SQL Database のストアードプロシージャのリターン値を受け取る方法

Last updated at Posted at 2023-09-07

概要

Azure Data Factory にて Azure SQL Database のストアードプロシージャのリターン値を受け取る方法として、スクリプトアクティビティを利用する方法を共有します。

検証コードと実行結果

1. ストアードプロシージャを Azure SQL Database に配置

Param1パラメータとParam2パラメータの文字を結合して返すストアードプロシージャを Azure SQL Database にデプロイします。

-- DROP  PROCEDURE dbo.StoredProcedure001;
CREATE PROCEDURE dbo.StoredProcedure001
    @Param1 VARCHAR(50),
    @Param2 VARCHAR(50),
	@OutputValues VARCHAR(200) OUTPUT
AS
BEGIN
    SET @OutputValues =@Param1 + @Param2;
END;

image.png

Hello World !を渡すと、Hello World !を返します。

DECLARE @abc nvarchar(200)

EXEC dbo.StoredProcedure001 'Hello ','World !',@abc OUTPUT

SELECT @abc

image.png

2. Azure Data Factory にてストアードプロシージャをコールするスクリプトアクティビティのパイプラインを作成

image.png

パイプライン定義
{
    "name": "pipeline",
    "properties": {
        "activities": [
            {
                "name": "Script1_copy1",
                "type": "Script",
                "dependsOn": [],
                "policy": {
                    "timeout": "0.12:00:00",
                    "retry": 0,
                    "retryIntervalInSeconds": 30,
                    "secureOutput": false,
                    "secureInput": false
                },
                "userProperties": [],
                "linkedServiceName": {
                    "referenceName": "sqldb__pj1",
                    "type": "LinkedServiceReference"
                },
                "typeProperties": {
                    "scripts": [
                        {
                            "parameters": [
                                {
                                    "name": "Param1",
                                    "type": "String",
                                    "value": "a",
                                    "direction": "Input"
                                },
                                {
                                    "name": "Param2",
                                    "type": "String",
                                    "value": "b",
                                    "direction": "Input"
                                },
                                {
                                    "name": "OutputValues",
                                    "type": "String",
                                    "value": "",
                                    "direction": "Output",
                                    "size": "200"
                                }
                            ],
                            "type": "Query",
                            "text": "EXEC dbo.StoredProcedure001 'Hello ','World !',@OutputValues OUTPUT"
                        }
                    ],
                    "scriptBlockExecutionTimeout": "02:00:00"
                }
            }
        ],
        "annotations": []
    }
}

3. Azure Data Factory にてパイプラインをデバック実行して、リターン値を確認

アクティビティの出力内におけるoutputParametersにてリターン値を取得していること確認。

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?