------------------------Oracle 的SQL 语法--------------------------=======================第(1,2)章 结 合 语 句==========================》1:创建表空间create tablespace 表空间名datafile'存放文件的路径_空间名_.dbf' size 30m;》2: 分配权限grant 权限| 角色 to 用户名》3: 创建用户create user 登陆名 identified by 密码grant connect , resource to 登陆名》4:创建唯一索引create unique index index_列_empon on 表名 (列);》5:创建序列create sequence 自定义表名 start with 1 increment by 1;》6: 查看当前序列的值select seql.currval from 表名》7:创建私有同义词create synonym e(自己定义的一个) for 表名;》8: 创建共有同义词create public synonym e for 表名;》9: 给某个用户访问的权限,可以访问该同义词grant select on e to 用户名;》10: 创建大写函数索引Create index index_ename on 表名 (upper(列));》间隔分区create table 表名partition by range (列)interval (numtoyminterval(3,'month'))(partition p1 values less than (to_date ('2013-04-01','yyyy-mm-dd')))asselect * from 表名=====================第(3)章 的 SQL 语 句=======================================PL/SQL 块可执行部分 其中变量语法如下:》1:声明变量declarev_name varchar2(20);》2: 声明和赋值declarev_Names varchar2(20):='战三';》3:循环控制---------------(1)Loop循环语法:LoopEXIT Where ---条件满足,退出END Loop;-------------(2)WHILE 循环语法:WHILK Loop要执行的语法END Loop;》4:输出语句dbms_ output.put_line ('您要输出的内容 , ZZZ.....想睡觉了.....');》5: 游标声明,打开,提取,关闭 (例子)declarecursor em_cursor isselect 列 from 表名 where (条件);--声明两个变量v_name employee name%type;v_sal employee%type;beginopen em_cursor ;--打开游标loopfetch em_cursor into v_name,v_sal --提取游标(提取行)exit when em_cursor%notfound; --判断游标是否为空,就退出dbms_output.put_line(v_name||v_sal); --输出两个变量endloop; --循环提取close em_cursor; --关闭游标end;》6: 循环游标取数据for i in 游标名 loopdbms_output.put_line('用户信息:'||i.userid||'-------'||i.username);(直接 i 不可取 i为对象)end loop;=========================第(4)章 的 SQL 语 句=======================================》1: 通过游标修改数据declarecursor userinfo is select * from t_user for update;v_name varchar2(50);beginfor i in userinfo loopv_name :=i.username;update t_user set username='王五' where current of userinfo;dbms_output.put_line('用户信息:'||i.userid||'-------'||i.username);end loop;commit;end;》2: 创建存储过程create or replace procedure usertestiscursor userinfo is select * from t_user;beginfor i in userinfo loopdbms_output.put_line('用户信息:'||i.userid||'-------'||i.username);end loop;end;》3: 调用存储过程exec usertest;call usertest();beginusertest;end;》4: 存储过程修改数据create or replace procedure usertest(v_name varchar2)isbeginupdate t_user set username=v_name where userid=1;if v_name is null then raisecommit;exceptionwhen others then rollback;end;exec usertest('zhangsan');》5: 过程中的参数--在过程中,in修饰的参数,不允许在过程中给它赋值create or replace procedure usertest(v_name in varchar2,v_pwd out varchar2,v_show in out varchar2)isv_hello varchar2(50);begin-- v_name := 'name';v_pwd := 'pwd';v_show := 'show';v_hello := 'hello';dbms_output.put_line('信息:'||v_name||'-------'||v_pwd||'-------'||v_show||'-------'||v_hello);end;declarevp varchar2(50);vs varchar2(50);beginvs := 'cccccc';usertest('aaaaaaa',vp,vs);end;》5: 存储过程的语法create or replace procedure 过程的名字(参数1 in/out 没有长度的类型,参数2 in/out 没有长度的类型) is过程中需要用的参数名 可以指定长度的类型;begin过程的内容end;》6: 变量的类型的另外一种写法--in传递的参数,长度由外部控制--out传递的参数,长度由内部控制create or replace procedure usertest(v_name in t_user.username%type,v_num in t_user.userid%type)isv_hello t_user.username%type;beginv_hello := 'hello';dbms_output.put_line('信息:'||v_name||'-------'||v_num||'-------'||v_hello);end;declarevp varchar2(50);vs number;beginvs :=11111111111111111111;usertest('aaaaaaa',vs);end;》7: 定义外部变量var vnum number;var vid number;var vname varchar2(50);exec :vnum:=23;exec :vid:=4;exec :vname:='wangwu';exec userinfo(:vid,:vname,:vnum);create or replace procedure userinfo(vid t_user.userid%type,vname t_user.username%type,vnum out t_user.userid%type)isbeginvnum :=vid;dbms_output.put_line('信息:'||vid||'-------'||vname||'--------'||vnum);end;》 8: 创建函数create or replace function funuserreturn varchar2 isv_id number(8);uname t_user.username%type;beginv_id := 3;select username into uname from t_user where userid=v_id;return uname;end;declarevname varchar2(50);beginvname :=funuser;dbms_output.put_line('vname:'||vname);end;call funuser() into :vname;print vname;》 9: 创建包的规范create or replace package user_pkgisprocedure userselect(v_id t_user.userid%type,v_name t_user.username%type);function getname return varchar2;end;》10: 创建包的内容create or replace package body user_pkgisprocedure userselect(v_id t_user.userid%type,v_name t_user.username%type)isvn varchar2(50);beginupdate t_user set username=v_name where userid=v_id;commit;dbms_output.put_line('v_name:'||v_name);end;function getname return varchar2isvname varchar2(50);beginselect username into vname from t_user where userid=3;return vname;end;end;----exec 为调用存储过程exec user_pkg.userselect(3,'lisi');call user_pkg.getname() into :vname;print vname;※ 11: 创建视图create or replace view empdeptasselect e.empno,e.ename,e.job,e.mgr,e.sal,e.hiredate,e.comm,d.dname,d.locfrom emp e,dept dwhere e.deptno=d.deptnowith read only (这为把值设为只读);update empdept set ename='world' where empno=7369;create or replace view deptviewasselect * from emp where deptno=20with check option;update deptview set ename='world' where empno=7369;update emp set deptno=10 where empno=7369;》 12 : 创建数据库链create database link mylinkconnect to tt identified by ttusing '(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = jiahua)))';select * fromcompany@mylink;》13: 创建触发器--当dept表(deptno=10)的loc的deptno改为BJ的时候,修改相关的emp表的ename=BJcreate or replace trigger updateempafter update of loc on dept for each rowbeginupdate emp set ename='BJ' where deptno=10;end;

oracle sql语句 只读,Oracle_SQL语句相关推荐

  1. Oracle+Sql Server相关查询语句

    上周处理过 Oracle.Sql Server 数据库相关数据,发现其实它们的 SQL 查询语句有些是不太一样的,比如行列转置和将查询结果插入新表.本人还是比较愿意写 SQL 语句的,互联网的技术日新 ...

  2. Oracle SQL:update更新语句总结

    update语句总结 update SQL用途: 用于修改表中的数据 语法: UPDATE 表名称 SET 列名称 = 新值 <WHERE 条件> 注意事项: ①.更新数字列则可以直接提供 ...

  3. oracle sql语句序列,Oracle SQL:使用Select语句插入序列

    假设您要在按序列生成密钥之前对数据进行分组,那么就像您想要的那样 INSERT INTO HISTORICAL_CAR_STATS ( HISTORICAL_CAR_STATS_ID, YEAR, M ...

  4. oracle sql语句序列,Oracle SQL之 序列使用限制

    Restrictions on Sequence Values You cannot use CURRVAL and NEXTVAL in the following constructs: ■ A ...

  5. oracle sql语句中包含‘’ 的解决方法

    oracle sql语句中包含'&' 的解决方法 参考文章: (1)oracle sql语句中包含'&' 的解决方法 (2)https://www.cnblogs.com/hm1990 ...

  6. Oracle SQL语句执行过程

    前言 QQ群讨论的时候有人遇到这样的问题:where子句中无法访问Oracle自定义的字段别名.这篇 博客就是就这一问题做一个探讨,并发散下思维,谈谈SQL语句的执行顺序问题. 问题呈现 直接给出SQ ...

  7. Oracle查询所有序列;[oracle中如何创建表的自增ID(通过序列);oracle sql语句大全

    Oracle查询所有序列 oracle sql语句大全 oracle中如何创建表的自增ID(通过序列)

  8. oracle sql语句大全

    ORACLE支持五种类型的完整性约束NOT NULL (非空)--防止NULL值进入指定的列,在单列基础上定义,默认情况下,ORACLE允许在任何列中有NULL值.CHECK (检查)--检查在约束中 ...

  9. oracle sql 语句如何插入全年日期?

    为什么80%的码农都做不了架构师?>>>    oracle sql 语句如何插入全年日期? create table BSYEAR (d date); insert into BS ...

最新文章

  1. Java培训的学费标准是多少
  2. 总结 | 机器学习的通俗讲解!
  3. java ug二次开发_使用Java进行UG二次开发:简单的例子(上) | 学步园
  4. Jetty 9.0.0 首个里程碑出现
  5. 18、Java Swing JMenu和JPopupMenu:菜单和弹出式菜单
  6. IHttpHandler与IHttpHandlerFactory的区别一例
  7. 一个常见的台式计算机有哪些硬件部分组成,台式电脑有哪些组成部分
  8. 数据库高级知识——索引优化分析(一)
  9. cad多线段长度计算总和_没想到啊,我平时用的CAD多段线有这么多学问
  10. Java Collections工具类
  11. python纵向数据分析_python数据分析三个重要方法之:numpy和pandas
  12. 43个PSD to XHTML,CSS教程
  13. layui父页面调用子页面的渲染_layUI ajax加载html页面后重新渲染的方法
  14. leetcode 1222 python
  15. css3中的zoom属性以及jquery中css()方法操作元素的属性
  16. 六十八个经典管理小故事
  17. 深入浅出WPF笔记——Binding
  18. LeetCode_69(x 的平方根 )
  19. 前端开发者必会的英语单词
  20. 近十年量化交易领域最重要的十本参考书推荐!重要!

热门文章

  1. 链接服务器访问接口返回了消息没有活动事务,因为链接服务器 SQLEHR 的 OLE DB 访问接口 SQLNCLI10 无法启动分布式事务。...
  2. 计算机操作系统 内存_计算机内存的类型| 操作系统
  3. Python检查特定值是否包含在列表中
  4. 二、WIN10 64位下Pycharm打包.py程序为可执行文件exe
  5. Java编写一个WebService并在Tomcat上发布
  6. Hibernate——(3)主键生成策略持久化类的三种状态
  7. python3字符串转数字_Python3基础语法和基本数据类型
  8. 许昌学院计算机学院张伶俐,2019年教育科学学院毕业论文答辩工作安排
  9. vscode代码库登录配置_VSCode 配置 Sonar Lint支持代码检查提效
  10. python代码没有反应_没有任何编程经验者不要被Python简明手册误导。