版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Using Single-Row Functions to Customize Output ObjectivesAfter completing this lesson, you should be able to do the following:Describe various types of functions available in SQLUse character, number, and date functions in SELECT statementsLesson AgendaSingle-row SQL functionsCharacter functionsNumb
2、er functionsWorking with datesDate functionsSQL FunctionsFunctionInputarg 1arg 2arg nFunction performs actionOutputResultvalueTwo Types of SQL FunctionsSingle-row functionsMultiple-rowfunctionsReturn one result per rowReturn one result per set of rowsFunctionsSingle-Row FunctionsSingle-row functions
3、:Manipulate data itemsAccept arguments and return one valueAct on each row that is returnedReturn one result per rowMay modify the data typeCan be nestedAccept arguments that can be a column or an expressionfunction_name (arg1, arg2,.)Single-Row FunctionsConversionCharacterNumberDateGeneralSingle-ro
4、w functionsLesson AgendaSingle-row SQL functionsCharacter functionsNumber functionsWorking with datesDate functionsCharacter FunctionsCharacterfunctionsLOWERUPPERINITCAPCONCATSUBSTRLENGTHINSTRLPAD | RPADTRIMREPLACECase-conversion functionsCharacter-manipulationfunctionsCase-Conversion FunctionsThese
5、 functions convert the case for character strings:sql courseLOWER(SQL Course)Sql CourseINITCAP(SQL Course)SQL COURSEUPPER(SQL Course)ResultFunctionSELECT employee_id, last_name, department_idFROM employeesWHERE LOWER(last_name) = higgins;Using Case-Conversion FunctionsDisplay the employee number, na
6、me, and department number for employee Higgins:SELECT employee_id, last_name, department_idFROM employeesWHERE last_name = higgins;Character-Manipulation FunctionsThese functions manipulate character strings:BLACK and BLUE REPLACE(JACK and JUE,J,BL) 10LENGTH(HelloWorld)6INSTR(HelloWorld, W)*24000LPA
7、D(salary,10,*)24000*RPAD(salary, 10, *)HelloWorldCONCAT(Hello, World)elloWorldTRIM(H FROM HelloWorld)HelloSUBSTR(HelloWorld,1,5)ResultFunctionSELECT employee_id, CONCAT(first_name, last_name) NAME, job_id, LENGTH (last_name), INSTR(last_name, a) Contains a?FROM employeesWHERE SUBSTR(job_id, 4) = REP
8、;Using the Character-Manipulation Functions231213Lesson AgendaSingle-row SQL functionsCharacter functionsNumber functionsWorking with datesDate FunctionsNumber FunctionsROUND: Rounds value to a specified decimalTRUNC: Truncates value to a specified decimalMOD: Returns remainder of division100MOD(160
9、0, 300)45.93ROUND(45.926, 2)45.92TRUNC(45.926, 2)ResultFunctionSELECT ROUND(45.923,2), ROUND(45.923,0), ROUND(45.923,-1)FROM DUAL;Using the ROUND FunctionDUAL is a dummy table that you can use to view results from functions and calculations.331212Using the TRUNC FunctionSELECT TRUNC(45.923,2), TRUNC
10、(45.923), TRUNC(45.923,-1)FROM DUAL;331212SELECT last_name, salary, MOD(salary, 5000)FROM employeesWHERE job_id = SA_REP;Using the MOD FunctionFor all employees with the job title of Sales Representative, calculate the remainder of the salary after it is divided by 5,000.Lesson AgendaSingle-row SQL
11、functionsCharacter functionsNumber functionsWorking with datesDate functionsSELECT last_name, hire_dateFROM employeesWHERE hire_date 01-FEB-88;Working with DatesThe Oracle database stores dates in an internal numeric format: century, year, month, day, hours, minutes, and seconds.The default date dis
12、play format is DD-MON-RR.Enables you to store 21st-century dates in the 20th century by specifying only the last two digits of the yearEnables you to store 20th-century dates in the21st century in the same wayRR Date FormatCurrent Year1995199520012001 27-OCT-9527-OCT-1727-OCT-1727-OCT-95 19952017201
13、71995 1995191720172095If two digits of the current year are:04904950995099The return date is in the current centuryThe return date is in the century after the current oneThe return date is in the century before the current oneThe return date is in the current centuryIf the specified two-digit year i
14、s:YY FormatRR FormatSpecified DateCurrent YearUsing the SYSDATE FunctionSYSDATE is a function that returns:DateTimeSELECT sysdateFROM dual;Arithmetic with DatesAdd or subtract a number to or from a date for a resultant date value.Subtract two dates to find the number of days between those dates.Add
15、hours to a date by dividing the number of hours by 24.SELECT last_name, (SYSDATE-hire_date)/7 AS WEEKSFROM employeesWHERE department_id = 90;Using Arithmetic Operatorswith DatesLesson AgendaSingle-row SQL functionsCharacter functionsNumber functionsWorking with datesDate functionsDate-Manipulation F
16、unctionsNext day of the date specifiedNEXT_DAYLast day of the monthLAST_DAYRound dateROUNDTruncate dateTRUNCNumber of months between two datesMONTHS_BETWEENAdd calendar months to dateADD_MONTHSResultFunctionUsing Date Functions08-SEP-95NEXT_DAY (01-SEP-95,FRIDAY)28-FEB-95LAST_DAY (01-FEB-95)19.67741
17、94MONTHS_BETWEEN (01-SEP-95,11-JAN-94)29-FEB-96ADD_MONTHS (31-JAN-96,1)ResultFunctionUsing ROUND and TRUNC Functions with DatesAssume SYSDATE = 25-JUL-03:01-JUL-03TRUNC(SYSDATE ,MONTH)01-JAN-03TRUNC(SYSDATE ,YEAR)01-AUG-03ROUND(SYSDATE,MONTH)01-JAN-04ROUND(SYSDATE ,YEAR)ResultFunctionSummaryIn this lesson, you should have learned how to:Perform calculations on data using functionsModify individual data item
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 高三年级地理最后30天冲刺复习教学设计-以山东省高考地理核心题型增分策略为中心
- 高二化学选择性必修3 醛的结构与性质 教学设计
- 高中英语选择性必修第四册Unit 2 Iconic Attractions Using Language教学设计
- 初中九年级化学教学设计:物质分类与化合价化学式专题突破
- 高中体育与健康教案:排球正面屈体扣球技术教学设计
- 初中九年级化学燃烧条件探究实验教学设计
- 九年级数学《二次函数应用中的其他问题》教学设计
- 人教版九年级数学上册 30.1.1 直线与圆的位置关系 教学设计
- 七年级科学《制造技术与工程》单元复习教学设计
- 小学三年级道德与法治“我们的节日·重阳”主题班会教学设计
- 老年多病共存管理课件
- 第一单元第2课《缤纷的世界美术流派》教学课件-2025-2026学年人美版(2024)初中美术八年级上册
- 建筑工程技术专业毕业论文
- 分布式光伏政策解读课件
- 航天质量管理课件
- 农村初中生大五人格与生命意义感的内在关联探究
- DB42T 1227-2016 全轻混凝土建筑地面保温工程技术规程
- 旅游规划设计管理制度
- FZ∕T 61002-2019 化纤仿毛毛毯
- 《直流工程深井接地极技术导则》(V1)
- CJJ-T 135-2009 (2023年版) 透水水泥混凝土路面技术规程
评论
0/150
提交评论