随笔分类 -  Oracle.语法

摘要:如果现存一张表emp67,要本地复制一张新表可以用: create table emp67_1 as select * from emp67; 执行效果是: SQL> select * from emp67_1; ID NAME AGE 1 杨志 21 2 鲁达 22 3 林冲 23 4 武松 24 阅读全文
posted @ 2022-06-07 22:38 逆火狂飙 阅读(991) 评论(0) 推荐(0) 编辑
摘要:建表语句: create table defects( id number(4), code varchar2(6), type varchar2(10) check(type='oper' or type='sql' or type='api'), status number(1) check(s 阅读全文
posted @ 2021-10-19 20:41 逆火狂飙 阅读(361) 评论(0) 推荐(0) 编辑
摘要:Sample1: with temp AS ( select * from emp where rownum<11) select * from temp Result: SQL> with temp AS ( 2 select * from emp where rownum<11) 3 selec 阅读全文
posted @ 2021-10-05 12:04 逆火狂飙 阅读(1059) 评论(0) 推荐(0) 编辑
摘要:有一张emp3表,表结构如下: create table emp3( id int, mngid int, name nvarchar2(20), primary key(id)); 其中mngid是他上级的id号,有了这个谁被谁管一目了然。 然后可以插点值: insert into emp3(id 阅读全文
posted @ 2021-08-26 15:58 逆火狂飙 阅读(255) 评论(0) 推荐(0) 编辑
摘要:需求:将emp表中工资大于一万的降到9成,工资少于一万的乘以1.2. 难点:如果分成两句update执行,在10000附近的值可能会执行两次. 钥匙:在update语句里采用case when,使更新仅仅执行一次. 代码展示: SQL> create table emp( 2 id number(4 阅读全文
posted @ 2020-05-09 09:01 逆火狂飙 阅读(569) 评论(0) 推荐(0) 编辑
摘要:With语句可以在查询中做成一个临时表/View,用意是在接下来的SQL中重用,而不需再写一遍。 With Clause方法的优点: 增加了SQL的易读性,如果构造了多个子查询,结构会更清晰。 示例: with soloemp as (select distinct salary from hy_e 阅读全文
posted @ 2020-04-14 16:46 逆火狂飙 阅读(1052) 评论(0) 推荐(0) 编辑
摘要:--表结构 create table hy_emp( id number(4,0) primary key, name nvarchar2(20) not null, edate date) --充值 insert into hy_emp select rownum,dbms_random.stri 阅读全文
posted @ 2020-04-02 08:28 逆火狂飙 阅读(150) 评论(0) 推荐(0) 编辑
摘要:树形查询一般用于上下级场合,使用的特殊sql语法包括level,prior,start with,connect by等,下面将就实例来说明其用法。 表定义: create table tb_hierarchy( id number(4,0) primary key, name nvarchar2( 阅读全文
posted @ 2020-03-18 15:08 逆火狂飙 阅读(1403) 评论(1) 推荐(0) 编辑
摘要:按:SQL术语Join在中文对应的翻译是“连接”还是“联结”说法不一,下文将统一采用“连接”的译法。 开局一张图: 前奏/准备工作: Emp表结构: create table emp( empid number(4,0), empname nvarchar2(20), deptno number(4 阅读全文
posted @ 2020-02-06 11:07 逆火狂飙 阅读(1526) 评论(1) 推荐(0) 编辑
摘要:转载地址:https://database.51cto.com/art/202001/609727.htm 阅读全文
posted @ 2020-01-30 17:52 逆火狂飙 阅读(112) 评论(0) 推荐(0) 编辑
摘要:比如有这么一个表: create table test02( id number(8,0) primary key, name nvarchar2(20), sal number(5,0) ) 可以这样给它充值: insert into test02 select rownum,dbms_rando 阅读全文
posted @ 2020-01-29 09:27 逆火狂飙 阅读(2038) 评论(2) 推荐(0) 编辑
摘要:SQL> SELECT COUNT (*) as cnt FROM ALL_TABLES WHERE table_name = UPPER('your_table'); CNT 1 返回1表示存在,0表示不存在。 --END-- 2020-01-09 14:27 阅读全文
posted @ 2020-01-09 13:27 逆火狂飙 阅读(1055) 评论(1) 推荐(0) 编辑
摘要:试问,如果有一张表有两个字段,均可为空,插入两条首个字段为空的记录,再插入两条第二字段为空的记录,问count(*)和count(列)结果如何? 答案:count(*)是正常的四条,而count(列)因为空值的影响均为两条,下面是实验结果: 看来只有count(非空列)才与count(*)等效。 附 阅读全文
posted @ 2020-01-01 17:41 逆火狂飙 阅读(618) 评论(0) 推荐(0) 编辑
摘要:有这么个表: 执行 select count(*) from hy_test select count(deptno) from hy_test 都得到 5 但执行 select count(name) from hy_test 却得到 2 原来count(字段)是取 字段中不为空的记录数,所以na 阅读全文
posted @ 2019-12-31 15:28 逆火狂飙 阅读(169) 评论(0) 推荐(0) 编辑
摘要:要求前三名,MySQL中有order by排序,limit限制数量,结果很容易得到,而且limit的执行顺序也在order by之后,写出的sql高效易懂而不易出错。 但在oracle中,由于没有limit子句,人们喜欢求助于rownum伪列,但是,因为rownum身处select子句中,而sele 阅读全文
posted @ 2019-12-31 09:08 逆火狂飙 阅读(636) 评论(2) 推荐(0) 编辑
摘要:Oracle也提供了类似MySQL的批量插入语法,只是稍微别扭些,具体代码如下: package com.hy; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import 阅读全文
posted @ 2019-11-06 17:33 逆火狂飙 阅读(1766) 评论(0) 推荐(0) 编辑

生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东
点击右上角即可分享
微信分享提示