首页 ORACLE培训教程4 _sql语言简介

ORACLE培训教程4 _sql语言简介

举报
开通vip

ORACLE培训教程4 _sql语言简介ORACLE培训教程4 _sql语言简介 SQL语言简介 1、 SQL概述 SQL是一种面向数据库的通用数据处理语言规范,能完成以下几类功能:提取查询数据,插入修改删除数据,生成修改和删除数据库对象,数据库安全控制,数据库完整性及数据保护控制。 数据库对象包括表、视图、索引、同义词、簇、触发器、函数、过程、包、数据库链、快照等(表空间、回滚段、角色、用户)。数据库通过对表的操作来管理存储在其中的数据。 1) SQL*PLUS界面: 登录:输入SQLPLUS回车;输入正确的ORACLE用户名并回车;输入用...

ORACLE培训教程4 _sql语言简介
ORACLE 培训 焊锡培训资料ppt免费下载焊接培训教程 ppt 下载特设培训下载班长管理培训下载培训时间表下载 教程4 _sql语言简介 SQL语言简介 1、 SQL概述 SQL是一种面向数据库的通用数据处理语言 规范 编程规范下载gsp规范下载钢格栅规范下载警徽规范下载建设厅规范下载 ,能完成以下几类功能:提取查询数据,插入修改删除数据,生成修改和删除数据库对象,数据库安全控制,数据库完整性及数据保护控制。 数据库对象包括表、视图、索引、同义词、簇、触发器、函数、过程、包、数据库链、快照等(表空间、回滚段、角色、用户)。数据库通过对表的操作来管理存储在其中的数据。 1) SQL*PLUS界面: 登录:输入SQLPLUS回车;输入正确的ORACLE用户名并回车;输入用户口令并回车,显示提示符:SQL> 退出:输入EXIT即可。 2)命令的编辑与运行: , 在命令提示符后输入SQL命令并运行,以分号结束输入;以斜杠结束输入;以空行结束输入; , 利用SQL缓冲区进行PL/SQL块的编辑和运行; , 利用命令文件进行PL/SQL块的编辑和运行。 2、 数据库查询 1) 用SELECT语句从表中提取查询数据。语法为 SELECT [DISTINCT] {column1,column2,…} FROM tablename WHERE {conditions} GROUP BY {conditions} ORDER BY {expressions} [ASC/DESC]; 说明:SELECT子句用于指定检索数据库的中哪些列,FROM子句用于指定从哪一个表或视图中检索数据。 2) SELECT中的操作符及多表查询WHERE子句。(LIKE,IS,…) WHERE子句中的条件可以是一个包含等号或不等号的条件表达式,也可以是一个含有IN、NOT IN、BETWEEN、LIKE、IS NOT NULL等比较运算符的条件式,还可以是由单一的条件表达通过逻辑运算符组合成复合条件。 ) ORDER BY 子句 3 ORDER BY 子句使得SQL在显示查询结果时将各返回行按顺序排列,返回行的排列顺序由ORDER BY 子句指定的表达式的值确定。 4) 连接查询 利用SELECT语句进行数据库查询时,可以把多个表、视图的数据结合起来,使得查询结果的每一行中包含来自多个表达式或视图的数据,这种操作被称为连接查询。 连接查询的方法是在SELECT命令的FROM子句中指定两个或多个将被连接查询的表或视图,并且在WHERE子句告诉ORACLE如何把多个表的数据进行合并。根据WHERE子句中的条件表达式是等还是不等式,可以把连接查询分为等式连接和 of the audit. Fire is a combination of auditing in the field of law enforcement law enforcement job rotation and fire practice of law enforcement, in the promotion changed, retraining retired key timing synchronization in place audit mechanism, and conducive to self-urged self-restraint, the fire law enforcement, to protect themselves. 1.3 preventive fire-fighting urged the current fire law enforcement corruption involving cases of violating law enforcement has an upward trend, judging from national reports of complaints in recent years, reported cases reflect the fire law enforcement is over 50%. In addition, the multiple corruption cases, with a high incidence of leading cadres, a small number of leading cadres ' corruption, corrupt, power-for-money transaction, especially teams, group reporting increasing complaints involving the supervision of law enforcement jobs, bring great pressure to force honest and serious challenges. Meanwhile, team and Brigade levels bear an administrative license approval, administrative punishment, routine inspections and more than 95% of the amount, some fire staff handled a year go through legal instruments and thousands of contact hundreds of social units, once inside lax, their quality is not high, extremely easy to induce discipline and corruption. In practical operation, the fire law enforcement as "athletes" and "umpire" internal inspector, inspection, test and not enough problem touches not found to leading policymakers, deviate from system design, system implementation has to deal with. 2 building fire law 不等式连接。 5) 子查询 如果某一个SELECT命令(查询1)出现在另一个SQL命令(查询2)的一个子句中,则称查询1是查询2的子查询。 3、 基本数据类型(NUMBER,VARCHAR2,DATE) O RACEL支持下列内部数据类型: , VARCHAR2 变长字符串,最长为2000字符。 , NUMBER 数值型。 , LONG 变长字符数据,最长为2G字节。 , DATE 日期型。 , RAW 二进制数据,最长为255字节。 , LONG RAW 变长二进制数据,最长为2G字节。 , ROWID 二六进制串,表示表的行的唯一地址。 , CHAR 定长字符数据,最长为255。 4、 常用函数用法: 一个函数类似于一个算符,它操作数据项,返回一个结果。函数在格式上不同于算符,它个具有变元,可操作0个、一个、二个或多个变元,形式为: 函数名(变元,变元,…) 函数具有下列一般类形: , 单行函数 , 分组函数 1)单行函数对查询的表或视图的每一行返回一个结果行。它有数值函数,字符 函数,日期函数,转换函数等。 2)分组函数返回的结果是基于行组而不是单行,所以分组函数不同于单行函数。 在许多分组函数中可有下列选项: , DISTRNCT 该选项使分组函数只考虑变元表达式中的不同值。 , ALL该选项使分组函数考虑全部值,包含全部重复。 全部分组函数(除COUNT(*)外)忽略空值。如果具有分组函数的查询,没 有返回行或只有空值(分组函数的变元取值的行),则分组函数返回空值。 5、 数据操纵语言命令: 数据库操纵语言(DML)命令用于查询和操纵模式对象中的数据,它不隐式地提交当前事务。它包含UPDATE、INSERT、DELETE、EXPLAIN PLAN、SELECT和LOCK TABLE 等命令。下面简单介绍一下: 1) UPDATE tablename SET {column1=expression1,column2=expression2,…} WHERE {conditions}; 例如:S QL>UPDATE EMP SET JOB =’MANAGER’ of the audit. Fire is a combination of auditing in the field of law enforcement law enforcement job rotation and fire practice of law enforcement, in the promotion changed, retraining retired key timing synchronization in place audit mechanism, and conducive to self-urged self-restraint, the fire law enforcement, to protect themselves. 1.3 preventive fire-fighting urged the current fire law enforcement corruption involving cases of violating law enforcement has an upward trend, judging from national reports of complaints in recent years, reported cases reflect the fire law enforcement is over 50%. In addition, the multiple corruption cases, with a high incidence of leading cadres, a small number of leading cadres ' corruption, corrupt, power-for-money transaction, especially teams, group reporting increasing complaints involving the supervision of law enforcement jobs, bring great pressure to force honest and serious challenges. Meanwhile, team and Brigade levels bear an administrative license approval, administrative punishment, routine inspections and more than 95% of the amount, some fire staff handled a year go through legal instruments and thousands of contact hundreds of social units, once inside lax, their quality is not high, extremely easy to induce discipline and corruption. In practical operation, the fire law enforcement as "athletes" and "umpire" internal inspector, inspection, test and not enough problem touches not found to leading policymakers, deviate from system design, system implementation has to deal with. 2 building fire law WHERE ENAME=’MAPTIN’; SQL >SELECT * FROM EMP; UPDATE子句指明了要修改的数据库是EMP,并用WHERE子句限制了只对名字(ENAME)为’MARTIN’的职工的数据进行修改,SET子句则说明修改的方式,即把’MARTION’的工作名称(JOB)改为’MARAGER’. 2) INSERT INTO tablename {column1,column2,…} VALUES {expression1,expression2,…}; 例如:SQL>SELECT INTO DEPT(DNAME, DEPTNO) VALUES (‘ACCOUNTING’,10) 3) DELETE FROM tablename WHERE {conditions}; 例如:SQL>DELETE FROM EMP WHERE EMPNO = 7654; DELETE命令删除一条记录,而且DELETE命令只能删除整行,而不能删除某行中的部分数据. 4) 事务控制命令 设置AUTOCOMMIT为允许状提交命令(COMMIT):可以使数据库的修改永久化. 态:SQL >SET AUTOCOMMIT ON; 回滚命令(ROLLBACK):消除上一个COMMIT命令后的所做的全部修改,使得数据库的 内容 财务内部控制制度的内容财务内部控制制度的内容人员招聘与配置的内容项目成本控制的内容消防安全演练内容 恢复到上一个COMMIT执行后的状态.使用方法是: SQL>ROLLBACK; 5、 创建表、视图、索引、同义词、用户。 1)、表是存储用户数据的基本结构。 建立表主要指定义下列信息: , 列定义 , 完整性约束 , 表所在表空间 , 存储特性 , 可选择的聚集 , 从一查询获得数据 语法如下:CREATE TABLE tablename (column1 datatype [DEFAULT expression] [constraint], column1 datatype [DEFAULT expression] [constraint], ……) [STORAGE子句] [其他子句…]; 例如: SQL>CREATE TABLE NEW_DEPT (DPTNO NUMBER(2), of the audit. Fire is a combination of auditing in the field of law enforcement law enforcement job rotation and fire practice of law enforcement, in the promotion changed, retraining retired key timing synchronization in place audit mechanism, and conducive to self-urged self-restraint, the fire law enforcement, to protect themselves. 1.3 preventive fire-fighting urged the current fire law enforcement corruption involving cases of violating law enforcement has an upward trend, judging from national reports of complaints in recent years, reported cases reflect the fire law enforcement is over 50%. In addition, the multiple corruption cases, with a high incidence of leading cadres, a small number of leading cadres ' corruption, corrupt, power-for-money transaction, especially teams, group reporting increasing complaints involving the supervision of law enforcement jobs, bring great pressure to force honest and serious challenges. Meanwhile, team and Brigade levels bear an administrative license approval, administrative punishment, routine inspections and more than 95% of the amount, some fire staff handled a year go through legal instruments and thousands of contact hundreds of social units, once inside lax, their quality is not high, extremely easy to induce discipline and corruption. In practical operation, the fire law enforcement as "athletes" and "umpire" internal inspector, inspection, test and not enough problem touches not found to leading policymakers, deviate from system design, system implementation has to deal with. 2 building fire law DNAME CHAR(6), LOC CHAR(13); 更改表作用: , 增加列 , 增加完整性约束 , 重新定义列(数据类型、长度、缺省值) , 修改存储参数或其它参数 , 使能、使不能或删除一完整性约束或触发器 , 显式地分配一个范围 2)、视图 视图是一个逻辑表,它允许操作者从其它表或视图存取数据,视图本身不包含数 据。视图所基于的表称为基表。 引入视图有下列作用: , 提供附加的表安全级,限制存取基表的行或/和列集合。 , 隐藏数据复杂性。 , 为数据提供另一种观点。 , 促使ORACLE的某些操作在包含视图的数据库上执行,而不在另一个数据 库上执行。 3)、索引 索引是种数据库对象。对于在表或聚集的索引列上的每一值将包含一项,为行 提供直接的快速存取。在下列情况ORACLE可利用索引改进性能: , 按指定的索引列的值查找行。 , 按索引列的顺序存取表。 建立索引: CREATE [UNIQUE] INDEX indexname ON tablename(column ,。。。); 例如:SQL>CREAT INDEX IC_EMP ON CLUSTER EMPLOYEE 4)、同义词 同义词:为表、视图、序列、存储函数、包、快照或其它同义词的另一个名字。 使用同义词为了安全和方便。对一对象建立同义词可有下列好处: , 引用对象不需指出对象的持有者。 , 引用对象不需指出它所位于的数据库。 , 为对象提供另一个名字。 建立同义词: CREATE SYNONYM symnon_name FOR [username.]tablename; 例如:CREAT PUBLIC SYNONYM EMP FOR SCOTT.EMP @SALES 5)、用户 CREATE USER username IDENTIFIED BY password; 例如:SQL>CREATE USER SIDNEY IDENTIFIED BY CARTON ; of the audit. Fire is a combination of auditing in the field of law enforcement law enforcement job rotation and fire practice of law enforcement, in the promotion changed, retraining retired key timing synchronization in place audit mechanism, and conducive to self-urged self-restraint, the fire law enforcement, to protect themselves. 1.3 preventive fire-fighting urged the current fire law enforcement corruption involving cases of violating law enforcement has an upward trend, judging from national reports of complaints in recent years, reported cases reflect the fire law enforcement is over 50%. In addition, the multiple corruption cases, with a high incidence of leading cadres, a small number of leading cadres ' corruption, corrupt, power-for-money transaction, especially teams, group reporting increasing complaints involving the supervision of law enforcement jobs, bring great pressure to force honest and serious challenges. Meanwhile, team and Brigade levels bear an administrative license approval, administrative punishment, routine inspections and more than 95% of the amount, some fire staff handled a year go through legal instruments and thousands of contact hundreds of social units, once inside lax, their quality is not high, extremely easy to induce discipline and corruption. In practical operation, the fire law enforcement as "athletes" and "umpire" internal inspector, inspection, test and not enough problem touches not found to leading policymakers, deviate from system design, system implementation has to deal with. 2 building fire law Oracle扩展PL/SQL简介 1、 PL/SQL概述。 PL/SQL是Oracle对SQL规范的扩展,是一种块结构语言,即构成一个PL/SQL程序的基本单位(过程、函数和无名块)是逻辑块,可包含任何数目的嵌套了快。这种程序结构支持逐步求精方法解决问题。一个块(或子块)将逻辑上相关的说明和语句组合在一起,其形式为: DECLARE ---说明 BEGIN ---语句序列 EXCEPTION ---例外处理程序 END; 它有以下优点: , 支持SQL; , 生产率高; , 性能好; , 可称植性; , 与ORACLE集成. 2、 PL/SQL体系结构 PL/SQL运行系统是种技术,不是一种独立产品,可认为这种技术是PL/SQL块和子程序的一种机,它可接收任何有效的PL/SQL块或子程序。如图所示: PL/SQL机 PL/SQL块 过程性语句 PL/SQL 块 执行器 SQL语句 PL/SQL机可执行过程性语句,而将SQL语句发送到ORACLE服务器上的SQL语句 执行器。在ORACLE预编译程序或OCI程序中可嵌入无名的PL/SQL块。如果 ORACLE具有PROCEDURAL选件,有名的PL/SQL块(子程序)可单独编译,永 久地存储在数据库中,准备执行。 of the audit. Fire is a combination of auditing in the field of law enforcement law enforcement job rotation and fire practice of law enforcement, in the promotion changed, retraining retired key timing synchronization in place audit mechanism, and conducive to self-urged self-restraint, the fire law enforcement, to protect themselves. 1.3 preventive fire-fighting urged the current fire law enforcement corruption involving cases of violating law enforcement has an upward trend, judging from national reports of complaints in recent years, reported cases reflect the fire law enforcement is over 50%. In addition, the multiple corruption cases, with a high incidence of leading cadres, a small number of leading cadres ' corruption, corrupt, power-for-money transaction, especially teams, group reporting increasing complaints involving the supervision of law enforcement jobs, bring great pressure to force honest and serious challenges. Meanwhile, team and Brigade levels bear an administrative license approval, administrative punishment, routine inspections and more than 95% of the amount, some fire staff handled a year go through legal instruments and thousands of contact hundreds of social units, once inside lax, their quality is not high, extremely easy to induce discipline and corruption. In practical operation, the fire law enforcement as "athletes" and "umpire" internal inspector, inspection, test and not enough problem touches not found to leading policymakers, deviate from system design, system implementation has to deal with. 2 building fire law 3、 PL/SQL基础: PL/SQL有一字符集、保留字、标点、数据类型、严密语法等,它与SQL有相同表示, 现重点介绍。 1)、数据类型:如下表所示 数据类型 子类型 BINARY_INTEGER NATURAL,POSITIVE 纯量数值 NUMBER DEC,DECIMAL,DOUBLE 类型 PRECISION,PLOAT,INTEGER,INT,N UMERIC,REAL,SMALLINT CHAR CHARACTER,STRING 字符 VARCHAR2 VARCHAR LONG LONG RAW RAW RAWID BOOLEAN 逻辑 DATE 日期 RECORD 组合 记录 TABLE 类型 表 2)、变量和常量 在PL/SQL程序中可将值存储在变量和常量中,当程序执行时,变量的值可以改 变,而常量的值不能改变。 3)、程序块式结构: DECLARE 变量说明部分; BEGIN 执行语句部分; [EXCEPTION 例外处理部分;] END; 4、 控制语句: 分支语句: IF condition THEN Sequence_of_statements; END IF; IF condition THEN Sequence_of_statement1; ELSE of the audit. Fire is a combination of auditing in the field of law enforcement law enforcement job rotation and fire practice of law enforcement, in the promotion changed, retraining retired key timing synchronization in place audit mechanism, and conducive to self-urged self-restraint, the fire law enforcement, to protect themselves. 1.3 preventive fire-fighting urged the current fire law enforcement corruption involving cases of violating law enforcement has an upward trend, judging from national reports of complaints in recent years, reported cases reflect the fire law enforcement is over 50%. In addition, the multiple corruption cases, with a high incidence of leading cadres, a small number of leading cadres ' corruption, corrupt, power-for-money transaction, especially teams, group reporting increasing complaints involving the supervision of law enforcement jobs, bring great pressure to force honest and serious challenges. Meanwhile, team and Brigade levels bear an administrative license approval, administrative punishment, routine inspections and more than 95% of the amount, some fire staff handled a year go through legal instruments and thousands of contact hundreds of social units, once inside lax, their quality is not high, extremely easy to induce discipline and corruption. In practical operation, the fire law enforcement as "athletes" and "umpire" internal inspector, inspection, test and not enough problem touches not found to leading policymakers, deviate from system design, system implementation has to deal with. 2 building fire law Sequence_of_statement2; END IF; IF condition1 THEN Sequence_of_statement1; ELSIF condition2 THEN Sequence_of_statement2; ELSIF condition3 THEN Sequence_of_statement3; END IF; 5、 循环语句: LOOP Sequence_of_statements; IF condition THEN EXIT; END IF; END LOOP; WHILE condition LOOP Sequence_of_statements; END LOOP; FOR counter IN lower_bound..higher_bound LOOP Sequence_of_statements; END LOOP; 6、 子程序: 存储过程: CREATE PROCEDURE 过程名 (参数说明1,参数说明2, 。。。) IS [局部说明] BEGIN 执行语句; END 过程名; 存储函数: CREATE FUNCTION 函数名 (参数说明1,参数说明2, 。。。) RETURN 类型 IS [局部说明] BEGIN 执行语句; END 函数名; of the audit. Fire is a combination of auditing in the field of law enforcement law enforcement job rotation and fire practice of law enforcement, in the promotion changed, retraining retired key timing synchronization in place audit mechanism, and conducive to self-urged self-restraint, the fire law enforcement, to protect themselves. 1.3 preventive fire-fighting urged the current fire law enforcement corruption involving cases of violating law enforcement has an upward trend, judging from national reports of complaints in recent years, reported cases reflect the fire law enforcement is over 50%. In addition, the multiple corruption cases, with a high incidence of leading cadres, a small number of leading cadres ' corruption, corrupt, power-for-money transaction, especially teams, group reporting increasing complaints involving the supervision of law enforcement jobs, bring great pressure to force honest and serious challenges. Meanwhile, team and Brigade levels bear an administrative license approval, administrative punishment, routine inspections and more than 95% of the amount, some fire staff handled a year go through legal instruments and thousands of contact hundreds of social units, once inside lax, their quality is not high, extremely easy to induce discipline and corruption. In practical operation, the fire law enforcement as "athletes" and "umpire" internal inspector, inspection, test and not enough problem touches not found to leading policymakers, deviate from system design, system implementation has to deal with. 2 building fire law
本文档为【ORACLE培训教程4 _sql语言简介】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_083599
暂无简介~
格式:doc
大小:49KB
软件:Word
页数:0
分类:生活休闲
上传时间:2017-10-22
浏览量:14