您的位置:程序门 -> db2 -> 基础类



sql语句问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


sql语句问题
发表于:2007-11-28 14:41:21 楼主
我想插入一组数据
  编号         年             月
    001       2007         1
    001       2007         2
    001       2007         3
    001       2007         4
    001       2007         5    
    001       2007         6
……
 
    请问大家有什么简便的插入语句,编号为001   的记录插入12条   年度为2007   对应12个月份
发表于:2007-11-28 15:33:121楼 得分:0
create   table   t_temp(id   varchar(4),p_year   int,p_month   int)

insert   into   t_temp   with   temp   (id,p_year,p_month)   as  
(values('001',2007,1)
union   all  
select   id,p_year,p_month+1  
from   temp   where   p_month <12)
  select   *   from   temp
发表于:2007-11-28 16:28:412楼 得分:0
我在命令行处理器上运行,总是提示不是有效的命令行处理器命令~~~~
发表于:2007-11-29 10:52:183楼 得分:0
可以设置@   为结束符
db2   -td@

db2   => create       table       t_temp(id       varchar(4),p_year       int,p_month       int)   @

db2   => insert       into       t_temp       with       temp       (id,p_year,p_month)       as      
(values('001',2007,1)  
union       all      
select       id,p_year,p_month+1      
from       temp       where       p_month   <12)  
    select       *       from       temp@

测试没有问题


快速检索

最新资讯
热门点击