SlideShare a Scribd company logo
Anchored data type
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.

Features of the anchored data type
An anchored type defines a data type based on another SQL object such as a
column, global variable, SQL variable, SQL parameter, or the row of a table or view.

A data type defined using an anchored type definition maintains a dependency on
the object to which it is anchored. Any change in the data type of the anchor object
will impact the anchored data type. If anchored to the row of a table or view, the
anchored data type is ROW with the fields defined by the columns of the anchor
table or anchor view.

This data type is useful when declaring variables in cases where you require that the
variable have the same data type as another object, for example a column in a table,
but you do not know exactly what is the data type.

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

Anchored data types can only be specified when declaring or creating one of the
following:
       a local variable in an SQL procedure, including a row variable
       a local variable in a compiled SQL function, including a row variable
       a routine parameter
       a user-defined cursor data type using the CREATE TYPE statement.
       It cannot be referenced in a DECLARE CURSOR statement.
       a function return data type
       a global variable
To define an anchored data type specify the ANCHOR DATA TYPE TO clause (or
the shorter form ANCHOR clause) to specify what the data type will be. If the
anchored data type is a row data type, the ANCHOR ROW OF clause, or one of its
synonyms, must be specified. These clauses are supported within the following
statements:
      DECLARE
      CREATE TYPE
      CREATE VARIABLE
      In this version, global variables can only be anchored to other global
      variables, a column in a table, or a column in a view.
Restrictions on the anchored data type
Review the restrictions on the use of the anchored data type before declaring
variables of this type or when troubleshooting problems related to their use.

The following restrictions apply to the use of anchored data types, including types
specified using the PL/SQL %TYPE attribute:
       Anchored data types are not supported in inline SQL functions.
       Anchored data types cannot reference nicknames or columns in nicknames.
       Anchored data types cannot reference typed tables, columns of typed tables,
       typed views, or columns of typed views.
       Anchored data types cannot reference declared temporary tables, or columns
       of declared temporary tables.
       Anchored data types cannot reference row definitions associated with a
       weakly typed cursor.
       Anchored data types cannot reference objects with a code page or collation
       that is different from the database code page or database collation.
Anchored data type variables
An anchored variable is a local variable or parameter with a data type that is an
anchored data type.

Anchored variables are supported in the following contexts:
     SQL procedures
         o In SQL procedures, parameters and local variables can be specified to
            be of an anchored data type.
     Compiled SQL functions
         o SQL functions created using the CREATE FUNCTION statement that
            specify the BEGIN clause instead of the BEGIN ATOMIC clause can
            include parameter or local variable specification that are of the
            anchored data type.
     Module variables
         o Anchored variables can be specified as published or unpublished
            variables defined within a module.
     Global variables
         o Global variables can be created of the anchored data type.
Declaring local variables of the anchored data type
Declaring local variables or parameters of the anchored data type is a task that you would
perform whenever it is necessary that the data type of the variable or parameter remain
consistent with the data type of the object to which it is anchored.
Before you begin

The object of the data type that the variable will be anchored to must be defined.

About this task

Procedure

   1. Formulate a DECLARE statement

           a. Specify the name of the variable.
           b. Specify the ANCHOR DATA TYPE TO clause.
           c. Specify the name of the object that is of the data type that the variable is to be
              anchored.

   2. Execute the DECLARE statement from a supported DB2® interface.

Results

If the DECLARE statement executes successfully, the variable is defined in the database
with the specified anchor data type.

Example
The following is an example of an anchored data type declaration in which a variable
named v1 is anchored to the data type of a column named c1 in a table named emp:

DECLARE v1 ANCHOR DATA TYPE TO emp.c1;

What to do next

Once the variable is defined it can be assigned a value, be referenced, or passed as a
parameter to routines.

Example: Variable declarations of anchored data types
Examples of anchored data type declarations can be useful references when declaring
variables.

The following is an example of a declaration of a variable named v1 that has the same data
type as the column name in table staff:
DECLARE v1 ANCHOR DATA TYPE TO staff.name;
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 namedemployee:
CREATE TYPE empRow1 AS ROW ANCHOR DATA TYPE TO ROW OF employee;
For variables declared of type empRow1, the field names are the same as the table column
names.

If the data type of the column name is VARCHAR(128), then the variable v1 will also be of
data type VARCHAR(128).

Examples: Anchored data type use in SQL routines
Examples of anchored data type use in SQL routines are useful to reference when creating
your own SQL routines.

The set of examples below demonstrate various features and uses of anchored data types in
SQL routines. The anchored data type features are demonstrated more so than the features
of the SQL routines that contain them.

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)@

CREATE PROCEDURE p1()
BEGIN
  DECLARE var1 ANCHOR tab1.col1;
  SELECT col1 INTO var1 FROM tab1 WHERE col2 = 2;
  INSERT INTO tab2 VALUES (var1, 'a');
END@

More Related Content

What's hot

Dbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational ModelDbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational Model
Amiya9439793168
 
03 Ch3 Notes Revised
03 Ch3 Notes Revised03 Ch3 Notes Revised
03 Ch3 Notes Revised
guest6f408c
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
Arun Sharma
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
Siti Ismail
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
Balqees Al.Mubarak
 
XML DTD and Schema
XML DTD and SchemaXML DTD and Schema
XML DTD and Schema
hamsa nandhini
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
Dhani Ahmad
 
Enhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) ModelingEnhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) Modeling
sontumax
 
Coupling and cohesion
Coupling and cohesionCoupling and cohesion
Coupling and cohesion
Sutha31
 
Referential integrity
Referential integrityReferential integrity
Referential integrity
Jubin Raju
 
Sap pi 10 nodes
Sap pi 10 nodesSap pi 10 nodes
Sap pi 10 nodes
prabha1987
 
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
Raj vardhan
 
Object-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdfObject-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdf
Bharath Choudhary
 
Trigger in DBMS
Trigger in DBMSTrigger in DBMS
Trigger in DBMS
A. S. M. Shafi
 
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING ARADHYAYANA
 
Fundamentals of Database ppt ch03
Fundamentals of Database ppt ch03Fundamentals of Database ppt ch03
Fundamentals of Database ppt ch03Jotham Gadot
 
Unit 5 composite datatypes
Unit 5  composite datatypesUnit 5  composite datatypes
Unit 5 composite datatypes
DrkhanchanaR
 
Alter table command
Alter table commandAlter table command
Alter table command
ravikhandelwal41
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 

What's hot (20)

Dbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational ModelDbms 10: Conversion of ER model to Relational Model
Dbms 10: Conversion of ER model to Relational Model
 
03 Ch3 Notes Revised
03 Ch3 Notes Revised03 Ch3 Notes Revised
03 Ch3 Notes Revised
 
Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
 
XML DTD and Schema
XML DTD and SchemaXML DTD and Schema
XML DTD and Schema
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
 
Enhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) ModelingEnhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) Modeling
 
Coupling and cohesion
Coupling and cohesionCoupling and cohesion
Coupling and cohesion
 
Referential integrity
Referential integrityReferential integrity
Referential integrity
 
Sap pi 10 nodes
Sap pi 10 nodesSap pi 10 nodes
Sap pi 10 nodes
 
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
 
Object-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdfObject-Oriented Programming in Java.pdf
Object-Oriented Programming in Java.pdf
 
Trigger in DBMS
Trigger in DBMSTrigger in DBMS
Trigger in DBMS
 
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
ER DIAGRAM TO RELATIONAL SCHEMA MAPPING
 
Fundamentals of Database ppt ch03
Fundamentals of Database ppt ch03Fundamentals of Database ppt ch03
Fundamentals of Database ppt ch03
 
Unit 5 composite datatypes
Unit 5  composite datatypesUnit 5  composite datatypes
Unit 5 composite datatypes
 
Alter table command
Alter table commandAlter table command
Alter table command
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
 

Viewers also liked

V.social campaign
V.social campaignV.social campaign
V.social campaign
Michael Scott
 
More than yea or nay day 1 0
More than yea or nay day 1 0More than yea or nay day 1 0
More than yea or nay day 1 0Becknell
 
Taking The Plunge In Blogging 2
Taking The Plunge In Blogging 2Taking The Plunge In Blogging 2
Taking The Plunge In Blogging 2
bigpinots
 
Tech pp
Tech ppTech pp
Tech ppCjd002
 
More than yea or nay day 2 0
More than yea or nay day 2 0More than yea or nay day 2 0
More than yea or nay day 2 0
Becknell
 
Assignment 1(web)
Assignment 1(web)Assignment 1(web)
Assignment 1(web)Jay Patel
 
Acampada
AcampadaAcampada
Acampadapiko217
 
Presentation1
Presentation1Presentation1
Presentation1Jay Patel
 
Mírame a los ojos
Mírame a los ojosMírame a los ojos
Mírame a los ojospiko217
 
Inwork-johdanto 3.12.2013
Inwork-johdanto 3.12.2013Inwork-johdanto 3.12.2013
Inwork-johdanto 3.12.2013
Sonja Kärkkäinen
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software toolsJay Patel
 
Selection sort
Selection sortSelection sort
Selection sortJay Patel
 

Viewers also liked (15)

V.social campaign
V.social campaignV.social campaign
V.social campaign
 
More than yea or nay day 1 0
More than yea or nay day 1 0More than yea or nay day 1 0
More than yea or nay day 1 0
 
Taking The Plunge In Blogging 2
Taking The Plunge In Blogging 2Taking The Plunge In Blogging 2
Taking The Plunge In Blogging 2
 
Tech pp
Tech ppTech pp
Tech pp
 
More than yea or nay day 2 0
More than yea or nay day 2 0More than yea or nay day 2 0
More than yea or nay day 2 0
 
Assignment 1(web)
Assignment 1(web)Assignment 1(web)
Assignment 1(web)
 
Codd rules
Codd rulesCodd rules
Codd rules
 
Acampada
AcampadaAcampada
Acampada
 
Codd rules
Codd rulesCodd rules
Codd rules
 
Images
ImagesImages
Images
 
Presentation1
Presentation1Presentation1
Presentation1
 
Mírame a los ojos
Mírame a los ojosMírame a los ojos
Mírame a los ojos
 
Inwork-johdanto 3.12.2013
Inwork-johdanto 3.12.2013Inwork-johdanto 3.12.2013
Inwork-johdanto 3.12.2013
 
Multimedia software tools
Multimedia software toolsMultimedia software tools
Multimedia software tools
 
Selection sort
Selection sortSelection sort
Selection sort
 

Similar to Anchored data type

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 typedhruv patel
 
Pl sql
Pl sqlPl sql
Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)
Nalina Kumari
 
Oracle 11G Development Training noida Delhi NCR
Oracle 11G Development Training noida Delhi NCROracle 11G Development Training noida Delhi NCR
Oracle 11G Development Training noida Delhi NCR
Shri Prakash Pandey
 
Dbms important questions and answers
Dbms important questions and answersDbms important questions and answers
Dbms important questions and answers
LakshmiSarvani6
 
Structure Query Language (SQL).pptx
Structure Query Language (SQL).pptxStructure Query Language (SQL).pptx
Structure Query Language (SQL).pptx
NalinaKumari2
 
DBMS MODULE 3 NOTES ENGINEERING CSE .pdf
DBMS MODULE 3 NOTES ENGINEERING CSE .pdfDBMS MODULE 3 NOTES ENGINEERING CSE .pdf
DBMS MODULE 3 NOTES ENGINEERING CSE .pdf
raki082m
 
Oracle11gdevtrainingindelhincr
Oracle11gdevtrainingindelhincrOracle11gdevtrainingindelhincr
Oracle11gdevtrainingindelhincr
ducat1989
 
chapter9-SQL.pptx
chapter9-SQL.pptxchapter9-SQL.pptx
chapter9-SQL.pptx
Yaser52
 
Oracle report from ppt
Oracle report from pptOracle report from ppt
Oracle report from ppt
kingshuk_goswami
 
Ankit
AnkitAnkit
SQL DDL
SQL DDLSQL DDL
SQL DDL
Vikas Gupta
 
11i&r12 difference
11i&r12 difference11i&r12 difference
11i&r12 difference
venki_venki
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server iiIblesoft
 

Similar to Anchored data type (20)

Unit1
Unit1Unit1
Unit1
 
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
 
Pl sql
Pl sqlPl sql
Pl sql
 
Pl sql
Pl sqlPl sql
Pl sql
 
Pl sql
Pl sqlPl sql
Pl sql
 
Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)
 
Oracle 11G Development Training noida Delhi NCR
Oracle 11G Development Training noida Delhi NCROracle 11G Development Training noida Delhi NCR
Oracle 11G Development Training noida Delhi NCR
 
Dbms important questions and answers
Dbms important questions and answersDbms important questions and answers
Dbms important questions and answers
 
Structure Query Language (SQL).pptx
Structure Query Language (SQL).pptxStructure Query Language (SQL).pptx
Structure Query Language (SQL).pptx
 
DBMS MODULE 3 NOTES ENGINEERING CSE .pdf
DBMS MODULE 3 NOTES ENGINEERING CSE .pdfDBMS MODULE 3 NOTES ENGINEERING CSE .pdf
DBMS MODULE 3 NOTES ENGINEERING CSE .pdf
 
Oracle11gdevtrainingindelhincr
Oracle11gdevtrainingindelhincrOracle11gdevtrainingindelhincr
Oracle11gdevtrainingindelhincr
 
chapter9-SQL.pptx
chapter9-SQL.pptxchapter9-SQL.pptx
chapter9-SQL.pptx
 
Oracle report from ppt
Oracle report from pptOracle report from ppt
Oracle report from ppt
 
Ankit
AnkitAnkit
Ankit
 
12 SQL
12 SQL12 SQL
12 SQL
 
12 SQL
12 SQL12 SQL
12 SQL
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 
Plsqlobj
PlsqlobjPlsqlobj
Plsqlobj
 
11i&r12 difference
11i&r12 difference11i&r12 difference
11i&r12 difference
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 

More from 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
 
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
 
Mutlimedia authoring tools
Mutlimedia authoring toolsMutlimedia authoring tools
Mutlimedia authoring 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
 
Lecturestacks 110802115132-phpapp02
Lecturestacks 110802115132-phpapp02Lecturestacks 110802115132-phpapp02
Lecturestacks 110802115132-phpapp02Jay Patel
 
Introductionofdatastructure 110731092019-phpapp01
Introductionofdatastructure 110731092019-phpapp01Introductionofdatastructure 110731092019-phpapp01
Introductionofdatastructure 110731092019-phpapp01Jay Patel
 
Applicationsofstack 110805072322-phpapp01
Applicationsofstack 110805072322-phpapp01Applicationsofstack 110805072322-phpapp01
Applicationsofstack 110805072322-phpapp01Jay Patel
 
Chapter19 multimedia-091006115642-phpapp02 (1)
Chapter19 multimedia-091006115642-phpapp02 (1)Chapter19 multimedia-091006115642-phpapp02 (1)
Chapter19 multimedia-091006115642-phpapp02 (1)Jay Patel
 

More from 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)
 
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
 
Mutlimedia authoring tools
Mutlimedia authoring toolsMutlimedia authoring tools
Mutlimedia authoring tools
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
 
Sound
SoundSound
Sound
 
Lecture6 text
Lecture6   textLecture6   text
Lecture6 text
 
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
 
Lecturestacks 110802115132-phpapp02
Lecturestacks 110802115132-phpapp02Lecturestacks 110802115132-phpapp02
Lecturestacks 110802115132-phpapp02
 
Introductionofdatastructure 110731092019-phpapp01
Introductionofdatastructure 110731092019-phpapp01Introductionofdatastructure 110731092019-phpapp01
Introductionofdatastructure 110731092019-phpapp01
 
Applicationsofstack 110805072322-phpapp01
Applicationsofstack 110805072322-phpapp01Applicationsofstack 110805072322-phpapp01
Applicationsofstack 110805072322-phpapp01
 
Chapter19 multimedia-091006115642-phpapp02 (1)
Chapter19 multimedia-091006115642-phpapp02 (1)Chapter19 multimedia-091006115642-phpapp02 (1)
Chapter19 multimedia-091006115642-phpapp02 (1)
 

Recently uploaded

Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 

Recently uploaded (20)

Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 

Anchored data type

  • 1. Anchored data type 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. Features of the anchored data type An anchored type defines a data type based on another SQL object such as a column, global variable, SQL variable, SQL parameter, or the row of a table or view. A data type defined using an anchored type definition maintains a dependency on the object to which it is anchored. Any change in the data type of the anchor object will impact the anchored data type. If anchored to the row of a table or view, the anchored data type is ROW with the fields defined by the columns of the anchor table or anchor view. This data type is useful when declaring variables in cases where you require that the variable have the same data type as another object, for example a column in a table, but you do not know exactly what is the data type. 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 Anchored data types can only be specified when declaring or creating one of the following: a local variable in an SQL procedure, including a row variable a local variable in a compiled SQL function, including a row variable a routine parameter a user-defined cursor data type using the CREATE TYPE statement. It cannot be referenced in a DECLARE CURSOR statement. a function return data type a global variable To define an anchored data type specify the ANCHOR DATA TYPE TO clause (or the shorter form ANCHOR clause) to specify what the data type will be. If the anchored data type is a row data type, the ANCHOR ROW OF clause, or one of its
  • 2. synonyms, must be specified. These clauses are supported within the following statements: DECLARE CREATE TYPE CREATE VARIABLE In this version, global variables can only be anchored to other global variables, a column in a table, or a column in a view. Restrictions on the anchored data type Review the restrictions on the use of the anchored data type before declaring variables of this type or when troubleshooting problems related to their use. The following restrictions apply to the use of anchored data types, including types specified using the PL/SQL %TYPE attribute: Anchored data types are not supported in inline SQL functions. Anchored data types cannot reference nicknames or columns in nicknames. Anchored data types cannot reference typed tables, columns of typed tables, typed views, or columns of typed views. Anchored data types cannot reference declared temporary tables, or columns of declared temporary tables. Anchored data types cannot reference row definitions associated with a weakly typed cursor. Anchored data types cannot reference objects with a code page or collation that is different from the database code page or database collation. Anchored data type variables An anchored variable is a local variable or parameter with a data type that is an anchored data type. Anchored variables are supported in the following contexts: SQL procedures o In SQL procedures, parameters and local variables can be specified to be of an anchored data type. Compiled SQL functions o SQL functions created using the CREATE FUNCTION statement that specify the BEGIN clause instead of the BEGIN ATOMIC clause can include parameter or local variable specification that are of the anchored data type. Module variables o Anchored variables can be specified as published or unpublished variables defined within a module. Global variables o Global variables can be created of the anchored data type. Declaring local variables of the anchored data type Declaring local variables or parameters of the anchored data type is a task that you would perform whenever it is necessary that the data type of the variable or parameter remain consistent with the data type of the object to which it is anchored.
  • 3. Before you begin The object of the data type that the variable will be anchored to must be defined. About this task Procedure 1. Formulate a DECLARE statement a. Specify the name of the variable. b. Specify the ANCHOR DATA TYPE TO clause. c. Specify the name of the object that is of the data type that the variable is to be anchored. 2. Execute the DECLARE statement from a supported DB2® interface. Results If the DECLARE statement executes successfully, the variable is defined in the database with the specified anchor data type. Example The following is an example of an anchored data type declaration in which a variable named v1 is anchored to the data type of a column named c1 in a table named emp: DECLARE v1 ANCHOR DATA TYPE TO emp.c1; What to do next Once the variable is defined it can be assigned a value, be referenced, or passed as a parameter to routines. Example: Variable declarations of anchored data types Examples of anchored data type declarations can be useful references when declaring variables. The following is an example of a declaration of a variable named v1 that has the same data type as the column name in table staff: DECLARE v1 ANCHOR DATA TYPE TO staff.name; 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 namedemployee: CREATE TYPE empRow1 AS ROW ANCHOR DATA TYPE TO ROW OF employee; For variables declared of type empRow1, the field names are the same as the table column names. If the data type of the column name is VARCHAR(128), then the variable v1 will also be of data type VARCHAR(128). Examples: Anchored data type use in SQL routines
  • 4. Examples of anchored data type use in SQL routines are useful to reference when creating your own SQL routines. The set of examples below demonstrate various features and uses of anchored data types in SQL routines. The anchored data type features are demonstrated more so than the features of the SQL routines that contain them. 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)@ CREATE PROCEDURE p1() BEGIN DECLARE var1 ANCHOR tab1.col1; SELECT col1 INTO var1 FROM tab1 WHERE col2 = 2; INSERT INTO tab2 VALUES (var1, 'a'); END@