LogoLogo
SnowflakeDocumentation Home
  • Snowflake SnowConvert Documentation
  • General (Beta)
    • Getting Started
      • System Requirements
      • Download and Access
      • Best practices
      • End User License Agreement
      • Release Notes ( Beta)
    • General Issues and Troubleshooting
      • FAQ and Troubleshooting
      • Complex Pattern Issues
        • MSCCP0001
        • MSCCP0002
        • MSCCP0003
        • MSCCP0004
        • MSCCP0005
        • MSCCP0006
        • MSCCP0007
        • MSCCP0008
        • MSCCP0009
        • MSCCP0010
        • MSCCP0011
      • Conversion Issues
        • MSCEWI1001
        • MSCEWI1002
        • MSCEWI1003
        • MSCEWI1004
        • MSCEWI1005
        • MSCEWI1006
        • MSCEWI1007
        • MSCEWI1009
        • MSCEWI1010
        • MSCEWI1011
        • MSCEWI1012
        • MSCEWI1013
        • MSCEWI1014
        • MSCEWI1015
        • MSCEWI1016
        • MSCEWI1017
        • MSCEWI1018
        • MSCEWI1019
        • MSCEWI1020
        • MSCEWI1021
        • MSCEWI1022
        • MSCEWI1023
        • MSCEWI1024
        • MSCEWI1025
        • MSCEWI1026
        • MSCEWI1027
        • MSCEWI1028
        • MSCEWI1029
        • MSCEWI1030
        • MSCEWI1031
        • MSCEWI1032
        • MSCEWI1033
        • MSCEWI1034
        • MSCEWI1035
        • MSCEWI1036
        • MSCEWI1037
        • MSCEWI1038
        • MSCEWI1039
        • MSCEWI1040
        • MSCEWI1041
        • MSCEWI1042
        • MSCEWI1043
        • MSCEWI1044
        • MSCEWI1045
        • MSCEWI1046
        • MSCEWI1047
        • MSCEWI1048
        • MSCEWI1049
        • MSCEWI1050
        • MSCEWI1051
        • MSCEWI1052
        • MSCEWI1053
        • MSCEWI1054
        • MSCEWI1055
        • MSCEWI1056
        • MSCEWI1057
        • MSCEWI1058
          • Teradata
          • Oracle
          • SQL Server
        • MSCEWI1059
        • MSCEWI1060
        • MSCEWI1061
        • MSCEWI1062
        • MSCEWI1063
        • MSCEWI1064
        • MSCEWI1065
        • MSCEWI1066
        • MSCEWI1067
        • MSCEWI1068
        • MSCEWI1069
        • MSCEWI1070
        • MSCEWI1071
        • MSCEWI1072
        • MSCEWI1073
        • MSCEWI1074
        • MSCEWI1075
        • MSCEWI1076
        • MSCEWI1077
        • MSCEWI1078
        • MSCEWI1079
        • MSCEWI1080
        • MSCEWI1081
        • MSCEWI1082
        • MSCEWI1083
        • MSCEWI1084
        • MSCEWI1086
        • MSCEWI1087
        • MSCEWI1088
        • MSCEWI1089
        • MSCEWI1090
        • MSCEWI1091
        • MSCEWI1092
        • MSCEWI1093
        • MSCEWI1094
        • MSCEWI1095
        • MSCEWI1096
        • MSCEWI1097
        • MSCEWI1098
        • MSCEWI1099
        • MSCEWI1100
        • MSCEWI1101
        • MSCEWI1102
        • MSCEWI1108
      • Informative Issues
        • MSCINF0001
        • MSCINF0002
        • MSCINF0003
        • MSCINF0004
        • MSCINF0005
        • MSCINF0006
        • MSCINF0007
        • MSCINF0008
    • Review Results
      • Output Code
      • Reports
        • Assessment Report
          • Overall Conversion Summary
          • SQL Conversion Summary
          • Scripts Line Conversion Summary
          • Object Conversion Summary
          • File and Object Level Breakdown - SQL Files
          • File and Object Level Breakdown - SQL Identified Objects
          • Scripts - Files
          • Scripts - Identified Objects
          • Schemas
          • Databases & Schemas
        • Top-Level Objects Report
        • Top-Level Queries Report
        • Issues Report
        • HTML Report
        • Missing Objects Report
        • Object References Report
        • Elements Report
    • How to Use SnowConvert with Docker
  • User Guide (Beta)
    • User Guide
    • How to install the tool
      • Linux
      • Windows
      • MacOS
    • How to update the tool
    • How to request an access code
    • What is a SnowConvert Project?
    • Supported Source Platforms
    • Assessment
      • Analyzing subfolders
    • Conversion
      • Converting subfolders
      • General Conversion Settings
      • Teradata Conversion Settings
      • Oracle Conversion Settings
      • SQL Server Conversion Settings
    • How to use the SnowConvert CLI
    • Additional Parameters
      • SnowConvert for SQL
      • Spark SnowConvert
    • Command Line Interface
  • FOR SQL LANGUAGES (BETA)
    • Release Notes
      • 2024
      • 2023
    • General Issues and Troubleshooting
  • General (Legacy)
    • Getting Started
      • Download and Access
      • Installation and Licensing
      • End User License Agreement
    • Contact Us
  • Function Reference
    • Teradata
      • CHAR2HEXINT_UDF
      • CHCKNUM_UDF
      • DATEADD_UDF
      • TIMESTAMP_DIFFERENCE_UDF
      • EXTRACT_TIMESTAMP_DIFFERENCE_UDF
      • TIME_DIFFERENCE_UDF
      • DATE_TO_INT_UDF
      • INT_TO_DATE_UDF
      • FIRST_DAY_OF_MONTH_ISO_UDF
      • DAYNUMBER_OF_MONTH_UDF
      • DAYNUMBER_OF_YEAR_UDF
      • COMPUTE_EXPAND_ON_UDF
      • EXPAND_ON_UDF
      • DIFFTTIME_PERIOD_UDF
      • ROW_COUNT_UDF
      • GETQUERYBANDVALUE_UDF
      • GETQUERYBANDVALUE_UDF
      • INSTR_UDF
      • INSTR_UDF
      • INSTR_UDF
      • INTERVAL_MULTIPLY_UDF
      • INTERVAL_ADD_UDF
      • INTERVAL_TO_MONTHS_UDF
      • INTERVAL_TO_SECONDS_UDF
      • JSON_EXTRACT_DOT_NOTATION_UDF
      • JSON_EXTRACT_UDF
      • JULIAN_TO_DATE_UDF
      • MONTHS_BETWEEN_UDF
      • NULLIFZERO_UDF
      • NVP_UDF
      • PERIOD_INTERSECT_UDF
      • PERIOD_OVERLAPS_UDF
      • QUARTERNUMBER_OF_YEAR_UDF
      • ROUND_DATE_UDF
      • SUBSTR_UDF
      • SUBSTR_UDF
      • TD_DAY_OF_CALENDAR_UDF
      • TD_DAY_OF_WEEK_UDF
      • TD_DAY_OF_WEEK_COMPATIBLE_UDF
      • TD_WEEK_OF_YEAR_UDF
      • TD_DAY_OF_WEEK_COMPATIBLE_UDF
      • FIRST_DAY_JANUARY_OF_ISO_UDF
      • YEAR_BEGIN_ISO_UDF
      • TD_YEAR_BEGIN_UDF
      • LAST_DAY_DECEMBER_OF_ISO_UDF
      • YEAR_END_ISO_UDF
      • TD_YEAR_END_UDF
      • TIMESTAMP_ADD_UDF
      • DAY_OF_WEEK_LONG_UDF
      • MONTH_NAME_LONG_UDF
      • TO_BYTES_HEX_UDF
      • CENTURY_UDF
      • DAYNAME_LONG_UDF
      • DAYNAME_LONG_UDF
      • DATE_LONG_UDF
      • FULL_MONTH_NAME_UDF
      • ISO_YEAR_PART_UDF
      • JULIAN_DAY_UDF
      • MONTH_SHORT_UDF
      • ROMAN_NUMERALS_MONTH_UDF
      • SECONDS_PAST_MIDNIGHT_UDF
      • WEEK_OF_MONTH_UDF
      • YEAR_PART_UDF
      • YEAR_WITH_COMMA_UDF
      • INSERT_CURRENCY_UDF
      • WRAP_NEGATIVE_WITH_ANGLE_BRACKETS_UDF
      • TRANSLATE_CHK_UDF
      • WEEK_NUMBER_OF_QUARTER_COMPATIBLE_UDF
      • WEEK_NUMBER_OF_QUARTER_ISO_UDF
      • WEEK_NUMBER_OF_QUARTER_COMPATIBLE_UDF
      • WEEKNUMBER_OF_MONTH_UDF
  • For Teradata
    • Introduction
    • Getting Started (LEGACY)
      • Training and Support
      • Code Extraction
      • Using SnowConvert
      • Review Results
        • Assessment.csv Report
        • Assessment.docx Report
        • Elements Report
        • Issues Report
        • Lineage Report
        • Output code
        • TopLevelObjects Report
    • Command Line Interface
      • Renaming feature
    • Code Extraction
    • Processing the code
      • Preprocess tasks
    • SQL Translation Reference
    • Issues and Troubleshooting
      • General Issues
      • MSCEWI2001
      • MSCEWI2002
      • MSCEWI2003
      • MSCEWI2004
      • MSCEWI2005
      • MSCEWI2006
      • MSCEWI2007
      • MSCEWI2008
      • MSCEWI2009
      • MSCEWI2010
      • MSCEWI2011
      • MSCEWI2012
      • MSCEWI2013
      • MSCEWI2014
      • MSCEWI2015
      • MSCEWI2016
      • MSCEWI2017
      • MSCEWI2018
      • MSCEWI2019
      • MSCEWI2020
      • MSCEWI2021
      • MSCEWI2022
      • MSCEWI2023
      • MSCEWI2024
      • MSCEWI2025
      • MSCEWI2026
      • MSCEWI2027
      • MSCEWI2028
      • MSCEWI2029
      • MSCEWI2030
      • MSCEWI2031
      • MSCEWI2032
      • MSCEWI2033
      • MSCEWI2034
      • MSCEWI2035
      • MSCEWI2036
      • MSCEWI2037
      • MSCEWI2038
      • MSCEWI2039
      • MSCEWI2040
      • MSCEWI2041
      • MSCEWI2042
      • MSCEWI2043
      • MSCEWI2044
      • MSCEWI2045
      • MSCEWI2046
      • MSCEWI2047
      • MSCEWI2049
      • MSCEWI2050
      • MSCEWI2051
      • MSCEWI2052
      • MSCEWI2053
      • MSCEWI2054
      • MSCEWI2055
      • MSCEWI2056
      • MSCEWI2057
      • MSCEWI2058
      • MSCEWI2059
      • MSCEWI2060
      • MSCEWI2061
      • MSCEWI2062
      • MSCEWI2063
      • MSCEWI2064
      • MSCEWI2065
      • MSCEWI2066
      • MSCEWI2067
      • MSCEWI2068
      • MSCEWI2069
      • MSCEWI2070
      • MSCEWI2071
      • MSCEWI2072
      • MSCEWI2073
      • MSCEWI2074
      • MSCEWI2075
      • MSCEWI2076
      • MSCEWI2077
      • MSCEWI2078
      • MSCEWI2079
      • MSCEWI2080
      • MSCEWI2081
      • MSCEWI2082
      • MSCEWI2083
      • MSCEWI2084
      • MSCEWI2085
      • MSCEWI2086
      • MSCEWI2087
      • MSCEWI2088
      • MSCEWI2089
      • MSCEWI2090
      • MSCEWI2091
    • Release Notes
      • 2024
      • 2023
      • 2022
      • 2021
      • 2020
      • Roadmap
    • Considerations
  • For Oracle
    • Introduction
    • Getting Started (LEGACY)
      • Using SnowConvert
      • Review Results
        • Output Code
        • Assessment Report
        • Issues Report
        • Top-Level Objects Report
    • Command Line Interface
    • Code Extraction
    • Processing the code
      • Preprocess tasks
    • Issues and Troubleshooting
      • General Issues
      • MSCEWI3001
      • MSCEWI3002
      • MSCEWI3003
      • MSCEWI3004
      • MSCEWI3005
      • MSCEWI3006
      • MSCEWI3007
      • MSCEWI3008
      • MSCEWI3009
      • MSCEWI3010
      • MSCEWI3011
      • MSCEWI3012
      • MSCEWI3013
      • MSCEWI3014
      • MSCEWI3015
      • MSCEWI3016
      • MSCEWI3017
      • MSCEWI3018
      • MSCEWI3019
      • MSCEWI3020
      • MSCEWI3021
      • MSCEWI3022
      • MSCEWI3023
      • MSCEWI3024
      • MSCEWI3025
      • MSCEWI3026
      • MSCEWI3027
      • MSCEWI3028
      • MSCEWI3029
      • MSCEWI3030
      • MSCEWI3031
      • MSCEWI3032
      • MSCEWI3033
      • MSCEWI3034
      • MSCEWI3035
      • MSCEWI3036
      • MSCEWI3037
      • MSCEWI3038
      • MSCEWI3039
      • MSCEWI3040
      • MSCEWI3041
      • MSCEWI3042
      • MSCEWI3043
      • MSCEWI3044
      • MSCEWI3046
      • MSCEWI3047
      • MSCEWI3048
      • MSCEWI3049
      • MSCEWI3050
      • MSCEWI3051
      • MSCEWI3052
      • MSCEWI3053
      • MSCEWI3054
      • MSCEWI3055
      • MSCEWI3056
      • MSCEWI3057
      • MSCEWI3058
      • MSCEWI3059
      • MSCEWI3060
      • MSCEWI3061
      • MSCEWI3062
      • MSCEWI3063
      • MSCEWI3064
      • MSCEWI3065
      • MSCEWI3066
      • MSCEWI3067
      • MSCEWI3068
      • MSCEWI3069
      • MSCEWI3070
      • MSCEWI3071
      • MSCEWI3072
      • MSCEWI3073
      • MSCEWI3074
      • MSCEWI3075
      • MSCEWI3076
      • MSCEWI3077
      • MSCEWI3078
      • MSCEWI3079
      • MSCEWI3080
      • MSCEWI3081
      • MSCEWI3082
      • MSCEWI3083
      • MSCEWI3084
      • MSCEWI3085
      • MSCEWI3086
      • MSCEWI3087
      • MSCEWI3088
      • MSCEWI3089
      • MSCEWI3090
      • MSCEWI3091
      • MSCEWI3092
      • MSCEWI3093
      • MSCEWI3094
      • MSCEWI3095
      • MSCEWI3096
      • MSCEWI3097
      • MSCEWI3098
      • MSCEWI3099
      • MSCEWI3100
      • MSCEWI3101
      • MSCEWI3102
      • MSCEWI3103
      • MSCEWI3104
      • MSCEWI3105
      • MSCEWI3106
      • MSCEWI3107
      • MSCEWI3108
      • MSCEWI3109
      • MSCEWI3110
      • MSCEWI3111
      • MSCEWI3112
      • MSCEWI3113
      • MSCEWI3114
      • MSCEWI3115
      • MSCEWI3116
      • MSCEWI3117
      • MSCEWI3118
      • MSCEWI3119
      • MSCEWI3120
      • MSCEWI3121
      • MSCEWI3122
      • MSCEWI3123
      • MSCEWI3124
      • MSCEWI3125
      • MSCEWI3126
      • MSCEWI3127
      • MSCEWI3128
      • MSCEWI3129
      • MSCEWI3130
      • MSCEWI3131
      • MSCEWI3132
      • MSCEWI3133
      • MSCEWI3135
    • Release Notes
      • 2023
      • 2022
      • 2021
      • 2020
      • Roadmap
    • SQL Translation Reference
  • FOR SQL SERVER
    • Introduction
    • Getting Started (LEGACY)
      • Training and Support
      • Arrange the Source Code
      • Review Results
        • Output Code
        • Assessment Report
        • Issues Report
        • TopLevelObjects Report
      • Using SnowConvert
    • Command Line Interface
    • Code Extraction
    • Translation Reference
    • Issues and Troubleshooting
      • General Issues
      • MSCEWI4001
      • MSCEWI4002
      • MSCEWI4003
      • MSCEWI4004
      • MSCEWI4005
      • MSCEWI4006
      • MSCEWI4007
      • MSCEWI4008
      • MSCEWI4009
      • MSCEWI4010
      • MSCEWI4011
      • MSCEWI4012
      • MSCEWI4013
      • MSCEWI4014
      • MSCEWI4015
      • MSCEWI4016
      • MSCEWI4017
      • MSCEWI4018
      • MSCEWI4019
      • MSCEWI4020
      • MSCEWI4021
      • MSCEWI4022
      • MSCEWI4023
      • MSCEWI4024
      • MSCEWI4025
      • MSCEWI4026
      • MSCEWI4027
      • MSCEWI4028
      • MSCEWI4029
      • MSCEWI4030
      • MSCEWI4031
      • MSCEWI4032
      • MSCEWI4033
      • MSCEWI4034
      • MSCEWI4035
      • MSCEWI4036
      • MSCEWI4037
      • MSCEWI4038
      • MSCEWI4039
      • MSCEWI4040
      • MSCEWI4041
      • MSCEWI4042
      • MSCEWI4043
      • MSCEWI4044
      • MSCEWI4045
      • MSCEWI4046
      • MSCEWI4047
      • MSCEWI4048
      • MSCEWI4049
      • MSCEWI4050
      • MSCEWI4051
      • MSCEWI4052
      • MSCEWI4053
      • MSCEWI4054
      • MSCEWI4055
      • MSCEWI4056
      • MSCEWI4057
      • MSCEWI4058
      • MSCEWI4059
      • MSCEWI4060
      • MSCEWI4061
      • MSCEWI4062
      • MSCEWI4063
      • MSCEWI4064
      • MSCEWI4065
      • MSCEWI4066
      • MSCEWI4067
      • MSCEWI4068
      • MSCEWI4069
      • MSCEWI4070
      • MSCEWI4071
      • MSCEWI4072
      • MSCEWI4073
      • MSCEWI4074
      • MSCEWI4075
    • Release Notes
      • 2023
      • 2022
      • 2021
      • Roadmap
  • For IBM DB2
    • Introduction
    • Getting Started (LEGACY)
      • Using SnowConvert
      • Review Results
        • Output
        • Reports
    • Command Line Interface
    • Translation Reference
    • Issues and Troubleshooting
      • MSCEWI5001
      • MSCEWI5002
      • MSCEWI5003
      • MSCEWI5004
      • MSCEWI5005
      • MSCEWI5006
      • MSCEWI5007
      • MSCEWI5008
      • MSCEWI5009
      • MSCEWI5010
      • MSCEWI5011
      • MSCEWI5012
      • MSCEWI5013
      • MSCEWI5014
      • MSCEWI5015
      • MSCEWI5016
      • MSCEWI5017
      • MSCEWI5018
      • MSCEWI5019
      • MSCEWI5020
      • MSCEWI5021
      • MSCEWI5022
    • Release Notes
      • 2022
  • For PostgreSQL
    • Introduction
    • Getting Started (LEGACY)
      • Using SnowConvert
      • Review Results
        • Output
        • Reports
    • Command Line Interface
    • Translation Reference
    • Issues and Troubleshooting
      • MSC-PG0000
      • MSC-PG0001
      • MSC-PG0002
      • MSC-PG0003
      • MSC-PG0004
      • MSC-PG0005
      • MSC-PG0006
      • MSC-PG0007
      • MSC-PG0008
      • MSC-PG0009
      • MSC-PG0010
      • MSC-PG0011
      • MSC-PG0012
      • MSC-PG0013
      • MSC-PG0014
      • MSC-PG0015
      • MSC-PG0016
      • MSC-PG0017
      • MSC-PG0018
      • MSC-PG0019
      • MSC-PG0020
      • MSC-PG0021
      • MSC-PG0022
      • MSC-PG0023
      • MSC-PG0024
      • MSC-PG0025
      • MSC-PG0026
      • MSC-PG0027
      • MSC-PG0028
    • Release Notes
      • 2022
  • For Greenplum
    • Introduction
    • Getting Started (LEGACY)
      • Using SnowConvert
      • Review Results
        • Output
        • Reports
    • Command Line Interface
    • Translation Reference
    • Issues and Troubleshooting
      • MSC-GP0000
      • MSC-GP0001
      • MSC-GP0002
      • MSC-GP0003
    • Release Notes
      • 2022
  • For Amazon RedShift
    • Introduction
    • Getting Started (LEGACY)
      • Using SnowConvert
      • Review Results
        • Output
        • Reports
    • Command Line Interface
    • Translation Reference
    • Issues and Troubleshooting
      • MSC-RS0004
      • MSC-RS0005
      • MSC-RS0011
      • MSC-RS0012
      • MSC-RS0013
      • MSC-RS0014
    • Release Notes
      • 2022
  • For Google BigQuery
    • Introduction
    • Getting Started (LEGACY)
      • Using SnowConvert
      • Review Results
        • Output
        • Reports
    • Command Line Interface
    • Translation Reference
    • Issues and Troubleshooting
      • General Issues
      • MSC-BQ0001
      • MSC-BQ0002
      • MSC-BQ0003
      • MSC-BQ0004
      • MSC-BQ0005
      • MSC-BQ0006
      • MSC-BQ0007
      • MSC-BQ0008
      • MSC-BQ0009
      • MSC-BQ0010
      • MSC-BQ0011
      • MSC-BQ0012
      • MSC-BQ0013
      • MSC-BQ0014
      • MSC-BQ0015
      • MSC-BQ0016
    • Release Notes
      • 2022
  • For Apache Hive
    • Introduction
    • Getting Started (LEGACY)
      • Using SnowConvert
      • Review Results
        • Output
        • Reports
    • Command Line Interface
    • Translation Reference
    • Issues and Troubleshooting
    • Release Notes
      • 2022
  • For Vertica
    • Introduction
    • Getting Started (LEGACY)
      • Using SnowConvert
      • Review Results
        • Output
        • Reports
    • Command Line Interface
    • Translation Reference
    • Issues and Troubleshooting
    • Release Notes
      • 2022
  • for Spark (Scala)
    • Snowpark Migration Accelerator for Spark Scala
  • FOR SPARK (PYTHON)
    • Snowpark Migration Accelerator for PySpark
  • Databricks workloads
    • Getting started
      • DBC files explode
Powered by GitBook
On this page
  • Severity
  • Description
  • Code examples
  • Recommendations
  1. General (Beta)
  2. General Issues and Troubleshooting
  3. Complex Pattern Issues

MSCCP0010

The statement below has usages of nested cursors

PreviousMSCCP0009NextMSCCP0011

Last updated 1 year ago

This is a deprecated version of the SnowConvert documentation, please visit the official site .

Severity

Low

Description

This warning is used to indicate that the statement has usages of nested cursors. A cursor is a database object that allows traversing and manipulating result sets in a database. When nested cursors are used, it means that one cursor is nested inside the loop of another cursor.

The use of nested cursors can have a significant impact on performance, especially with large result sets. Each cursor operation requires a round trip to the database server, which can increase overhead and slow down execution.

Code examples

SQL Server

CREATE OR ALTER PROCEDURE procedureSample
AS
BEGIN
  DECLARE
    @outer_category_id INT,
    @outer_category_name NVARCHAR(50),
    @inner_product_name NVARCHAR(50);

  -- Define the outer cursor
  DECLARE outer_cursor CURSOR FOR 
    SELECT category_id, category_name FROM categories;

  -- Open the outer cursor
  OPEN @outer_cursor;

  -- Fetch the first row from the outer cursor
  FETCH NEXT FROM outer_cursor INTO @outer_category_id, @outer_category_name;

  -- Start the outer loop
  WHILE @@FETCH_STATUS = 0
  BEGIN

    PRINT 'Category: ' + @outer_category_name;
	
    -- Define the inner cursor
    DECLARE inner_cursor CURSOR FOR
      SELECT product_name FROM products WHERE category_id = @outer_category_id;
    
    -- Open the inner cursor
    OPEN inner_cursor;
	FETCH NEXT FROM inner_cursor INTO @inner_product_name;

    WHILE @@FETCH_STATUS = 0
    BEGIN
      PRINT 'Product: ' + @inner_product_name + ' Category: ' + CAST(@outer_category_id AS NVARCHAR(10));

      -- Fetch the next row from the inner cursor
      FETCH NEXT FROM inner_cursor INTO @inner_product_name;
    END;

    -- Close the inner cursor
    CLOSE inner_cursor;
    DEALLOCATE inner_cursor;

    -- Fetch the next row from the outer cursor
    FETCH NEXT FROM outer_cursor INTO @outer_category_id, @outer_category_name;
  END;

  -- Close the outer cursor
  CLOSE outer_cursor;
  DEALLOCATE outer_cursor;
  
END;
CREATE OR REPLACE PROCEDURE procedureSample ()
RETURNS VARCHAR
LANGUAGE SQL
EXECUTE AS CALLER
AS
$$
  DECLARE
    OUTER_CATEGORY_ID INT;
    OUTER_CATEGORY_NAME VARCHAR(50);
    INNER_PRODUCT_NAME VARCHAR(50);
    /*** MSC-ERROR - MSCEWI4038 - SNOWFLAKE SCRIPTING CURSOR ROWS ARE NOT MODIFIABLE ***/
    outer_cursor CURSOR
    FOR
      SELECT
        category_id,
        category_name
      FROM
        categories;
    /*** MSC-ERROR - MSCEWI4038 - SNOWFLAKE SCRIPTING CURSOR ROWS ARE NOT MODIFIABLE ***/
    inner_cursor CURSOR
    FOR
      SELECT
        product_name
      FROM
        products
      WHERE
        category_id = :OUTER_CATEGORY_ID;
  BEGIN
     
     
    --** MSC-WARNING - MSCCP0010 - THIS STATEMENT HAS USAGES OF NESTED CURSORS. **
    OPEN OUTER_CURSOR;
    FETCH
      outer_cursor
      INTO
      :OUTER_CATEGORY_ID,
      :OUTER_CATEGORY_NAME;
      WHILE (:FETCH_STATUS = 0) LOOP
-- ** MSC-ERROR - MSCEWI1037 - TRANSLATION FOR PRINT IS PLANNED TO BE DELIVERED IN THE FUTURE **
--      PRINT 'Category: ' + @outer_category_name;
       
      OPEN inner_cursor;
      --** MSC-WARNING - MSCCP0006 - FETCH INSIDE A LOOP IS CONSIDERED A COMPLEX PATTERN, THIS COULD DEGRADE SNOWFLAKE PERFORMANCE. **
      FETCH
        inner_cursor
      INTO
        :INNER_PRODUCT_NAME;
      WHILE (:FETCH_STATUS = 0) LOOP
-- ** MSC-ERROR - MSCEWI1037 - TRANSLATION FOR PRINT IS PLANNED TO BE DELIVERED IN THE FUTURE **
--        PRINT 'Product: ' + @inner_product_name + ' Category: ' + CAST(@outer_category_id AS NVARCHAR(10));
        --** MSC-WARNING - MSCCP0006 - FETCH INSIDE A LOOP IS CONSIDERED A COMPLEX PATTERN, THIS COULD DEGRADE SNOWFLAKE PERFORMANCE. **
        FETCH
          inner_cursor
        INTO
          :INNER_PRODUCT_NAME;
      END LOOP;
      CLOSE inner_cursor;
-- ** MSC-ERROR - MSCEWI1058 - FUNCTIONALITY FOR 'DEALLOCATE' IS NOT CURRENTLY SUPPORTED BY SNOWFLAKE SCRIPTING **
--      DEALLOCATE inner_cursor
                             ;
      --** MSC-WARNING - MSCCP0006 - FETCH INSIDE A LOOP IS CONSIDERED A COMPLEX PATTERN, THIS COULD DEGRADE SNOWFLAKE PERFORMANCE. **
      FETCH
        outer_cursor
      INTO
        :OUTER_CATEGORY_ID,
        :OUTER_CATEGORY_NAME;
      END LOOP;
      CLOSE outer_cursor;
-- ** MSC-ERROR - MSCEWI1058 - FUNCTIONALITY FOR 'DEALLOCATE' IS NOT CURRENTLY SUPPORTED BY SNOWFLAKE SCRIPTING **
--      DEALLOCATE outer_cursor                             ;
  END;
$$;

Oracle

Explicit cursor

CREATE OR REPLACE PROCEDURE procedureSample AS
BEGIN
DECLARE
  CURSOR outer_cursor IS
    SELECT category_id, category_name FROM categories;

  CURSOR inner_cursor (p_category_id NUMBER) IS
    SELECT product_name FROM products WHERE category_id = p_category_id;

  outer_category_id categories.category_id%TYPE;
  outer_category_name categories.category_name%TYPE;
  inner_product_name products.product_name%TYPE;
BEGIN

  OPEN outer_cursor;
  FETCH outer_cursor INTO outer_category_id, outer_category_name;

  LOOP
    EXIT WHEN outer_cursor%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE('Category: ' || outer_category_name);

    OPEN inner_cursor(outer_category_id);
    LOOP
        FETCH inner_cursor INTO inner_product_name;
        EXIT WHEN inner_cursor%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE('Product: ' || inner_product_name || ' Category: ' || outer_category_id);
    END LOOP;
    CLOSE inner_cursor;

    FETCH outer_cursor INTO outer_category_id, outer_category_name;
  END LOOP;

  CLOSE outer_cursor;
END;
END;
CREATE OR REPLACE PROCEDURE procedureSample ()
RETURNS VARCHAR
LANGUAGE SQL
EXECUTE AS CALLER
AS
$$
  BEGIN
    DECLARE
      outer_cursor CURSOR
      FOR
        SELECT category_id, category_name FROM
          categories;
      inner_cursor CURSOR
      FOR
        SELECT product_name FROM
          products
        WHERE category_id = ?;
      outer_category_id VARIANT /*** MSC-WARNING - MSCEWI3129 - TYPE ATTRIBUTE 'categories.category_id%TYPE' COULD NOT BE RESOLVED, SO IT WAS TRANSFORMED TO VARIANT ***/;
      outer_category_name VARIANT /*** MSC-WARNING - MSCEWI3129 - TYPE ATTRIBUTE 'categories.category_name%TYPE' COULD NOT BE RESOLVED, SO IT WAS TRANSFORMED TO VARIANT ***/;
      inner_product_name VARIANT /*** MSC-WARNING - MSCEWI3129 - TYPE ATTRIBUTE 'products.PRODUCT_NAME%TYPE' COULD NOT BE RESOLVED, SO IT WAS TRANSFORMED TO VARIANT ***/;
    BEGIN
      --** MSC-WARNING - MSCCP0010 - THIS STATEMENT HAS USAGES OF NESTED CURSORS. **
      OPEN outer_cursor USING ('DEFAULT VALUE NOT FOUND');
      FETCH outer_cursor INTO
        :outer_category_id,
        :outer_category_name;
      LOOP
        IF (outer_category_id IS NULL) THEN
          EXIT;
        END IF;
        /*** MSC-WARNING - MSCEWI1020 - CUSTOM UDF 'DBMS_OUTPUT.PUT_LINE' INSERTED. ***/
        /*** MSC-WARNING - MSCEWI3115 - CHECK UDF IMPLEMENTATION FOR DBMS_OUTPUT.PUT_LINE. ***/
        CALL DBMS_OUTPUT.PUT_LINE('Category: ' || NVL(:outer_category_name :: STRING, ''));
        OPEN inner_cursor USING (:outer_category_id);
        LOOP
          --** MSC-WARNING - MSCCP0006 - FETCH INSIDE A LOOP IS CONSIDERED A COMPLEX PATTERN, THIS COULD DEGRADE SNOWFLAKE PERFORMANCE. **
          FETCH inner_cursor INTO
            :inner_product_name;
          IF (inner_product_name IS NULL) THEN
            EXIT;
          END IF;
          /*** MSC-WARNING - MSCEWI1020 - CUSTOM UDF 'DBMS_OUTPUT.PUT_LINE' INSERTED. ***/
          /*** MSC-WARNING - MSCEWI3115 - CHECK UDF IMPLEMENTATION FOR DBMS_OUTPUT.PUT_LINE. ***/
          CALL DBMS_OUTPUT.PUT_LINE('Product: ' || NVL(:inner_product_name :: STRING, '') || ' Category: ' || NVL(:outer_category_id :: STRING, ''));
        END LOOP;
        CLOSE inner_cursor;
        --** MSC-WARNING - MSCCP0006 - FETCH INSIDE A LOOP IS CONSIDERED A COMPLEX PATTERN, THIS COULD DEGRADE SNOWFLAKE PERFORMANCE. **
        FETCH outer_cursor INTO
          :outer_category_id,
          :outer_category_name;
      END LOOP;
      CLOSE outer_cursor;
    END;
  END;
$$;

Implicit Cursor

CREATE OR REPLACE PROCEDURE procedureSample AS
BEGIN
DECLARE
   inner_category_id categories.category_name%TYPE;
   inner_product_name products.product_name%TYPE;
   inner_cursor SYS_REFCURSOR;
BEGIN
   FOR outer_cursor IN (SELECT category_id, category_name FROM categories)
   LOOP
      OPEN inner_cursor
       FOR SELECT product_name, category_id FROM products WHERE category_id = outer_cursor.category_id;
      LOOP
         FETCH inner_cursor INTO inner_product_name, inner_category_id;
         EXIT WHEN inner_cursor%NOTFOUND;
         dbms_output.put_line( 'Category id: '|| outer_cursor.category_id);
         dbms_output.put_line('Product name: ' || inner_product_name);
      END LOOP;
      CLOSE inner_cursor;
   END LOOP;
END;
END;
CREATE OR REPLACE PROCEDURE procedureSample ()
RETURNS VARCHAR
LANGUAGE SQL
EXECUTE AS CALLER
AS
$$
  BEGIN
    DECLARE
       inner_category_id VARIANT /*** MSC-WARNING - MSCEWI3129 - TYPE ATTRIBUTE 'categories.category_name%TYPE' COULD NOT BE RESOLVED, SO IT WAS TRANSFORMED TO VARIANT ***/;
       inner_product_name VARIANT /*** MSC-WARNING - MSCEWI3129 - TYPE ATTRIBUTE 'products.PRODUCT_NAME%TYPE' COULD NOT BE RESOLVED, SO IT WAS TRANSFORMED TO VARIANT ***/;
      inner_cursor_res RESULTSET /*** MSC-WARNING - MSCEWI1036 - SYS_REFCURSOR DATA TYPE CONVERTED TO RESULTSET ***/;
    BEGIN
      LET temporary_for_cursor_0 CURSOR
      FOR
        (SELECT category_id, category_name FROM
            categories
        );
      --** MSC-WARNING - MSCCP0010 - THIS STATEMENT HAS USAGES OF NESTED CURSORS. **
      /*** MSC-WARNING - MSCCP0003 - THIS STATEMENT HAS USAGES OF CURSOR FOR LOOP ***/
      FOR outer_cursor IN temporary_for_cursor_0 DO
        LET inner_cursor CURSOR
        FOR
          SELECT product_name, category_id FROM
            products
          WHERE category_id = outer_cursor.category_id;
        OPEN inner_cursor;
        LOOP
          --** MSC-WARNING - MSCCP0006 - FETCH INSIDE A LOOP IS CONSIDERED A COMPLEX PATTERN, THIS COULD DEGRADE SNOWFLAKE PERFORMANCE. **
          FETCH inner_cursor INTO
            :inner_product_name,
            :inner_category_id;
          IF (inner_product_name IS NULL) THEN
            EXIT;
          END IF;
          /*** MSC-WARNING - MSCEWI1020 - CUSTOM UDF 'DBMS_OUTPUT.PUT_LINE' INSERTED. ***/
          /*** MSC-WARNING - MSCEWI3115 - CHECK UDF IMPLEMENTATION FOR DBMS_OUTPUT.PUT_LINE. ***/
          CALL DBMS_OUTPUT.PUT_LINE( 'Category id: ' || NVL(outer_cursor.category_id :: STRING, ''));
          /*** MSC-WARNING - MSCEWI1020 - CUSTOM UDF 'DBMS_OUTPUT.PUT_LINE' INSERTED. ***/
          /*** MSC-WARNING - MSCEWI3115 - CHECK UDF IMPLEMENTATION FOR DBMS_OUTPUT.PUT_LINE. ***/
          CALL DBMS_OUTPUT.PUT_LINE('Product name: ' || NVL(:inner_product_name :: STRING, ''));
        END LOOP;
             CLOSE inner_cursor;
      END FOR;
    END;
  END;
$$;

Recommendations

  • Avoid them whenever possible due to their potential impact on performance and code complexity.

  • Remove the use of nested cursors, instead, you can use SQL functions, joins, subqueries, window functions, common table expressions (CTEs), recursive queries, and other features to process bulk data and avoid the need for nested cursors.

If you need more support, you can email us at

HERE
snowconvert-support@snowflake.com