SlideShare una empresa de Scribd logo
1 de 59
Descargar para leer sin conexión
Single-Row Functions
Objectives ,[object Object],[object Object],[object Object],[object Object],[object Object]
SQL Functions Function Function performs action Input arg 1 arg 2 arg  n Output Result value
Two Types of SQL Functions Functions Single-row  functions Multiple-row functions
Single-Row Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],function_name  [( arg1, arg2,... )]
Single-Row Functions Conversion Character Number Date General Single-row  functions
Character Functions Character functions LOWER UPPER INITCAP CONCAT SUBSTR LENGTH INSTR LPAD | RPAD TRIM REPLACE Case-manipulation  functions Character-manipulation functions
Character Functions Character functions LOWER UPPER INITCAP CONCAT SUBSTR LENGTH INSTR LPAD | RPAD TRIM REPLACE Case-manipulation  functions Character-manipulation functions
Case Manipulation Functions ,[object Object],Function Result LOWER('SQL Course') UPPER('SQL Course') INITCAP('SQL Course') sql course SQL COURSE Sql Course
Using Case Manipulation Functions ,[object Object],SELECT employee_id, last_name, department_id FROM  employees WHERE  last_name = 'higgins'; no rows selected SELECT employee_id, last_name, department_id FROM  employees WHERE  LOWER(last_name) = 'higgins';
Character-Manipulation Functions ,[object Object],CONCAT('Hello', 'World') SUBSTR('HelloWorld',1,5) LENGTH('HelloWorld') INSTR('HelloWorld', 'W') LPAD(salary,10,'*') RPAD(salary, 10, '*') TRIM('H' FROM 'HelloWorld') HelloWorld Hello 10 6 *****24000 24000***** elloWorld Function Result
Using the Character-Manipulation Functions SELECT employee_id, CONCAT(first_name, last_name) NAME,  job_id, LENGTH (last_name),  INSTR(last_name, 'a') "Contains 'a'?" FROM  employees WHERE  SUBSTR(job_id, 4) = 'REP'; 1 2 3 1 2 3
Number Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using the  ROUND  Function SELECT ROUND(45.923,2), ROUND(45.923,0), ROUND(45.923,-1) FROM  DUAL; DUAL  is a dummy table you can use to view results  from functions and calculations. 1 2 3 3 1 2
Using the  TRUNC  Function SELECT  TRUNC(45.923,2), TRUNC(45.923), TRUNC(45.923,-2) FROM  DUAL; 3 1 2 1 2 3
Using the  MOD  Function ,[object Object],SELECT last_name, salary, MOD(salary, 5000) FROM  employees WHERE  job_id = 'SA_REP';
Working with Dates ,[object Object],[object Object],[object Object],[object Object],SELECT last_name, hire_date FROM  employees WHERE  last_name like  ' G% ';
Working with Dates ,[object Object],[object Object],[object Object]
Arithmetic with Dates ,[object Object],[object Object],[object Object]
Using Arithmetic Operators with Dates SELECT last_name, (SYSDATE-hire_date)/7 AS WEEKS FROM  employees WHERE  department_id = 90;
Date Functions Number of months between two dates MONTHS_BETWEEN ADD_MONTHS NEXT_DAY LAST_DAY ROUND TRUNC  Add calendar months to date Next day of the date specified Last day of the month Round date  Truncate date Function Description
Using Date Functions ,[object Object],[object Object],[object Object],[object Object],19.6774194 '11-JUL-94' '08-SEP-95' '28-FEB-95'
Using Date Functions ,[object Object],[object Object],[object Object],[object Object],Assume  SYSDATE = '25-JUL-95' :
Practice 3, Part One: Overview ,[object Object],[object Object],[object Object],[object Object]
Conversion Functions Implicit data type conversion Explicit data type conversion Data type conversion
Implicit Data Type Conversion ,[object Object],[object Object],VARCHAR2 or CHAR From To VARCHAR2 or CHAR NUMBER DATE NUMBER DATE VARCHAR2 VARCHAR2
Implicit Data Type Conversion ,[object Object],[object Object],VARCHAR2 or CHAR From To VARCHAR2 or CHAR NUMBER DATE
Explicit Data Type Conversion NUMBER CHARACTER TO_CHAR TO_NUMBER DATE TO_CHAR TO_DATE
Explicit Data Type Conversion NUMBER CHARACTER TO_CHAR TO_NUMBER DATE TO_CHAR TO_DATE
Explicit Data Type Conversion NUMBER CHARACTER TO_CHAR TO_NUMBER DATE TO_CHAR TO_DATE
Using the  TO_CHAR  Function with Dates ,[object Object],[object Object],[object Object],[object Object],[object Object],TO_CHAR( date,  ' format_model ')
Elements of the Date Format Model YYYY YEAR MM MONTH DY DAY Full year in numbers Year spelled out Two-digit value for month Three-letter abbreviation of the day of the week Full name of the day of the week Full name of the month MON Three-letter abbreviation of the month DD Numeric day of the month
 
Elements of the Date Format Model ,[object Object],[object Object],[object Object],HH24:MI:SS AM 15:45:32 PM DD "of" MONTH 12 of OCTOBER ddspth fourteenth
 
Using the  TO_CHAR  Function with Dates SELECT last_name, TO_CHAR(hire_date, 'fmDD Month YYYY') AS HIREDATE FROM  employees; …
Using the  TO_CHAR  Function with Numbers ,[object Object],TO_CHAR( number,  ' format_model ') 9 0 $ L . , Represents a number Forces a zero to be displayed Places a floating dollar sign Uses the floating local currency symbol Prints a decimal point Prints a thousand indicator
Using the  TO_CHAR  Function with Numbers SELECT TO_CHAR(salary, '$99,999.00') SALARY FROM  employees WHERE  last_name = 'Ernst';
Using the  TO_NUMBER  and  TO_DATE  Functions  ,[object Object],[object Object],[object Object],TO_NUMBER( char [ ,  ' format_model ']) TO_DATE( char [, ' format_model '])
Using the  TO_NUMBER  and  TO_DATE  Functions  ,[object Object],[object Object],[object Object],TO_NUMBER( char [ ,  ' format_model ']) TO_DATE( char [, ' format_model '])
RR Date Format Current Year 1995 1995 2001 2001 Specified Date 27-OCT-95 27-OCT-17 27-OCT-17 27-OCT-95 RR Format 1995 2017 2017 1995 YY Format 1995 1917 2017 2095 If two digits of the current  year are: 0–49 0–49 50–99 50–99 The return date is in the current century The return date is in the century after the current one The return date is in the century before the current one The return date is in the current century If the specified two-digit year is:
Example of  RR  Date Format ,[object Object],[object Object],[object Object],SELECT last_name, TO_CHAR(hire_date, 'DD-Mon-YYYY') FROM  employees WHERE hire_date < TO_DATE('01-Jan-90', 'DD-Mon-RR');
Nesting Functions ,[object Object],[object Object],F3 (F2 (F1(col,arg1) ,arg2) , arg3) Step 1 = Result 1 Step 2 = Result 2 Step 3 = Result 3
Nesting Functions SELECT last_name, NVL(TO_CHAR(manager_id), 'No Manager') FROM  employees WHERE  manager_id IS NULL;
General Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
NVL  Function ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using the  NVL  Function SELECT last_name, salary, NVL(commission_pct, 0), (salary*12) + (salary*12*NVL(commission_pct, 0)) AN_SAL FROM employees; … 1 2 1 2
Using the  NVL2  Function SELECT last_name,  salary, commission_pct, NVL2(commission_pct,  'SAL+COMM', 'SAL') income FROM  employees WHERE department_id IN (50, 80); 1 2 1 2
Using the  NULLIF  Function SELECT first_name, LENGTH(first_name) &quot;expr1&quot;,  last_name,  LENGTH(last_name)  &quot;expr2&quot;, NULLIF(LENGTH(first_name), LENGTH(last_name)) result FROM  employees; … 1 2 3 1 2 3
Using the  COALESCE  Function ,[object Object],[object Object]
Using the  COALESCE  Function SELECT  last_name, COALESCE(commission_pct, salary, 10) comm FROM  employees ORDER BY commission_pct; …
Conditional Expressions ,[object Object],[object Object],[object Object],[object Object]
The  CASE  Expression ,[object Object],[object Object],CASE  expr  WHEN  comparison_expr1  THEN  return_expr1 [WHEN  comparison_expr2  THEN  return_expr2 WHEN  comparison_exprn  THEN  return_exprn ELSE  else_expr ] END
Using the  CASE  Expression ,[object Object],[object Object],SELECT last_name, job_id, salary, CASE job_id WHEN 'IT_PROG'  THEN  1.10*salary WHEN 'ST_CLERK' THEN  1.15*salary WHEN 'SA_REP'  THEN  1.20*salary ELSE  salary END  &quot;REVISED_SALARY&quot; FROM  employees; … …
The  DECODE  Function ,[object Object],DECODE( col|expression, search1, result1    [ , search2, result2,..., ]   [ , default ])
Using the  DECODE  Function SELECT last_name, job_id, salary, DECODE(job_id, 'IT_PROG',  1.10*salary, 'ST_CLERK', 1.15*salary, 'SA_REP',  1.20*salary, salary) REVISED_SALARY FROM  employees; … …
Using the  DECODE  Function ,[object Object],SELECT last_name, salary, DECODE (TRUNC(salary/2000, 0), 0, 0.00, 1, 0.09, 2, 0.20, 3, 0.30, 4, 0.40, 5, 0.42, 6, 0.44, 0.45) TAX_RATE FROM  employees WHERE  department_id = 80;
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Practice 3, Part Two: Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Más contenido relacionado

La actualidad más candente

Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...Meghaj Mallick
 
Structured query language functions
Structured query language functionsStructured query language functions
Structured query language functionsVineeta Garg
 
Sap script system_symbol
Sap script system_symbolSap script system_symbol
Sap script system_symbolmoderngladiator
 
Numeric functions in SQL | Oracle
Numeric functions in SQL | OracleNumeric functions in SQL | Oracle
Numeric functions in SQL | OracleVimal Raj
 
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Raj vardhan
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functionssinhacp
 
Use Cases of Row Pattern Matching in Oracle 12c
Use Cases of Row Pattern Matching in Oracle 12cUse Cases of Row Pattern Matching in Oracle 12c
Use Cases of Row Pattern Matching in Oracle 12cGerger
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Finalmukesh24pandey
 
Visual Basic Codes And Screen Designs
Visual Basic Codes And Screen DesignsVisual Basic Codes And Screen Designs
Visual Basic Codes And Screen Designsprcastano
 
Aggregate Function - Database
Aggregate Function - DatabaseAggregate Function - Database
Aggregate Function - DatabaseShahadat153031
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functionsMudasir Syed
 

La actualidad más candente (20)

Sql functions
Sql functionsSql functions
Sql functions
 
Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...Reference Parameter, Passing object by reference, constant parameter & Defaul...
Reference Parameter, Passing object by reference, constant parameter & Defaul...
 
Structured query language functions
Structured query language functionsStructured query language functions
Structured query language functions
 
Sap script system_symbol
Sap script system_symbolSap script system_symbol
Sap script system_symbol
 
Les07
Les07Les07
Les07
 
Numeric functions in SQL | Oracle
Numeric functions in SQL | OracleNumeric functions in SQL | Oracle
Numeric functions in SQL | Oracle
 
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
Use Cases of Row Pattern Matching in Oracle 12c
Use Cases of Row Pattern Matching in Oracle 12cUse Cases of Row Pattern Matching in Oracle 12c
Use Cases of Row Pattern Matching in Oracle 12c
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Final
 
C++ Functions
C++ FunctionsC++ Functions
C++ Functions
 
C++ functions
C++ functionsC++ functions
C++ functions
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek SharmaIntroduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
 
Visual Basic Codes And Screen Designs
Visual Basic Codes And Screen DesignsVisual Basic Codes And Screen Designs
Visual Basic Codes And Screen Designs
 
Aggregate Function - Database
Aggregate Function - DatabaseAggregate Function - Database
Aggregate Function - Database
 
C++ functions
C++ functionsC++ functions
C++ functions
 
Aggregate function
Aggregate functionAggregate function
Aggregate function
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
PHP mysql Aggregate functions
PHP mysql Aggregate functionsPHP mysql Aggregate functions
PHP mysql Aggregate functions
 

Destacado (9)

Les06
Les06Les06
Les06
 
Les19
Les19Les19
Les19
 
Les04
Les04Les04
Les04
 
Les05
Les05Les05
Les05
 
Les08
Les08Les08
Les08
 
Les20
Les20Les20
Les20
 
Les02
Les02Les02
Les02
 
Advanced functions in PL SQL
Advanced functions in PL SQLAdvanced functions in PL SQL
Advanced functions in PL SQL
 
Oracle sql developer_slides
Oracle sql developer_slidesOracle sql developer_slides
Oracle sql developer_slides
 

Similar a Les03

Similar a Les03 (20)

Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)Les03 (Using Single Row Functions To Customize Output)
Les03 (Using Single Row Functions To Customize Output)
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Les03 Single Row Function
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize output
 
Les03
Les03Les03
Les03
 
Les03 Single Row Functions in Oracle and SQL.ppt
Les03 Single Row Functions in Oracle and SQL.pptLes03 Single Row Functions in Oracle and SQL.ppt
Les03 Single Row Functions in Oracle and SQL.ppt
 
Les03
Les03Les03
Les03
 
Single-Row Functions in orcale Data base
Single-Row Functions in orcale Data baseSingle-Row Functions in orcale Data base
Single-Row Functions in orcale Data base
 
Intro to tsql unit 10
Intro to tsql   unit 10Intro to tsql   unit 10
Intro to tsql unit 10
 
SAS functions.pptx
SAS functions.pptxSAS functions.pptx
SAS functions.pptx
 
Les03[1] Single-Row Functions
Les03[1] Single-Row FunctionsLes03[1] Single-Row Functions
Les03[1] Single-Row Functions
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle Sql
 
2 sql - single-row functions
2   sql - single-row functions2   sql - single-row functions
2 sql - single-row functions
 
SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3
 
Les03.pptx
Les03.pptxLes03.pptx
Les03.pptx
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Sql 3
Sql 3Sql 3
Sql 3
 
Sterling Integrator Map Editor
Sterling Integrator Map EditorSterling Integrator Map Editor
Sterling Integrator Map Editor
 
Chinabankppt
ChinabankpptChinabankppt
Chinabankppt
 

Más de Vijay Kumar (10)

Les18
Les18Les18
Les18
 
Les17
Les17Les17
Les17
 
Les15
Les15Les15
Les15
 
Les16
Les16Les16
Les16
 
Les14
Les14Les14
Les14
 
Les13
Les13Les13
Les13
 
Les12
Les12Les12
Les12
 
Les10
Les10Les10
Les10
 
Les11
Les11Les11
Les11
 
Les09
Les09Les09
Les09
 

Último

IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsSafe Software
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 

Último (20)

IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration WorkflowsIgniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 

Les03

  • 2.
  • 3. SQL Functions Function Function performs action Input arg 1 arg 2 arg n Output Result value
  • 4. Two Types of SQL Functions Functions Single-row functions Multiple-row functions
  • 5.
  • 6. Single-Row Functions Conversion Character Number Date General Single-row functions
  • 7. Character Functions Character functions LOWER UPPER INITCAP CONCAT SUBSTR LENGTH INSTR LPAD | RPAD TRIM REPLACE Case-manipulation functions Character-manipulation functions
  • 8. Character Functions Character functions LOWER UPPER INITCAP CONCAT SUBSTR LENGTH INSTR LPAD | RPAD TRIM REPLACE Case-manipulation functions Character-manipulation functions
  • 9.
  • 10.
  • 11.
  • 12. Using the Character-Manipulation Functions SELECT employee_id, CONCAT(first_name, last_name) NAME, job_id, LENGTH (last_name), INSTR(last_name, 'a') &quot;Contains 'a'?&quot; FROM employees WHERE SUBSTR(job_id, 4) = 'REP'; 1 2 3 1 2 3
  • 13.
  • 14. Using the ROUND Function SELECT ROUND(45.923,2), ROUND(45.923,0), ROUND(45.923,-1) FROM DUAL; DUAL is a dummy table you can use to view results from functions and calculations. 1 2 3 3 1 2
  • 15. Using the TRUNC Function SELECT TRUNC(45.923,2), TRUNC(45.923), TRUNC(45.923,-2) FROM DUAL; 3 1 2 1 2 3
  • 16.
  • 17.
  • 18.
  • 19.
  • 20. Using Arithmetic Operators with Dates SELECT last_name, (SYSDATE-hire_date)/7 AS WEEKS FROM employees WHERE department_id = 90;
  • 21. Date Functions Number of months between two dates MONTHS_BETWEEN ADD_MONTHS NEXT_DAY LAST_DAY ROUND TRUNC Add calendar months to date Next day of the date specified Last day of the month Round date Truncate date Function Description
  • 22.
  • 23.
  • 24.
  • 25. Conversion Functions Implicit data type conversion Explicit data type conversion Data type conversion
  • 26.
  • 27.
  • 28. Explicit Data Type Conversion NUMBER CHARACTER TO_CHAR TO_NUMBER DATE TO_CHAR TO_DATE
  • 29. Explicit Data Type Conversion NUMBER CHARACTER TO_CHAR TO_NUMBER DATE TO_CHAR TO_DATE
  • 30. Explicit Data Type Conversion NUMBER CHARACTER TO_CHAR TO_NUMBER DATE TO_CHAR TO_DATE
  • 31.
  • 32. Elements of the Date Format Model YYYY YEAR MM MONTH DY DAY Full year in numbers Year spelled out Two-digit value for month Three-letter abbreviation of the day of the week Full name of the day of the week Full name of the month MON Three-letter abbreviation of the month DD Numeric day of the month
  • 33.  
  • 34.
  • 35.  
  • 36. Using the TO_CHAR Function with Dates SELECT last_name, TO_CHAR(hire_date, 'fmDD Month YYYY') AS HIREDATE FROM employees; …
  • 37.
  • 38. Using the TO_CHAR Function with Numbers SELECT TO_CHAR(salary, '$99,999.00') SALARY FROM employees WHERE last_name = 'Ernst';
  • 39.
  • 40.
  • 41. RR Date Format Current Year 1995 1995 2001 2001 Specified Date 27-OCT-95 27-OCT-17 27-OCT-17 27-OCT-95 RR Format 1995 2017 2017 1995 YY Format 1995 1917 2017 2095 If two digits of the current year are: 0–49 0–49 50–99 50–99 The return date is in the current century The return date is in the century after the current one The return date is in the century before the current one The return date is in the current century If the specified two-digit year is:
  • 42.
  • 43.
  • 44. Nesting Functions SELECT last_name, NVL(TO_CHAR(manager_id), 'No Manager') FROM employees WHERE manager_id IS NULL;
  • 45.
  • 46.
  • 47. Using the NVL Function SELECT last_name, salary, NVL(commission_pct, 0), (salary*12) + (salary*12*NVL(commission_pct, 0)) AN_SAL FROM employees; … 1 2 1 2
  • 48. Using the NVL2 Function SELECT last_name, salary, commission_pct, NVL2(commission_pct, 'SAL+COMM', 'SAL') income FROM employees WHERE department_id IN (50, 80); 1 2 1 2
  • 49. Using the NULLIF Function SELECT first_name, LENGTH(first_name) &quot;expr1&quot;, last_name, LENGTH(last_name) &quot;expr2&quot;, NULLIF(LENGTH(first_name), LENGTH(last_name)) result FROM employees; … 1 2 3 1 2 3
  • 50.
  • 51. Using the COALESCE Function SELECT last_name, COALESCE(commission_pct, salary, 10) comm FROM employees ORDER BY commission_pct; …
  • 52.
  • 53.
  • 54.
  • 55.
  • 56. Using the DECODE Function SELECT last_name, job_id, salary, DECODE(job_id, 'IT_PROG', 1.10*salary, 'ST_CLERK', 1.15*salary, 'SA_REP', 1.20*salary, salary) REVISED_SALARY FROM employees; … …
  • 57.
  • 58.
  • 59.

Notas del editor

  1. Schedule: Timing Topic 55 minutes Lecture 30 minutes Practice 85 minutes Total