首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

oracle中两表其间值互相插入和表自身插入值

2012-09-25 
oracle中两表之间值互相插入和表自身插入值有两张表student和otherStudent,表信息如下SQL desc studentNa

oracle中两表之间值互相插入和表自身插入值


有两张表student和otherStudent,表信息如下

SQL> desc student
Name Type         Nullable Default Comments
---- ------------ -------- ------- --------
NUM  NUMBER                                
NAME VARCHAR2(20)                          
AGE  NUMBER       Y                        
 
SQL> desc otherStudent
Name Type         Nullable Default Comments
---- ------------ -------- ------- --------
NUM  VARCHAR2(50)                          
NAME VARCHAR2(50)

现在做以下几个实验

 

实验一

现在student中有数据,我想把里面的数据插入otherStudent里面。

insert into otherStudent(num,name) select num,name from student

两表插入的字段类型或长度并补一致仍然可以插入,说明只要被插入的表可以接收,类型不一致或长度不一致不影响。

 


实验二

otherStudent有了数据了,可以将该表的数据再插入本表

insert into otherStudent select * from otherStudent

 


实验三

语句insert into otherStudent select * from student。报错“值过多”。

语句insert into student select * from student otherStudent。报错“没有足够的值”。

 

 

热点排行