版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Retrieving Data Using the SQL SELECT StatementObjectivesAfter completing this lesson, you should be able to do the following:List the capabilities of SQL SELECT statementsExecute a basic SELECT statementLesson AgendaBasic SELECT statementArithmetic expressions and NULL values in the SELECT statement
2、Column aliasesUse of concatenation operator, literal character strings, alternative quote operator, and the DISTINCT keywordDESCRIBE commandCapabilities of SQL SELECT StatementsSelectionProjectionTable 1Table 2Table 1Table 1JoinBasic SELECT StatementSELECT identifies the columns to be displayed.FROM
3、 identifies the table containing those columns.SELECT *|DISTINCT column|expression alias,.FROM table;Selecting All ColumnsSELECT *FROM departments;Selecting Specific ColumnsSELECT department_id, location_idFROM departments;Writing SQL StatementsSQL statements are not case sensitive.SQL statements ca
4、n be entered on one or more lines.Keywords cannot be abbreviated or split across lines.Clauses are usually placed on separate lines.Indents are used to enhance readability.In SQL Developer, SQL statements can be optionally terminated by a semicolon (;). Semicolons are required when you execute multi
5、ple SQL statements.In SQL*Plus, you are required to end each SQL statement with a semicolon (;).Column Heading DefaultsSQL Developer:Default heading alignment: Left-alignedDefault heading display: UppercaseSQL*Plus:Character and Date column headings are left-aligned.Number column headings are right-
6、aligned.Default heading display: UppercaseLesson AgendaBasic SELECT statementArithmetic expressions and NULL values in the SELECT statementColumn AliasesUse of concatenation operator, literal character strings, alternative quote operator, and the DISTINCT keywordDESCRIBE commandArithmetic Expression
7、sCreate expressions with number and date data by using arithmetic operators.Multiply*Divide/Subtract-Add+DescriptionOperatorSELECT last_name, salary, salary + 300FROM employees;Using Arithmetic OperatorsSELECT last_name, salary, 12*salary+100FROM employees;Operator PrecedenceSELECT last_name, salary
8、, 12*(salary+100)FROM employees;12注:题17 Defining a Null ValueNull is a value that is unavailable, unassigned, unknown, or inapplicable.Null is not the same as zero or a blank space.SELECT last_name, job_id, salary, commission_pctFROM employees; SELECT last_name, 12*salary*commission_pctFROM employee
9、s;Null Values in Arithmetic ExpressionsArithmetic expressions containing a null value evaluate to null.Lesson AgendaBasic SELECT statementArithmetic expressions and NULL values in the SELECT statementColumn aliasesUse of concatenation operator, literal character strings, alternative quote operator,
10、and the DISTINCT keywordDESCRIBE commandDefining a Column AliasA column alias:Renames a column headingIs useful with calculationsImmediately follows the column name (There can also be the optional AS keyword between the column name and the alias.)Requires double quotation marks if it contains spaces
11、 or special characters, or if it is case-sensitive Using Column AliasesSELECT last_name Name , salary*12 Annual SalaryFROM employees;SELECT last_name AS name, commission_pct commFROM employees;注:题12、题15Lesson AgendaBasic SELECT StatementArithmetic Expressions and NULL values in SELECT statementColum
12、n AliasesUse of concatenation operator, literal character strings, alternative quote operator, and the DISTINCT keywordDESCRIBE commandConcatenation OperatorA concatenation operator:Links columns or character strings to other columnsIs represented by two vertical bars (|)Creates a resultant column t
13、hat is a character expressionSELECTlast_name|job_id AS EmployeesFROM employees;Literal Character StringsA literal is a character, a number, or a date that is included in the SELECT statement.Date and character literal values must be enclosed within single quotation marks.Each character string is out
14、put once for each row returned.Using Literal Character StringsSELECT last_name | is a |job_id AS Employee DetailsFROM employees;Alternative Quote (q) OperatorSpecify your own quotation mark delimiter.Select any delimiter.Increase readability and usability.SELECT department_name | q Departments Manag
15、er Id: | manager_id AS Department and Manager FROM departments;注:题13Duplicate RowsThe default display of queries is all rows, including duplicate rows.SELECT department_idFROM employees;SELECT DISTINCT department_idFROM employees;12注:题14Lesson AgendaBasic SELECT statementArithmetic expressions and N
16、ULL values in the SELECT statementColumn aliasesUse of concatenation operator, literal character strings, alternative quote operator, and the DISTINCT keywordDESCRIBE commandDisplaying the Table StructureUse the DESCRIBE command to display the structure of a table.Or, select the table in the Connect
17、ions tree and use the Columns tab to view the table structure.DESCRIBE tablenameUsing the DESCRIBE CommandDESCRIBE employees QuizIdentify the SELECT statements that execute successfully.SELECT first_name, last_name, job_id, salary*12 AS Yearly SalFROM employees; SELECT first_name, last_name, job_id,
18、 salary*12 yearly salFROM employees; SELECT first_name, last_name, job_id, salary AS yearly salFROM employees;SELECT first_name+last_name AS name, job_Id, salary*12 yearly salFROM employees;SummaryIn this lesson, you should have learned how to:Write a SELECT statement that:Returns all rows and columns from a tableReturns specified columns from a tableUses column aliases to disp
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 信息安全事件应急响应指南
- 2026年注会会计金融工具核算模拟试卷及答案
- 物流配送服务流程与质量标准
- 2025年证券从业资格考试专业科目模拟测验试题及答案
- 企业市场营销团队建设与培训指南
- 民航服务质量管理规范(标准版)
- 房地产销售与客户服务操作手册(标准版)
- 水电安装与维护规范手册(标准版)
- 企业物流配送中心规划与设计手册(标准版)
- 航空食品制作与配送操作指南
- 2025年山西国企笔试题库及答案
- 招标文件编制细则与常见问题解析
- 水下机器人与海洋自动化:创新技术的前沿探索
- DLT 5142-2012 火力发电厂除灰设计技术规程
- DB3208∕T 162-2021 青虾池套养中华绒螯蟹养殖技术操作规程
- 2025餐饮创意菜品研发趋势研究及厨师IP化与出品标准化平衡报告
- 医院科室整改前后对比
- 海外机械设备管理制度
- 上海印象旅游城市介绍模板(免费下载)
- 文献检索与科技论文写作
- 社区工作者经典备考题库(必背300题)
评论
0/150
提交评论