SlideShare una empresa de Scribd logo
1 de 17
Descargar para leer sin conexión
SQL Functions
&
Operators
CS2258 – Database Management Systems Lab
R. Mohan Kumar
Assistant Professor / CSE
Saranathan College of Engineering
SQL Functions
 Numeric Functions
 Date Functions
 Text Functions
CS2258 – Database Management Systems Lab
Syntax
select <function_name> from dual;
2
Numeric Functions
CS2258 – Database Management Systems Lab
FUNCTION NAME DESCRIPTION
ABS(x) Absolute value of the number “x”
CEIL(x) Integer value that is greater than (or) equal to “x”
FLOOR(x) Integer value that is lesser than (or) equal to “x”
TRUNC(x,y) Truncate values of “x” upto “y” decimal places.
ROUND(x,y) Rounded off value of “x” upto “y” decimal places.
1 of 5
3
Numeric Functions
CS2258 – Database Management Systems Lab
FUNCTION NAME DESCRIPTION
MOD(x,y) Returns the result of X % Y (remainder)
POWER(x,y) Returns the value of X ^ Y
SQRT(x) Returns the square root value of X
LOG(x) Returns the Base 10 logarithm of X
SIGN(x) 1 if X is POSITIVE ; -1 if X is NEGATIVE ; 0 if X is ZERO
2 of 5
4
Numeric Functions
CS2258 – Database Management Systems Lab
FUNCTION NAME DESCRIPTION
SIN(x) Returns the Sine value of X
COS(x) Returns the Cosine value of X
TAN(x) Returns the Tangent value of X
EXP(x) E raised to X exponent
LN(x) Returns the Natural Logarithm of X
3 of 5
5
Numeric Functions
CS2258 – Database Management Systems Lab
FUNCTION NAME DESCRIPTION
MAX()
It selects the MAXIMUM value in the specified column.
Syntax:
Select MAX(<col_name>) from <table_name>;
MIN()
It selects the MINIMUM value in the specified column.
Syntax:
Select MIN(<col_name>) from <table_name>;
MEDIAN()
It returns the MEDIAN of all values in the given
column.
Syntax:
Select MEDIAN(<col_name>) from <table_name>;
4 of 5
6
Numeric Functions
CS2258 – Database Management Systems Lab
FUNCTION NAME DESCRIPTION
AVG()
It returns the average of all values in the given column.
Syntax:
Select AVG(<col_name>) from <table_name>;
SUM()
It returns the sum of all values in the given column.
Syntax:
Select SUM(<col_name>) from <table_name>;
COUNT()
It returns the no. of rows in the given column.
Syntax:
Select COUNT(<col_name>) from <table_name>;
5 of 5
7
Date Functions
FUNCTION NAME DESCRIPTION
SYSDATE Returns the systems current date.
ADD_MONTHS(date,n)
Returns a date value after adding in months
to the “date”.
MONTHS_BETWEEN(x1,x2)
Returns the number of months between dates
x1 and x2.
NEXTDAY(x, weekday)
Returns the next date of the “weekday” on or
after “x” occurs.
LAST_DAY(x) Returns the last date of the particular month.
CS2258 – Database Management Systems Lab
1 of 2
8
Date Functions
FUNCTION NAME DESCRIPTION
SysTimeStamp
Returns the system date in TIMESTAMP
format.
To_char(date,format)
Returns the date value in given format.
Syntax:
Select to_char(sysdate,’mm/dd/yy’)
from dual;
CS2258 – Database Management Systems Lab
2 of 2
9
String / Text Functions
FUNCTION NAME DESCRIPTION
UPPER(x) It converts the string ‘X’ to UPPER case
LOWER(x) It converts the string ‘X’ to LOWER case
RTRIM(x,y)
It returns the string after trimming all
occurrence of sub string ‘y’ from right side of
the input string ‘X’.
LTRIM(x,y)
It returns the string after trimming all
occurrence of sub string ‘y’ from left side of
the input string ‘X’.
LENGTH(x) Returns the length of the input string ‘X’
CS2258 – Database Management Systems Lab
1 of 2
10
String / Text Functions
FUNCTION NAME DESCRIPTION
INITCAP(x)
It converts the first character of the input
string to UPPER case.
SUBSTR(x,m,n)
Returns the substring of given string starting
from position integer ‘m’ and length integer
‘n’.
TRANSLATE(x,new,old)
It converts the string by substituting the new
string in the place of old string.
ASCII(c) Returns the ASCII value of the character ‘c’.
CHR(number)
Returns the character for a ASCII value
‘number’.
CS2258 – Database Management Systems Lab
2 of 2
11
Operators
 Arithmetic Operators
+ , - , * , /
 Comparison Operators
= , != , <, <=, >, >=
Like, In, Between And , Is Null
 Logical Operators
OR, AND, NOT
CS2258 – Database Management Systems Lab 12
Operators usage
 Arithmetic Operator
select 2 + 3 from dual;
select 10 - 5 from dual;
select salary + allowance from worker;
salary & allowance are the attributes of worker table.
update customer set balance = balance + balance * 0.075;
CS2258 – Database Management Systems Lab 13
Operators usage
 Comparison Operator
select * from customer where amount = 10000;
select * from customer where amount < 500;
select * from customer where age > 68;
update customer set interest_rate = 0.0925
where age >= 68;
delete from customer where balance <= 50;
CS2258 – Database Management Systems Lab 14
Operators usage
 Comparison Operator
select * from customer where cname LIKE ‘a%;
select * from customer where cname LIKE ‘%er;
select * from customer where cname IN (value1,value2,…);
delete from customer where balance BETWEEN 0 AND 50;
select * from customer where phoneno IS NULL;
CS2258 – Database Management Systems Lab 15
Operators usage
 Logical Operator
select * from customer where cname=‘john’ OR
cname=‘joshy’ ;
select * from customer where fname=‘joe’ AND
lname=‘parker’ ;
select * from customer where phoneno IS NOT NULL;
CS2258 – Database Management Systems Lab 16
17
Browse for this material
www.sara-eclass.blogspot.in
CS2258 – Database Management Systems Lab

Más contenido relacionado

La actualidad más candente (20)

PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts PL/SQL Introduction and Concepts
PL/SQL Introduction and Concepts
 
sql function(ppt)
sql function(ppt)sql function(ppt)
sql function(ppt)
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
SQL
SQLSQL
SQL
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
Data Manipulation Language
Data Manipulation LanguageData Manipulation Language
Data Manipulation Language
 
Oracle SQL Basics
Oracle SQL BasicsOracle SQL Basics
Oracle SQL Basics
 

Similar a SQL Functions & Operators Guide

SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?Andrej Pashchenko
 
Intro to tsql unit 10
Intro to tsql   unit 10Intro to tsql   unit 10
Intro to tsql unit 10Syed Asrarali
 
sql functions3 (1).pdf
sql functions3 (1).pdfsql functions3 (1).pdf
sql functions3 (1).pdfUsha570012
 
Mysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERTMysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERTHarish Gyanani
 
Structured query language functions
Structured query language functionsStructured query language functions
Structured query language functionsVineeta Garg
 
Sql FUNCTIONS
Sql FUNCTIONSSql FUNCTIONS
Sql FUNCTIONSAbrar ali
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptxEllenGracePorras
 
Explaining the Postgres Query Optimizer
Explaining the Postgres Query OptimizerExplaining the Postgres Query Optimizer
Explaining the Postgres Query OptimizerEDB
 
Key functions in_oracle_sql
Key functions in_oracle_sqlKey functions in_oracle_sql
Key functions in_oracle_sqlpgolhar
 
Sql intro
Sql introSql intro
Sql introglubox
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSabrinaShanta2
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSaiMiryala1
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxBhupendraShahi6
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql newSANTOSH RATH
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answerRaajTech
 
Getting Started with SQL Language.pptx
Getting Started with SQL Language.pptxGetting Started with SQL Language.pptx
Getting Started with SQL Language.pptxCecilia Brusatori
 

Similar a SQL Functions & Operators Guide (20)

SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
Intro to tsql unit 10
Intro to tsql   unit 10Intro to tsql   unit 10
Intro to tsql unit 10
 
sql functions3 (1).pdf
sql functions3 (1).pdfsql functions3 (1).pdf
sql functions3 (1).pdf
 
Mysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERTMysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERT
 
Sql functions
Sql functionsSql functions
Sql functions
 
R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
 
Structured query language functions
Structured query language functionsStructured query language functions
Structured query language functions
 
Sql FUNCTIONS
Sql FUNCTIONSSql FUNCTIONS
Sql FUNCTIONS
 
Data Manipulation Language.pptx
Data Manipulation Language.pptxData Manipulation Language.pptx
Data Manipulation Language.pptx
 
Explaining the Postgres Query Optimizer
Explaining the Postgres Query OptimizerExplaining the Postgres Query Optimizer
Explaining the Postgres Query Optimizer
 
Key functions in_oracle_sql
Key functions in_oracle_sqlKey functions in_oracle_sql
Key functions in_oracle_sql
 
Sql intro
Sql introSql intro
Sql intro
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
PPT
PPTPPT
PPT
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Les03 Single Row Function
 
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptxSQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
SQL-Tutorial.P1241112567Pczwq.powerpoint.pptx
 
Introduction to sql new
Introduction to sql newIntroduction to sql new
Introduction to sql new
 
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1  questions and answerChapter 16-spreadsheet1  questions and answer
Chapter 16-spreadsheet1 questions and answer
 
Getting Started with SQL Language.pptx
Getting Started with SQL Language.pptxGetting Started with SQL Language.pptx
Getting Started with SQL Language.pptx
 

Último

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
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
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
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
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 

Último (20)

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
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
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
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.
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 

SQL Functions & Operators Guide

  • 1. SQL Functions & Operators CS2258 – Database Management Systems Lab R. Mohan Kumar Assistant Professor / CSE Saranathan College of Engineering
  • 2. SQL Functions  Numeric Functions  Date Functions  Text Functions CS2258 – Database Management Systems Lab Syntax select <function_name> from dual; 2
  • 3. Numeric Functions CS2258 – Database Management Systems Lab FUNCTION NAME DESCRIPTION ABS(x) Absolute value of the number “x” CEIL(x) Integer value that is greater than (or) equal to “x” FLOOR(x) Integer value that is lesser than (or) equal to “x” TRUNC(x,y) Truncate values of “x” upto “y” decimal places. ROUND(x,y) Rounded off value of “x” upto “y” decimal places. 1 of 5 3
  • 4. Numeric Functions CS2258 – Database Management Systems Lab FUNCTION NAME DESCRIPTION MOD(x,y) Returns the result of X % Y (remainder) POWER(x,y) Returns the value of X ^ Y SQRT(x) Returns the square root value of X LOG(x) Returns the Base 10 logarithm of X SIGN(x) 1 if X is POSITIVE ; -1 if X is NEGATIVE ; 0 if X is ZERO 2 of 5 4
  • 5. Numeric Functions CS2258 – Database Management Systems Lab FUNCTION NAME DESCRIPTION SIN(x) Returns the Sine value of X COS(x) Returns the Cosine value of X TAN(x) Returns the Tangent value of X EXP(x) E raised to X exponent LN(x) Returns the Natural Logarithm of X 3 of 5 5
  • 6. Numeric Functions CS2258 – Database Management Systems Lab FUNCTION NAME DESCRIPTION MAX() It selects the MAXIMUM value in the specified column. Syntax: Select MAX(<col_name>) from <table_name>; MIN() It selects the MINIMUM value in the specified column. Syntax: Select MIN(<col_name>) from <table_name>; MEDIAN() It returns the MEDIAN of all values in the given column. Syntax: Select MEDIAN(<col_name>) from <table_name>; 4 of 5 6
  • 7. Numeric Functions CS2258 – Database Management Systems Lab FUNCTION NAME DESCRIPTION AVG() It returns the average of all values in the given column. Syntax: Select AVG(<col_name>) from <table_name>; SUM() It returns the sum of all values in the given column. Syntax: Select SUM(<col_name>) from <table_name>; COUNT() It returns the no. of rows in the given column. Syntax: Select COUNT(<col_name>) from <table_name>; 5 of 5 7
  • 8. Date Functions FUNCTION NAME DESCRIPTION SYSDATE Returns the systems current date. ADD_MONTHS(date,n) Returns a date value after adding in months to the “date”. MONTHS_BETWEEN(x1,x2) Returns the number of months between dates x1 and x2. NEXTDAY(x, weekday) Returns the next date of the “weekday” on or after “x” occurs. LAST_DAY(x) Returns the last date of the particular month. CS2258 – Database Management Systems Lab 1 of 2 8
  • 9. Date Functions FUNCTION NAME DESCRIPTION SysTimeStamp Returns the system date in TIMESTAMP format. To_char(date,format) Returns the date value in given format. Syntax: Select to_char(sysdate,’mm/dd/yy’) from dual; CS2258 – Database Management Systems Lab 2 of 2 9
  • 10. String / Text Functions FUNCTION NAME DESCRIPTION UPPER(x) It converts the string ‘X’ to UPPER case LOWER(x) It converts the string ‘X’ to LOWER case RTRIM(x,y) It returns the string after trimming all occurrence of sub string ‘y’ from right side of the input string ‘X’. LTRIM(x,y) It returns the string after trimming all occurrence of sub string ‘y’ from left side of the input string ‘X’. LENGTH(x) Returns the length of the input string ‘X’ CS2258 – Database Management Systems Lab 1 of 2 10
  • 11. String / Text Functions FUNCTION NAME DESCRIPTION INITCAP(x) It converts the first character of the input string to UPPER case. SUBSTR(x,m,n) Returns the substring of given string starting from position integer ‘m’ and length integer ‘n’. TRANSLATE(x,new,old) It converts the string by substituting the new string in the place of old string. ASCII(c) Returns the ASCII value of the character ‘c’. CHR(number) Returns the character for a ASCII value ‘number’. CS2258 – Database Management Systems Lab 2 of 2 11
  • 12. Operators  Arithmetic Operators + , - , * , /  Comparison Operators = , != , <, <=, >, >= Like, In, Between And , Is Null  Logical Operators OR, AND, NOT CS2258 – Database Management Systems Lab 12
  • 13. Operators usage  Arithmetic Operator select 2 + 3 from dual; select 10 - 5 from dual; select salary + allowance from worker; salary & allowance are the attributes of worker table. update customer set balance = balance + balance * 0.075; CS2258 – Database Management Systems Lab 13
  • 14. Operators usage  Comparison Operator select * from customer where amount = 10000; select * from customer where amount < 500; select * from customer where age > 68; update customer set interest_rate = 0.0925 where age >= 68; delete from customer where balance <= 50; CS2258 – Database Management Systems Lab 14
  • 15. Operators usage  Comparison Operator select * from customer where cname LIKE ‘a%; select * from customer where cname LIKE ‘%er; select * from customer where cname IN (value1,value2,…); delete from customer where balance BETWEEN 0 AND 50; select * from customer where phoneno IS NULL; CS2258 – Database Management Systems Lab 15
  • 16. Operators usage  Logical Operator select * from customer where cname=‘john’ OR cname=‘joshy’ ; select * from customer where fname=‘joe’ AND lname=‘parker’ ; select * from customer where phoneno IS NOT NULL; CS2258 – Database Management Systems Lab 16
  • 17. 17 Browse for this material www.sara-eclass.blogspot.in CS2258 – Database Management Systems Lab