版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年中能建绿色数字科技(庆阳)有限公司招聘笔试备考试题及答案解析
- 2026年泰和县康寿养老服务有限公司面向社会公开招聘工作人员考试模拟试题及答案解析
- 2026年济宁嘉祥县事业单位公开招聘工作人员 (教育类)(27人)笔试备考试题及答案解析
- 2026西昌人力资源开发有限公司凉山交城建设有限责任公司建设项目招聘2名笔试模拟试题及答案解析
- 2026年及未来5年市场数据中国温泉旅游开发市场调查研究及行业投资潜力预测报告
- 品牌授权补充协议
- 新人教版二年级下册数学第一单元同步课时练习(二)
- 2026山西忻州市定襄县招聘易地搬迁后扶工作公益性岗位4人考试模拟试题及答案解析
- 交换机务员岗前管理应用考核试卷含答案
- 转化膜工创新实践强化考核试卷含答案
- T-ZGCMCA 007-2024 国家工业互联网大数据中心体系 产业链编码规则
- 淋浴器安装施工方案
- 2025年陕西省中考化学试卷真题(含答案)
- DB32/T 3582-2019水运工程水泥土搅拌桩复合地基质量检测及评定规程
- DB37-T2118-2025高温熔融金属道路运输安全技术要求
- 常见的逻辑谬误分析试题及答案
- 商铺租赁协议
- 钢结构墙板拆除施工方案
- 第十一章-中国古代史学课件
- 全国统一市政工程预算定额
- 智能可穿戴服装研究
评论
0/150
提交评论