EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials Oracle Tutorial Oracle SYS_GUID()
Secondary Sidebar
Oracle Tutorial
  • Advanced
    • Timestamp to Date in Oracle
    • Oracle Golden Gate
    • Oracle Virtual Machine
    • Oracle Describe Table
    • Oracle Clauses
    • Oracle Having Clause
    • Oracle?Primavera
    • Oracle FOREIGN Key
    • PIVOT in Oracle
    • Oracle Alter Table
    • Oracle Queries
    • Oracle Views
    • Oracle Window Functions
    • Oracle String Functions
    • Oracle Date Functions
    • Oracle Analytic Functions
    • Oracle Aggregate Functions
    • Select in Oracle
    • INSERT in Oracle
    • DISTINCT in Oracle
    • Function in Oracle
    • Oracle GROUP_CONCAT
    • Oracle INSTR()
    • Oracle CONVERT
    • Oracle LENGTH()
    • Oracle EXISTS
    • Oracle REPLACE()
    • Oracle MERGE
    • Oracle LEAD()
    • Oracle EXTRACT()
    • Oracle LISTAGG()
    • Oracle SYS_CONTEXT()
    • Oracle COALESCE
    • Oracle NVL()
    • Oracle SYSDATE()
    • Oracle?Date Format
    • Oracle SYS_GUID()
    • Oracle WILDCARDS
    • Oracle Synonyms
    • Oracle Subquery
    • BETWEEN in Oracle
    • FETCH in Oracle
    • Oracle Index
    • Oracle Function-based Index
    • Oracle UNIQUE Index
    • Oracle Bitmap Index
    • Oracle Column
    • Oracle Triggers
    • Oracle Procedures
    • Sample Database for Oracle
    • Oracle LIKE Operator
    • ORDER BY in Oracle
    • Oracle ORDER BY DESC
    • GROUP BY in Oracle
    • Oracle GROUP BY HAVING
    • Oracle Aliases
    • Table in Oracle
    • Oracle Temporary Table
    • Oracle? Table Partition
    • Oracle rename table
    • Oracle CTE
    • Cursor in Oracle
    • Oracle LOCK TABLE
    • Oracle Tablespace
    • Oracle CARDINALITY
    • Oracle REGEXP
    • Oracle REGEXP_REPLACE
    • Oracle to_date
    • JSON in Oracle
    • Oracle COMMIT
    • Oracle GRANT
    • Oracle MD5
    • Oracle ROLLBACK
    • Oracle Users
    • Oracle TIMESTAMP
    • IF THEN ELSE in Oracle
    • Oracle While Loop
    • Oracle Clone Database
    • Oracle Backup Database
    • Oracle? XML
    • Oracle XMLAGG
    • Oracle XMLTABLE
    • Oracle Performance Tuning
    • Oracle B Tree Index
    • Oracle fusion
    • Oracle ebs
    • Oracle GRC
    • Oracle ERP
    • Oracle ASM
    • Oracle Cloud
    • Oracle HCM Cloud
    • Oracle Integration Cloud
    • Oracle Jinitiator
    • Oracle pathfinder
    • Oracle VirtualBox
    • Oracle Weblogic Server
    • Oracle decode
    • Oracle Exadata
    • Oracle ZFS
    • Oracle? utilities
    • JDBC Driver for Oracle
    • Oracle? DBA Versions
    • Oracle DBA Salary
  • Basic
    • Oracle Marketing Cloud
    • What is Oracle?
    • Career in Oracle
    • How to Install Oracle
    • Oracle Versions
    • What Is Oracle Database
    • Oracle Data Warehousing
    • Oracle Warehouse Builder
    • Career In Oracle Database Administrator
    • Career In Oracle DBA
    • What is Oracle RAC
    • Oracle DBA
    • Oracle? Vanderbilt
    • What is RMAN Oracle
    • Oracle Database Administration
    • Oracle Operators
    • Oracle Constraints
    • Oracle number
    • Oracle Data Types
    • Oracle UNIQUE Constraint
    • Oracle Check Constraint
  • Joins
    • Joins in Oracle
    • Inner Join in Oracle
    • Oracle Cross Join
    • Left Join in Oracle
    • OUTER Join in Oracle
    • Oracle Full Outer Join
    • Natural Join in Oracle
    • Oracle Self Join
    • Oracle hash join
    • Oracle? Update with Join
  • Oracle SET Operators
    • UNION in Oracle
    • Oracle UNION ALL
    • INTERSECT in Oracle
    • MINUS in Oracle
  • Interview Questions
    • Oracle Interview Questions
    • Oracle Apps Interview Questions
    • Oracle Apps Technical Interview Questions
    • Oracle Database Interview Questions
    • Oracle Forms Interview Questions
    • Oracle PL/SQL Interview Questions
    • Oracle RAC Interview Questions
    • Oracle SOA Interview Questions

Related Courses

Oracle Course Training

Oracle DBA Certification Course

MongoDB Certification Training

Oracle SYS_GUID()

By Priya PedamkarPriya Pedamkar

Oracle SYS_GUID()

Definition of Oracle SYS_GUID()

SYS_GUID () function in oracle database can be defined as a built-in function in PL/SQL which is used to generate and return a global unique identifier (GUID) (RAW value) of size 16 bytes for each row of the table and it does not accept any argument in the function, it generates GUID which are supposed to be unique meaning they should never be repeated twice and it also consists of a host identifier a process or thread identifier of the process which invoked the function.

Syntax:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

In the previous section we discussed about the definition of the function. In this section we will discuss about the syntax of the function. Let us go through the syntax of this function below.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (85,992 ratings)

SYS_GUID()

One important point to remember is that this function takes no argument.

How SYS_GUID() Works in Oracle?

In this section, we will discuss the working of sys_guid built-in function in the Oracle database. This function generates unique identifiers that are of type RAW and it is a 128-bit number or 16 bytes in size. So when we execute the function SYS_GUID it generates a 128-bit number which is unique which means it is not the same as the previous numbers it generated. It relies on a combination of components to make sure it is unique every time. A UUID consists of a reference to the network address of the host who generated the UUID, a timestamp (the exact time in which it was generated) and the last component is a randomly generated component. The network address and the timestamp of the exact time when the number was generated help in making the number generated always a unique number and the last component also helps in contributing to the uniqueness of the number. The combination of these three components helps the function to generate a unique number every time.

Examples of Oracle SYS_GUID()

In the previous sections, we discussed the working of the sys_guid () and now in this section, we are going to discuss a few examples.

1. SYS_GUID() with Dual

In the first example, we are going to generate a Unique identification number using this function. So, let us prepare the query for the same.

Query:

SELECT sys_guid() from DUAL;

In the above query DUAL is one row and one column table present by default in the Oracle database. It is accessible to all users by the name DUAL.

Let us now run the query in SQL worksheet and check the result.

Oracle SYS_GUID()-1.1

As, we can see in the above screenshot, a unique 128 bit or 16-byte number has been generated.

2. Insert a Unique Id in A Column Using SYS_GUID

In the previous example, we created a unique identifier using the function. We can also use this function to insert a unique identification numbers in columns of a table. In this example, we will insert a random unique number in the employee id column present in the table employee. The employee id column is the primary key of the table. We will use the function SYS_GUID for this purpose. Let us prepare an INSERT query for the same.

Query:

INSERT INTO employee(employee_id, employee_name, city) values(sys_guid(), 'Nilanjan', 'Mumbai');

In the above query, we are using the sys_guid() function for employee_id column. Let us execute the query in the SQL worksheet and check the result.

Oracle SYS_GUID()-1.2

As we can see on the screenshot a row has been inserted successfully.

Let us now check the data in the employee table and verify. Let us prepare a SELECT statement for the same.

Query:

SELECT employee_id, employee_name, city from employee;

Oracle SYS_GUID()-1.3

As we can see in the above screenshot, the employee id consists of a 16 byte or 128-bit Unique Identification Number. Hence, we can use this function to generate primary numbers.

3. Update a Unique Id in A Column Using SYS_GUID

In the previous example, we discussed that we can insert a primary key using the SYS_GUID function. In this example, we will check how to update the value of an existing column using this function. Just as we used in the previous example to INSERT a unique Identification Number, Similarly we will use the same function to update the value of a column with an unique number. Let us prepare an UPDATE statement for the same.

Query:

UPDATE employee SET uid_col = SYS_GUID();

Let us execute the query in the SQL worksheet and check the result.

Oracle SYS_GUID()-1.4

As we can see in the screenshot above, the row has been updated. Let us now check the data in the employee table and verify. Let us prepare a SELECT statement for the same.

Query:

SELECT employee_id, employee_name, city, uid_col from employee;

Let us now execute the above query in SQL worksheet and verify the result.

Oracle SYS_GUID()-1.5

As we can see in the above screenshot the UID_COL shows a unique number generated from the function SYS_GUID ().

Advantages

In the above section, we discussed a few examples to get a better understanding of using this function. Now, we will discuss the advantages of using this function. This function can be used as a default value for a primary key. This function can be used as an alternative instead of a sequence which we generally use. The numbers generated are always unique because the number generated from this function consists of three parts: reference to the network address of the host who generated the UUID, a timestamp and the last component is a randomly generated component which means that it will always be unique. One important point to note is that the numbers generated are not sequential but generally random and it also reduces contention for hot blocks and we cannot perform arithmetical operations.

Conclusion

In this article, we discussed the definition of the topic SYS_GUID() in the beginning of the article. Later we discussed the syntax of the function and the working of the function. We discussed a few examples and ended the article with the advantages of this function.

Recommended Articles

This is a guide to Oracle SYS_GUID(). Here we also discuss the definition and how sys_guid() works in oracle? along with different examples and its code implementation. You may also have a look at the following articles to learn more –

  1. Oracle Tablespace
  2. Oracle INSTR()
  3. Oracle UNIQUE Index
  4. Oracle Index
Popular Course in this category
Oracle Training (14 Courses, 8+ Projects)
  14 Online Courses |  8 Hands-on Projects |  120+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Oracle DBA Database Management System Training (2 Courses)4.9
All in One Financial Analyst Bundle- 250+ Courses, 40+ Projects4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more