v_receipt         warehouse_receipt%ROWTYPE;-- 这里创建表类型,v_receipt复刻了warehouse_receipt的类型(相当于拥有了所有相同的字段)

select * into v_receipt_detail from warehouse_receipt_detail d where d.receipt_detail_id = v_detailId;

**而在MySQL总无法用select into new_table from old_table这个语句**

但是MySQL中有temporary table这个临时表

如何复刻另一张表呢,语句来了

create temporary table new_table (select * from old_table)

这样就创建了一个新的临时表

drop table if exists temp_table;
create temporary table temp_table(select * from test_table);
select name from temp_table where id=2; -- 这句话同样能用

那么,为什么要用这种表变量和复刻的临时表呢?

其实这种临时表是动态的,在满足某种筛选条件下,产生的筛选出的主表

test_table

delimiter $$
-- drop table if exists temp_table;
create procedure temp_test()
begin
drop table if exists temp_table;
create temporary table temp_table(select * from test_table);
-- set @name=temp_table.name;
select name from temp_table where id=2;
end$$
delimiter

测试

call temp_test()

结果

name

------

nyu-ploy

另保留一段代码

delimiter $$
drop procedure if exists test_at $$
create definer=root@localhost procedure test_at()
begin
declare i1 integer default 1;
set i1=i1+1;
set @i2=i2+1;
select i1,@i2;
end $$
delimiter;

**但重点是在oracle 中,表类型可以直接引用字段,即

v_inventoryTotal warehouse_inventory_total%ROWTYPE

v_inventoryTotal.XXId可以直接用,特别是ROWTYPE的表只有一行时,此时引用字段就是一个值

但是对于临时表 temp_table不可以直接 '.id'同时实质表也不可以

在MySQL中引用字段都要起别名 ,这和对象的道理一样,所以想用其中的字段,只能这样

delimiter $$
drop procedure if exists temp_test $$
create definer=root@localhost procedure temp_test()
begin
declare i1 integer default 1;
drop table if exists temp_table;
create temporary table temp_table(select * from test_table t where t.id=2);
select name into @temp_table_name from temp_table;
select @temp_table_name;
end $$
delimiter;

call temp_test ,就有一个值出来 即nyu-poly

如果这里where t.id>2,就会报错:Result consisted of more than one row 即@temp_table_name不可以是多个值

论MySQL中如何代替Oracle中select into new_table from old_table的更多相关文章

  1. mysql导入数据到oracle中

    mysql导入数据到oracle中. 建立Oracle表: CREATE TABLE "GG_USER" ( "USERID" BYTE) NOT NULL, ...

  2. SQL中Charindex和Oracle中对应的函数Instr

    转:http://blog.csdn.net/zhuyu19911016520/article/details/8568640 sql :charindex('字符串',字段)>0 charin ...

  3. mysql 生成UUID() 即 ORACLE 中的guid()函数

    MYSQL 生成UUID 即 guid 函数-- 带 - 的UUIDselect UUID() -- 去掉 - 的UUIDselect replace(uuid(),'-','') 一个表的数据插入另 ...

  4. Java SpringMvc+hibernate架构中,调用Oracle中的sp,传递数组参数

    一.问题 我们调用数据,大都是可以直接获取表中的数据,或者用复杂点的sql语句组成的.但是,有时候,当这样达不到我们要的全部数据的时候,这时,我们就用到了存储过程[sp],如果sp需要参数是数组的话, ...

  5. Oracle中的数据类型和数据类型之间的转换

    Oracle中的数据类型 /* ORACLE 中的数据类型: char 长度固定 范围:1-2000 VARCHAR2 长度可变 范围:1-4000 LONG 长度可变 最大的范围2gb 长字符类型 ...

  6. oracle 中的存储过程

      oracle 中的存储过程 --oracle 中的存储过程, --不带任何参数的 CREATE OR REPLACE PROCEDURE PRO_TEST AS -- AS 和is 没有任何区别 ...

  7. Oracle中的内置函数在sql中的转换整理

    程序里面经常会即支持Oracle数据库,又支持sql数据库.而有些Oracle内置函数用的比较多,但在sql中语法有些不同,我做了些整理,希望可以帮助大家.... 1.oracle中的内置函数:ora ...

  8. Oracle中REGEXP_SUBSTR函数(转)

    Oracle中REGEXP_SUBSTR函数 Oracle中REGEXP_SUBSTR函数的使用说明: 题目如下:在oracle中,使用一条语句实现将'17,20,23'拆分成'17','20','2 ...

  9. Oracle中使用透明网关链接到Sqlserver[Z]

    Oracle中使用透明网关链接到Sqlserver 在最近项目中需要从Oracle中访问SQL Server数据库, 自然想到了透明网关. 因为Oracle数据库是Linux上的, 而Linux上的O ...

随机推荐

  1. Codeforces Round #542(Div. 2) C.Connect

    链接:https://codeforces.com/contest/1130/problem/C 题意: 给一个n*n的图,0表示地面,1表示水,给出起点和终点, 现要从起点到达终点,有一次在两个坐标 ...

  2. [洛谷P2417]课程

    题目链接: 点我 题目分析: 二分图最大匹配裸题,跑完匈牙利判断\(ans\)是否等于教室数即可 多组数据请注意初始化. 代码: #include<bits/stdc++.h> #defi ...

  3. Coloring Trees CodeForces - 711C

    Coloring Trees CodeForces - 711C 题意:有n个点,每个点有一个c值,如果为0表示它没有被染色,否则表示它被染成了c值的颜色.颜色有1到m.把第i棵树染成颜色j所需要的代 ...

  4. 为什么站点使用https加密之后还能看到相关数据

    为什么站点使用了https加密之后,还是能够用firebug之类的软件查看到提交到的信息,并且还是明文的?例如说这样: 这是因为:https(ssl)加密是发生在应用层与传输层之间,所以在传输层看到的 ...

  5. Finally语句

  6. 高阶组件(Higher-Order Components)

    有时候人们很喜欢造一些名字很吓人的名词,让人一听这个名词就觉得自己不可能学会,从而让人望而却步.但是其实这些名词背后所代表的东西其实很简单. 我不能说高阶组件就是这么一个东西.但是它是一个概念上很简单 ...

  7. netcdf源码在windows上的编译

    作者:朱金灿 来源:http://blog.csdn.net/clever101 今天搞搞netcdf源码在windows上的编译,折腾了半天,算是搞成了,特地记录一下过程.我的目标是要生成netcd ...

  8. ag-grid-vue 本地删除,不重新刷新数据

    // 这是本地删除,不重新刷新数据 that.gridListOptions.api.updateRowData({ remove: [that.submitTransmitData] });

  9. DLL入门浅析【转】

     1.建立DLL动态库 动态链接库(DLL)是从C语言函数库和Pascal库单元的概念发展而来的.所有的C语言标准库函数都存放在某一函数库中.在链接应用程序的过程中,链接器从库文件中拷贝程序调用的函数 ...

  10. activitmq+keepalived+nfs 非zk的高可用集群构建

    nfs 192.168.10.32 maast 192.168.10.4 savel 192.168.10.31 应对这个需求既要高可用又要消息延迟,只能使用变态方式实现 nfs部署 #yum ins ...