SlideShare ist ein Scribd-Unternehmen logo
1 von 51
Procedural SQL data types
RDBMS
 Relational Database Management System

 For defining a fully relational database

    Dr. E. F. Codd's 12 rules is used.

 Codd's twelve rules are a set of thirteen rules (numbered zero

  to twelve) proposed by Edgar F. Codd, a pioneer of the
  relational model for databases.

 Codd’s Rule Designed to define what is required from a database

  management system in order for it to be considered relational.
Dr. E.F. Codd's 12 Rule
 Rule 0 : Foundation Rule
    For a system to qualify as a relational database management system

     (RDBMS), that system must use its relational facilities (exclusively)
     to manage the database.

 Rule 1: The Information Rule
    All data should be presented to the user in table form.

● Rule 2: Guaranteed Access Rule

    All data should be accessible without ambiguity.

    This can be achieved through a combination of the table name,

     primary key, and column name.
● Rule 3: Systematic Treatment of Null Values

    A field should be allowed to remain empty.

    This involves the support of a null value, which is distinct from an

     empty string or a number with a value of zero. Of course, this can't
     apply to primary keys.

● Rule 4: Active online catalog based on the relational model:

    The system must support an online, inline, relational catalog that is

     accessible to authorized users by means of their regular query
     language.

    That is, users must be able to access the database's structure

     (catalog) using the same query language that they use to access the
     database's data.
●   Rule 5: Comprehensive Data Sublanguage
     The database must support at least one clearly defined language

      that includes functionality for data definition, data manipulation,
      data integrity, and database transaction control.

     All commercial relational databases use forms of the standard SQL

      (Structured Query Language) as their supported comprehensive
      language.

     Supported Language :
         Data definition
         View definition
         Data manipulation (interactive and by program)
         Integrity constraints
         Authorization
         Transaction boundaries (begin, commit, and rollback).
 Rule 6: View Updating Rule
    View : Data can be presented to the user in different logical

     combinations, called views.

    Each view should support the same full range of data manipulation that

     direct-access to a table has available.

 Rule 7: High-level Insert, Update, and Delete

   The system must support set-at-a-time insert, update, and delete

    operators.

   This means that data can be retrieved from a relational database in sets

    constructed of data from multiple rows and/or multiple tables.
   This rule states that insert, update, and delete operations should be supported for

    any retrievable set rather than just for a single row in a single table.
 Rule 8: Physical Data Independence
    Changes to the physical level (how the data is stored, whether in

     arrays or linked lists etc.) must not require a change to an application
     based on the structure.

    Rule 9: Logical Data Independence

    Changes to the logical level (tables, columns, rows, and so on) must

     not require a change to an application based on the structure.

    Logical data independence is more difficult to achieve than physical

     data independence
 Rule 10: Integrity Independence
    Integrity constraints must be specified separately from application

     programs and stored in the structure/catalog.

    It must be possible to change such constraints as and when

     appropriate without unnecessarily affecting existing applications.

    No component of a primary key can have a null value. (see rule 3)

     If a foreign key is defined in one table, any value in it must exist as a
     primary key in another table.
 Rule 11: Distribution Independence
   A user should be totally unaware of whether or not the database is
    distributed (whether parts of the database exist in multiple locations).

   A variety of reasons make this rule difficult to implement;

 Rule 12: Nonsubversion Rule

   If a relational system has or supports a low-level (single-record-at-a-
    time) language, that low-level language cannot be used to subvert or
    bypass the integrity rules or constraints expressed in the higher-level
    (multiple-records-at-a-time) relational language.
SQL PL
 SQL PL stands for SQL procedural language with extension SQL.

 The SQL Procedural Language (SQL PL) is a language that
  consists of statements and language elements that can be used to
  implement procedural logic in SQL statements.
 SQL PL provides

      Statements for declaring variables

      Condition handlers

      Assigning values to variables

      For implementing procedural logic.
Datatypes
 The following new data types are available in SQL PL:

   Anchored datatype

   Row datatype

   Boolean datatype

   Associative array datatype

   Cursor datatype
Anchored Datatype
 An anchored data type is a data type that is defined to be the same as
  that of another object.
 If the underlying object data type changes, the anchored data type also
  changes.

 An anchored type defines a data type based on another SQL object
  such as a
    Column

    Global variable,

    SQL variable,

    SQL parameter,

    Row of a table or view.
Anchored Datatype
 A data type defined using an anchored type definition maintains
  a dependency on the object to which it is anchored.

 These clauses are supported within the following statements:
     DECLARE

     CREATE TYPE

     CREATE VARIABLE
DECLARE
 Syntax :
     DECLARE Var_Name ANCHOR DATA TYPE TO Object_Name

 Formulate a DECLARE statement

    Specify the name of the variable.

    Specify the ANCHOR DATA TYPE TO clause.

    Specify the name of the object that is of the data type that the

     variable is to be anchored.

 E.g. DECLARE v1 ANCHOR DATA TYPE TO emp.c1;
CREATE TYPE
 The following is an example of a CREATE TYPE statement that
  defines a type named empRow1 that is anchored to a row defined
  in a table named employee:

 Example :

 CREATE TYPE empRow1 AS ROW ANCHOR DATA TYPE TO
  ROW OF employee;
CREATE VARIABLE
 The following is an example that demonstrates a declared variable that is
  anchored to the data type of a column in a table:
   CREATE TABLE tab1(col1 INT, col2 CHAR);
   INSERT INTO tab1 VALUES (1,2);
   INSERT INTO tab1 VALUES (3,4);
   CREATE TABLE tab2 (col1a INT, col2a CHAR);
      BEGIN
           DECLARE var1 ANCHOR tab1.col1;
                  SELECT col1 INTO var1 FROM tab1 WHERE col2 = 2;
                  INSERT INTO tab2 VALUES (var1, 'a');
      END;
 An anchored data type can be of the same type as one of:

     a row in a table

     a row in a view

     a cursor variable row definition

     a column in a table

     a column in a view

     a local variable, including a local cursor variable or row variable

     a global variable
Row Datatype
 This data type is a structure composed of multiple fields,
  each with its own name and data type, which can be used
  to store the column values of a row in a result set or other
  similarly formatted data.

 You must create this user-defined data type using the
  CREATE TYPE statement before you can reference it.
Row Datatype
 You can use this data type for the following tasks:

    Creating or declaring of variables of type row that can be

     used to store row data.

    Passing row values as parameters to other SQL routines.

    Storing multiple SQL data type values as a single set.

    Referencing row data in data change statements and

     queries, including INSERT, FETCH, and SELECT INTO.
Creating row variables
 To create row variables you must first create the row type and then
  declare the row variable.

 The following topics show you how to create the row data type and
  variable:

 Creating a row data type

    Creating a row data type is a prerequisite to creating a row variable.

 Declaring local variables of type row

    Variables of type row can be declared once the row data type has

     been created.
Creating Row Datatype
 Formulate a CREATE TYPE (ROW) statement:

    Specify a name for the type.

    Specify the row field definition for the row by specifying a name

     and data type for each field in the row.
CREATE TYPE name AS ROW(field1 Datatype(size),field2 Datatype(size));

 The following is an example of how to create a row data type that can
  be associated with result sets with the same format as the empRow row
  data type:

    CREATE TYPE empRow AS ROW (name VARCHAR(128), id

     VARCHAR(8));
Declaring local variable
 Formulate a declare statement:

    Specify a name for the variable.

    Specify the row data type that will define the variable.

    The specified row data type must be already defined in the
     database.
   DECLARE var_name rowName;
 The following is an example of how to formulate a DECLARE
  statement that defines a row variable of type empRow:
    DECLARE r1 empRow;
Examples: Row data type use
 Examples of row data type use provide a useful reference for
  understanding how and when to use the row data type.

 The following topics demonstrate how to use the row data type:

 Example: Row data type use in a CLP script
  Some basic features of row data types are shown within a DB2® CLP
  script to demonstrate how row data types are most commonly used.

 Example: Row data type use in an SQL procedure
  The row data type can be used in SQL procedures to retrieve record
  data and pass it as a parameter.
Ordinary Array
 An ordinary array data type is a structure that contains an
  ordered collection of data elements in which each element can
  be referenced by its ordinal position in the collection.

 If N is the cardinality (number of elements) in an array.

 The ordinal position associated with each element, called the
  index, is an integer value greater than or equal to 1 and less than
  or equal to N.

 All elements in an array have the same data type.
Array variables
 Array variables are variables based on user-defined array data types.

 Array variables can be

    Declared

    Assigned a value

    Set to another value

    Passed as a parameter to and from SQL procedures.

 Local array variables can be declared within SQL procedures using the
  DECLARE statement.
 Global array variables can be created using the CREATE VARIABLE
  statement.
Creating array variables
 To create array variables you must first create the array type and then
  declare the local array variable or create the global array variable.
 How to create array data types and array variables:

    Creating an array data type (CREATE TYPE statement)

         Creating an array data type is a task that you would perform as a
          prerequisite to creating a variable of the array data type.
    Declaring local variables of type array

         Declaring array data type variables is a task that you perform after
          creating array data types if you want to be able to temporarily
          store or pass array data type values.
Creating an array data type (CREATE TYPE statement)
 Syntax:

  CREATE TYPE array_name AS Datatype(size) ARRAY[upper bound]

 Define the CREATE TYPE statement

    Specify a name for the array data type.

    Specify the AS keyword followed by the keyword name for the data

     type of the array element. For example, INTEGER, VARCHAR.

    Specify the ARRAY keyword and the domain of the subindices in

     the array.
 Example :
     CREATE TYPE phone AS number(10) ARRAY[100];
Declare Variable
 Syntax:

  DECLARE Var_Name array_name
 Define the DECLARE statement.

    Specify a name for the array data type variable.

    Specify the name of the array data type that you used when
     you created the array data type.
Example

     CREATE TYPE name AS varchar(10) ARRAY[100];
    DECLARE emp_name name;
Assigning Value to array
  Syntax : SET array[index]=value
  Example :

    SET myArray[1] = 123;

    SET myArray[2] = 124;

    SET myArray[100] = 223;
Retrieving Value to array
 Retrieving array values using an index

   Syntax : SET value = array[index]
   Example : SET a = myArray[3];
 Count total Element

  Syntax :
  SET value = CARDINALITY/MAX_CARDINALITY(arrayName)
  Example :
  SET Count= CARDINALITY(myArray);
   SET count= MAX_CARDINALITY(myArray);
 Retrieving previous and next array values

  SET phone1= FIRST(phones);

  SET nextPhone = NEXT(phones, phone1);

 Delete array values

  SET name= ARRAY_DELETE ( name, 1, 2 );

 Determine if array element exist

        IF (ARRAY_EXISTS(phones, 2)) THEN

                  SET x = 1;

        END IF;
Cursor
 Cursors will be used in DB2 SQL PL stored procedures to
  perform a complex logic on a row-by-row basis.

 Cursors are special programming constructs that allow data
  to be manipulated on a row-by-row basis, similar to other
  structured programming languages.

 They are declared like a variable, and then move one
  record at a time using a loop for the control.
Content :
  Overview of cursor data types

  Cursor variables

  Cursor predicates/attributes

  Referencing cursor variables

  Determining the number of fetched rows for a cursor
Overview of cursor data types
 This overview of cursor data types introduces the

    Types of cursor data types

    The scope in which they can be used

    Provides information about the restrictions and

      privileges that pertain to their use.
Types of cursor data types
 There are two main types of cursor data types:

       Strongly -typed cursor data types .

       Weakly -typed cursor data types .

 The property of being strongly or weakly typed is defined
  when the data type is created.

 This property is maintained in variables created of each
  type.
Weakly-typed cursor data types
 A weakly typed cursor type is not associated with any row data type
  definition.
 No type checking is performed when values are assigned to weakly
  typed cursor variables.
 Syntax :
        DECLARE cur_name CURSOR for select statement ;
 Weakly typed cursor variables are useful when you must store a result
  set with an unknown row definition.
   Example:

   Decalre c1 cursor for select empno, salary from emp
     where salary<=5000
Strongly-typed cursor data types
 A strongly-typed cursor data type is one that is created with
  a result set definition specified by a row data structure.

 These data types are called strongly typed, because when
  result set values are assigned to them the data types of the
  result sets can be checked.

 Strong type checking is performed at assignment time and
  if there are any data type mismatches, an error is raised.
Strongly-typed cursor data types
 Syntax :

        CREATE TYPE cursorType AS rowType CURSOR

 Example:

   1) CREATE TYPE r1 AS ROW (C1 INT);

       CREATE TYPE k1 AS r1 CURSOR;
CREATE TYPE myRowType AS ROW (edlevel SMALLINT, name

VARCHAR(128));

CREATE TYPE myCursorType AS myRowType CURSOR;

BEGIN

      DECLARE rv1 myRowType;

     DECLARE c1 CURSOR;

     FETCH c1 INTO rv1;

      CLOSE c1;

 END ;
Overview of cursor data types
  2. The scope in which they can be used

       Restrictions on cursor data types and cursor variables limit cursor
        variable functionality as well as where cursor variables can be
        defined and referenced.

  3. Provides information about the restrictions and privileges

       To create cursor data types, you require the following privilege

       Privilege to execute the CREATE TYPE statement to create a
        cursor data type.

       To declare cursor variables based on existing cursor data types,
        no privileges are required.
Cursor variables
 Cursor variables are cursors based on predefined cursor data
  type.

 Cursor variables can be un-initialized, initialized, assigned a
  value, set to another value, or passed as a parameter from SQL
  procedures.

 Cursor variables can be strongly-typed or weakly-typed.

 Cursor variables can be declared within SQL procedures using
  the DECLARE statement.
Referencing cursor variables
 The following statements can be used to reference cursor
  variables within an SQL PL context:
   CALL

   SET

   OPEN

   FETCH

   CLOSE
 Call Statement:

    Cursor variables can also be referenced as parameters in the

     CALL statement.

    The following is an example of a CALL statement within an

     SQL procedure that references a cursor variable named curVar

     which is an output parameter:

       Example: CALL P2(curVar);

 Set Statement:

    Used to set value to curser variable.

       Example : SET c1 = CURSOR FOR SELECT * FROM T;
 The OPEN statement is used to initialize the result set associated
  with the cursor variable.
     Example : OPEN C1;

 The FETCH statement is used to specifically retrieve the column
  values in the current row being accessed by the cursor variable.
     Example : FETCH c1 into variable;

 The CLOSE statement is used to end the processing of the cursor
  variable.

    Example : closeC1;

       Code
Cursor predicates
 Cursor predicates are SQL keywords that can be used to
  determine the state of a cursor defined within the current scope.

 They provide a means for easily referencing whether a cursor is
  open, closed or if there are rows associated with the cursor.

 The cursor predicates that can be used include
    IS OPEN

    IS NOT OPEN

    IS FOUND

    IS NOT FOUND
 IS OPEN

   This predicate can be used to determine if the cursor is

    in an open state.

   This can be a useful predicate in cases where cursors are

    passed as parameters to functions and procedures.

   Before attempting to open the cursor, this predicate can

    be used to determine if the cursor is already open.
 IS NOT OPEN
   This predicate can be used to determine if the cursor is

    closed.

   Its value is the logical inverse of IS OPEN.

   This predicate can be useful to determine whether a

    cursor is closed before attempting to actually close the
    cursor.
 IS FOUND

   This predicate can be used to determine if the cursor contains

    rows after the execution of a FETCH statement.

   If the last FETCH statement executed was successful, the IS

    FOUND predicate value is true.

   If the last FETCH statement executed resulted in a condition

    where rows were not found, the result is false.

   The result is unknown when:

       the value of cursor-variable-name is null

       the underlying cursor of cursor-variable-name is not open

       the last FETCH action returned an error
BEGIN

        DECLARE C1 CURSOR FOR SELECT c1 FROM t1;

        IF (c1 IS NOT OPEN) THEN

                  OPEN c1;

        end if;

        IF (c1 IS OPEN) THEN

                  FETCH c1 into lvarInt;

                  WHILE (c1 IS FOUND) DO



                  END WHILE;

        END IF;
Determining the number of fetched
rows for a cursor
 Determining the number of rows associated with a cursor can be
  efficiently done by using the cursor_rowCount scalar function

 It takes a cursor variable as a parameter and returns an integer
  value as an output corresponding to the number of rows that
  have been fetched since the cursor was opened.
Determining the number of fetched rows for a cursor

 The following pre-requisites must be met before you use the

  cursor_rowCount function:

    A cursor data type must be created.

    A cursor variable of the cursor data type must be declared.

    An OPEN statement referencing the cursor must have been

     executed.

  Example : SET rows_fetched = CURSOR_ROWCOUNT(curEmp)

Weitere ähnliche Inhalte

Was ist angesagt? (19)

10g plsql slide
10g plsql slide10g plsql slide
10g plsql slide
 
Pl sql-ch1
Pl sql-ch1Pl sql-ch1
Pl sql-ch1
 
PL/SQL 3 DML
PL/SQL 3 DMLPL/SQL 3 DML
PL/SQL 3 DML
 
PL/SQL Part 1
PL/SQL Part 1PL/SQL Part 1
PL/SQL Part 1
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
Open Gurukul Language PL/SQL
Open Gurukul Language PL/SQLOpen Gurukul Language PL/SQL
Open Gurukul Language PL/SQL
 
Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
 
PL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics CoveredPL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics Covered
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
 
plsql les01
 plsql les01 plsql les01
plsql les01
 
4. plsql
4. plsql4. plsql
4. plsql
 
Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQL
 
Oracle etl openworld
Oracle etl openworldOracle etl openworld
Oracle etl openworld
 
PL/SQL CURSORES
PL/SQL CURSORESPL/SQL CURSORES
PL/SQL CURSORES
 
ORACLE PL/SQL
ORACLE PL/SQLORACLE PL/SQL
ORACLE PL/SQL
 
SQL
SQLSQL
SQL
 
PL/SQL CONDICIONALES Y CICLOS
PL/SQL CONDICIONALES Y CICLOSPL/SQL CONDICIONALES Y CICLOS
PL/SQL CONDICIONALES Y CICLOS
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 

Ähnlich wie SQL Procedural Data Types

Ähnlich wie SQL Procedural Data Types (20)

Presentation1
Presentation1Presentation1
Presentation1
 
Anchor data type,cursor data type,array data type
Anchor data type,cursor data type,array data typeAnchor data type,cursor data type,array data type
Anchor data type,cursor data type,array data type
 
T-SQL Overview
T-SQL OverviewT-SQL Overview
T-SQL Overview
 
RDBMS
RDBMSRDBMS
RDBMS
 
Fg d
Fg dFg d
Fg d
 
Bank mangement system
Bank mangement systemBank mangement system
Bank mangement system
 
Dbms important questions and answers
Dbms important questions and answersDbms important questions and answers
Dbms important questions and answers
 
Codds rules & keys
Codds rules & keysCodds rules & keys
Codds rules & keys
 
Oracle SQL Part1
Oracle SQL Part1Oracle SQL Part1
Oracle SQL Part1
 
chapter-14-sql-commands.pdf
chapter-14-sql-commands.pdfchapter-14-sql-commands.pdf
chapter-14-sql-commands.pdf
 
Relational Database Management System part II
Relational Database Management System part IIRelational Database Management System part II
Relational Database Management System part II
 
Oracle
OracleOracle
Oracle
 
Anchored data type
Anchored data typeAnchored data type
Anchored data type
 
Module02
Module02Module02
Module02
 
Data base
Data baseData base
Data base
 
SQL: Structured Query Language
SQL: Structured Query LanguageSQL: Structured Query Language
SQL: Structured Query Language
 
SQL ppt.pptx
SQL ppt.pptxSQL ppt.pptx
SQL ppt.pptx
 
12 SQL
12 SQL12 SQL
12 SQL
 
12 SQL
12 SQL12 SQL
12 SQL
 
Ankit
AnkitAnkit
Ankit
 

Mehr von Jay Patel

Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)Jay Patel
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)Jay Patel
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)Jay Patel
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)Jay Patel
 
Assignment 1(web)
Assignment 1(web)Assignment 1(web)
Assignment 1(web)Jay Patel
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)Jay Patel
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)Jay Patel
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)Jay Patel
 
Selection sort
Selection sortSelection sort
Selection sortJay Patel
 
Mutlimedia authoring tools
Mutlimedia authoring toolsMutlimedia authoring tools
Mutlimedia authoring toolsJay Patel
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software toolsJay Patel
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 textJay Patel
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 textJay Patel
 
Hypertext and hypermedia
Hypertext and hypermediaHypertext and hypermedia
Hypertext and hypermediaJay Patel
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software toolsJay Patel
 

Mehr von Jay Patel (20)

Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)
 
Quiz(web)
Quiz(web)Quiz(web)
Quiz(web)
 
Assignment 2(web)
Assignment 2(web)Assignment 2(web)
Assignment 2(web)
 
Assignment 1(web)
Assignment 1(web)Assignment 1(web)
Assignment 1(web)
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Inline function(oops)
Inline function(oops)Inline function(oops)
Inline function(oops)
 
1 unit (oops)
1 unit (oops)1 unit (oops)
1 unit (oops)
 
Cursor
CursorCursor
Cursor
 
Selection sort
Selection sortSelection sort
Selection sort
 
Mutlimedia authoring tools
Mutlimedia authoring toolsMutlimedia authoring tools
Mutlimedia authoring tools
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software tools
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
 
Sound
SoundSound
Sound
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
 
Images
ImagesImages
Images
 
Hypertext and hypermedia
Hypertext and hypermediaHypertext and hypermedia
Hypertext and hypermedia
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software tools
 
Cursor
CursorCursor
Cursor
 

Kürzlich hochgeladen

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 

Kürzlich hochgeladen (20)

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 

SQL Procedural Data Types

  • 2. RDBMS  Relational Database Management System  For defining a fully relational database  Dr. E. F. Codd's 12 rules is used.  Codd's twelve rules are a set of thirteen rules (numbered zero to twelve) proposed by Edgar F. Codd, a pioneer of the relational model for databases.  Codd’s Rule Designed to define what is required from a database management system in order for it to be considered relational.
  • 3. Dr. E.F. Codd's 12 Rule  Rule 0 : Foundation Rule  For a system to qualify as a relational database management system (RDBMS), that system must use its relational facilities (exclusively) to manage the database.  Rule 1: The Information Rule  All data should be presented to the user in table form. ● Rule 2: Guaranteed Access Rule  All data should be accessible without ambiguity.  This can be achieved through a combination of the table name, primary key, and column name.
  • 4. ● Rule 3: Systematic Treatment of Null Values  A field should be allowed to remain empty.  This involves the support of a null value, which is distinct from an empty string or a number with a value of zero. Of course, this can't apply to primary keys. ● Rule 4: Active online catalog based on the relational model:  The system must support an online, inline, relational catalog that is accessible to authorized users by means of their regular query language.  That is, users must be able to access the database's structure (catalog) using the same query language that they use to access the database's data.
  • 5. Rule 5: Comprehensive Data Sublanguage  The database must support at least one clearly defined language that includes functionality for data definition, data manipulation, data integrity, and database transaction control.  All commercial relational databases use forms of the standard SQL (Structured Query Language) as their supported comprehensive language.  Supported Language :  Data definition  View definition  Data manipulation (interactive and by program)  Integrity constraints  Authorization  Transaction boundaries (begin, commit, and rollback).
  • 6.  Rule 6: View Updating Rule  View : Data can be presented to the user in different logical combinations, called views.  Each view should support the same full range of data manipulation that direct-access to a table has available.  Rule 7: High-level Insert, Update, and Delete  The system must support set-at-a-time insert, update, and delete operators.  This means that data can be retrieved from a relational database in sets constructed of data from multiple rows and/or multiple tables.  This rule states that insert, update, and delete operations should be supported for any retrievable set rather than just for a single row in a single table.
  • 7.  Rule 8: Physical Data Independence  Changes to the physical level (how the data is stored, whether in arrays or linked lists etc.) must not require a change to an application based on the structure.  Rule 9: Logical Data Independence  Changes to the logical level (tables, columns, rows, and so on) must not require a change to an application based on the structure.  Logical data independence is more difficult to achieve than physical data independence
  • 8.  Rule 10: Integrity Independence  Integrity constraints must be specified separately from application programs and stored in the structure/catalog.  It must be possible to change such constraints as and when appropriate without unnecessarily affecting existing applications.  No component of a primary key can have a null value. (see rule 3) If a foreign key is defined in one table, any value in it must exist as a primary key in another table.
  • 9.  Rule 11: Distribution Independence  A user should be totally unaware of whether or not the database is distributed (whether parts of the database exist in multiple locations).  A variety of reasons make this rule difficult to implement;  Rule 12: Nonsubversion Rule  If a relational system has or supports a low-level (single-record-at-a- time) language, that low-level language cannot be used to subvert or bypass the integrity rules or constraints expressed in the higher-level (multiple-records-at-a-time) relational language.
  • 10. SQL PL  SQL PL stands for SQL procedural language with extension SQL.  The SQL Procedural Language (SQL PL) is a language that consists of statements and language elements that can be used to implement procedural logic in SQL statements.  SQL PL provides  Statements for declaring variables  Condition handlers  Assigning values to variables  For implementing procedural logic.
  • 11. Datatypes  The following new data types are available in SQL PL:  Anchored datatype  Row datatype  Boolean datatype  Associative array datatype  Cursor datatype
  • 12. Anchored Datatype  An anchored data type is a data type that is defined to be the same as that of another object.  If the underlying object data type changes, the anchored data type also changes.  An anchored type defines a data type based on another SQL object such as a  Column  Global variable,  SQL variable,  SQL parameter,  Row of a table or view.
  • 13. Anchored Datatype  A data type defined using an anchored type definition maintains a dependency on the object to which it is anchored.  These clauses are supported within the following statements:  DECLARE  CREATE TYPE  CREATE VARIABLE
  • 14. DECLARE  Syntax : DECLARE Var_Name ANCHOR DATA TYPE TO Object_Name  Formulate a DECLARE statement  Specify the name of the variable.  Specify the ANCHOR DATA TYPE TO clause.  Specify the name of the object that is of the data type that the variable is to be anchored.  E.g. DECLARE v1 ANCHOR DATA TYPE TO emp.c1;
  • 15. CREATE TYPE  The following is an example of a CREATE TYPE statement that defines a type named empRow1 that is anchored to a row defined in a table named employee:  Example :  CREATE TYPE empRow1 AS ROW ANCHOR DATA TYPE TO ROW OF employee;
  • 16. CREATE VARIABLE  The following is an example that demonstrates a declared variable that is anchored to the data type of a column in a table: CREATE TABLE tab1(col1 INT, col2 CHAR); INSERT INTO tab1 VALUES (1,2); INSERT INTO tab1 VALUES (3,4); CREATE TABLE tab2 (col1a INT, col2a CHAR); BEGIN DECLARE var1 ANCHOR tab1.col1; SELECT col1 INTO var1 FROM tab1 WHERE col2 = 2; INSERT INTO tab2 VALUES (var1, 'a'); END;
  • 17.  An anchored data type can be of the same type as one of:  a row in a table  a row in a view  a cursor variable row definition  a column in a table  a column in a view  a local variable, including a local cursor variable or row variable  a global variable
  • 18. Row Datatype  This data type is a structure composed of multiple fields, each with its own name and data type, which can be used to store the column values of a row in a result set or other similarly formatted data.  You must create this user-defined data type using the CREATE TYPE statement before you can reference it.
  • 19. Row Datatype  You can use this data type for the following tasks:  Creating or declaring of variables of type row that can be used to store row data.  Passing row values as parameters to other SQL routines.  Storing multiple SQL data type values as a single set.  Referencing row data in data change statements and queries, including INSERT, FETCH, and SELECT INTO.
  • 20. Creating row variables  To create row variables you must first create the row type and then declare the row variable.  The following topics show you how to create the row data type and variable:  Creating a row data type  Creating a row data type is a prerequisite to creating a row variable.  Declaring local variables of type row  Variables of type row can be declared once the row data type has been created.
  • 21. Creating Row Datatype  Formulate a CREATE TYPE (ROW) statement:  Specify a name for the type.  Specify the row field definition for the row by specifying a name and data type for each field in the row. CREATE TYPE name AS ROW(field1 Datatype(size),field2 Datatype(size));  The following is an example of how to create a row data type that can be associated with result sets with the same format as the empRow row data type:  CREATE TYPE empRow AS ROW (name VARCHAR(128), id VARCHAR(8));
  • 22. Declaring local variable  Formulate a declare statement:  Specify a name for the variable.  Specify the row data type that will define the variable.  The specified row data type must be already defined in the database. DECLARE var_name rowName;  The following is an example of how to formulate a DECLARE statement that defines a row variable of type empRow:  DECLARE r1 empRow;
  • 23. Examples: Row data type use  Examples of row data type use provide a useful reference for understanding how and when to use the row data type.  The following topics demonstrate how to use the row data type:  Example: Row data type use in a CLP script Some basic features of row data types are shown within a DB2® CLP script to demonstrate how row data types are most commonly used.  Example: Row data type use in an SQL procedure The row data type can be used in SQL procedures to retrieve record data and pass it as a parameter.
  • 24. Ordinary Array  An ordinary array data type is a structure that contains an ordered collection of data elements in which each element can be referenced by its ordinal position in the collection.  If N is the cardinality (number of elements) in an array.  The ordinal position associated with each element, called the index, is an integer value greater than or equal to 1 and less than or equal to N.  All elements in an array have the same data type.
  • 25. Array variables  Array variables are variables based on user-defined array data types.  Array variables can be  Declared  Assigned a value  Set to another value  Passed as a parameter to and from SQL procedures.  Local array variables can be declared within SQL procedures using the DECLARE statement.  Global array variables can be created using the CREATE VARIABLE statement.
  • 26. Creating array variables  To create array variables you must first create the array type and then declare the local array variable or create the global array variable.  How to create array data types and array variables:  Creating an array data type (CREATE TYPE statement)  Creating an array data type is a task that you would perform as a prerequisite to creating a variable of the array data type.  Declaring local variables of type array  Declaring array data type variables is a task that you perform after creating array data types if you want to be able to temporarily store or pass array data type values.
  • 27. Creating an array data type (CREATE TYPE statement)  Syntax: CREATE TYPE array_name AS Datatype(size) ARRAY[upper bound]  Define the CREATE TYPE statement  Specify a name for the array data type.  Specify the AS keyword followed by the keyword name for the data type of the array element. For example, INTEGER, VARCHAR.  Specify the ARRAY keyword and the domain of the subindices in the array.  Example : CREATE TYPE phone AS number(10) ARRAY[100];
  • 28. Declare Variable  Syntax: DECLARE Var_Name array_name  Define the DECLARE statement.  Specify a name for the array data type variable.  Specify the name of the array data type that you used when you created the array data type. Example CREATE TYPE name AS varchar(10) ARRAY[100]; DECLARE emp_name name;
  • 29. Assigning Value to array Syntax : SET array[index]=value Example : SET myArray[1] = 123; SET myArray[2] = 124; SET myArray[100] = 223;
  • 30. Retrieving Value to array  Retrieving array values using an index Syntax : SET value = array[index] Example : SET a = myArray[3];  Count total Element Syntax : SET value = CARDINALITY/MAX_CARDINALITY(arrayName) Example : SET Count= CARDINALITY(myArray); SET count= MAX_CARDINALITY(myArray);
  • 31.  Retrieving previous and next array values SET phone1= FIRST(phones); SET nextPhone = NEXT(phones, phone1);  Delete array values SET name= ARRAY_DELETE ( name, 1, 2 );  Determine if array element exist IF (ARRAY_EXISTS(phones, 2)) THEN SET x = 1; END IF;
  • 32. Cursor  Cursors will be used in DB2 SQL PL stored procedures to perform a complex logic on a row-by-row basis.  Cursors are special programming constructs that allow data to be manipulated on a row-by-row basis, similar to other structured programming languages.  They are declared like a variable, and then move one record at a time using a loop for the control.
  • 33. Content :  Overview of cursor data types  Cursor variables  Cursor predicates/attributes  Referencing cursor variables  Determining the number of fetched rows for a cursor
  • 34. Overview of cursor data types  This overview of cursor data types introduces the  Types of cursor data types  The scope in which they can be used  Provides information about the restrictions and privileges that pertain to their use.
  • 35. Types of cursor data types  There are two main types of cursor data types:  Strongly -typed cursor data types .  Weakly -typed cursor data types .  The property of being strongly or weakly typed is defined when the data type is created.  This property is maintained in variables created of each type.
  • 36. Weakly-typed cursor data types  A weakly typed cursor type is not associated with any row data type definition.  No type checking is performed when values are assigned to weakly typed cursor variables.  Syntax : DECLARE cur_name CURSOR for select statement ;  Weakly typed cursor variables are useful when you must store a result set with an unknown row definition. Example: Decalre c1 cursor for select empno, salary from emp where salary<=5000
  • 37. Strongly-typed cursor data types  A strongly-typed cursor data type is one that is created with a result set definition specified by a row data structure.  These data types are called strongly typed, because when result set values are assigned to them the data types of the result sets can be checked.  Strong type checking is performed at assignment time and if there are any data type mismatches, an error is raised.
  • 38. Strongly-typed cursor data types  Syntax : CREATE TYPE cursorType AS rowType CURSOR  Example: 1) CREATE TYPE r1 AS ROW (C1 INT); CREATE TYPE k1 AS r1 CURSOR;
  • 39. CREATE TYPE myRowType AS ROW (edlevel SMALLINT, name VARCHAR(128)); CREATE TYPE myCursorType AS myRowType CURSOR; BEGIN DECLARE rv1 myRowType; DECLARE c1 CURSOR; FETCH c1 INTO rv1; CLOSE c1; END ;
  • 40. Overview of cursor data types 2. The scope in which they can be used  Restrictions on cursor data types and cursor variables limit cursor variable functionality as well as where cursor variables can be defined and referenced. 3. Provides information about the restrictions and privileges  To create cursor data types, you require the following privilege  Privilege to execute the CREATE TYPE statement to create a cursor data type.  To declare cursor variables based on existing cursor data types, no privileges are required.
  • 41. Cursor variables  Cursor variables are cursors based on predefined cursor data type.  Cursor variables can be un-initialized, initialized, assigned a value, set to another value, or passed as a parameter from SQL procedures.  Cursor variables can be strongly-typed or weakly-typed.  Cursor variables can be declared within SQL procedures using the DECLARE statement.
  • 42. Referencing cursor variables  The following statements can be used to reference cursor variables within an SQL PL context:  CALL  SET  OPEN  FETCH  CLOSE
  • 43.  Call Statement:  Cursor variables can also be referenced as parameters in the CALL statement.  The following is an example of a CALL statement within an SQL procedure that references a cursor variable named curVar which is an output parameter: Example: CALL P2(curVar);  Set Statement:  Used to set value to curser variable. Example : SET c1 = CURSOR FOR SELECT * FROM T;
  • 44.  The OPEN statement is used to initialize the result set associated with the cursor variable. Example : OPEN C1;  The FETCH statement is used to specifically retrieve the column values in the current row being accessed by the cursor variable. Example : FETCH c1 into variable;  The CLOSE statement is used to end the processing of the cursor variable. Example : closeC1; Code
  • 45. Cursor predicates  Cursor predicates are SQL keywords that can be used to determine the state of a cursor defined within the current scope.  They provide a means for easily referencing whether a cursor is open, closed or if there are rows associated with the cursor.  The cursor predicates that can be used include  IS OPEN  IS NOT OPEN  IS FOUND  IS NOT FOUND
  • 46.  IS OPEN  This predicate can be used to determine if the cursor is in an open state.  This can be a useful predicate in cases where cursors are passed as parameters to functions and procedures.  Before attempting to open the cursor, this predicate can be used to determine if the cursor is already open.
  • 47.  IS NOT OPEN  This predicate can be used to determine if the cursor is closed.  Its value is the logical inverse of IS OPEN.  This predicate can be useful to determine whether a cursor is closed before attempting to actually close the cursor.
  • 48.  IS FOUND  This predicate can be used to determine if the cursor contains rows after the execution of a FETCH statement.  If the last FETCH statement executed was successful, the IS FOUND predicate value is true.  If the last FETCH statement executed resulted in a condition where rows were not found, the result is false.  The result is unknown when:  the value of cursor-variable-name is null  the underlying cursor of cursor-variable-name is not open  the last FETCH action returned an error
  • 49. BEGIN DECLARE C1 CURSOR FOR SELECT c1 FROM t1; IF (c1 IS NOT OPEN) THEN OPEN c1; end if; IF (c1 IS OPEN) THEN FETCH c1 into lvarInt; WHILE (c1 IS FOUND) DO END WHILE; END IF;
  • 50. Determining the number of fetched rows for a cursor  Determining the number of rows associated with a cursor can be efficiently done by using the cursor_rowCount scalar function  It takes a cursor variable as a parameter and returns an integer value as an output corresponding to the number of rows that have been fetched since the cursor was opened.
  • 51. Determining the number of fetched rows for a cursor  The following pre-requisites must be met before you use the cursor_rowCount function:  A cursor data type must be created.  A cursor variable of the cursor data type must be declared.  An OPEN statement referencing the cursor must have been executed. Example : SET rows_fetched = CURSOR_ROWCOUNT(curEmp)