Teradata SQL重复插入语句

发布于 01-22 20:48 字数 152 浏览 3 评论 0原文

Teradata非常陌生,并试图弄清楚如何重复简单的插入语句。

我有以下陈述

Insert into Test (Id) values ((sel max (Id)+1 from test))

,我将重复20次。

pretty new to teradata and trying to figure out how to repeat a simple insert statement.

I have the following statement

Insert into Test (Id) values ((sel max (Id)+1 from test))

And I would to repeat this 20 times.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅黛梨妆こ2025-01-29 20:48:35

为了运行语句20次

create table test_table_1 ( numcol int );

replace procedure test_proc()
begin
  declare rowcnt int;
  set rowcnt = 0;
while rowcnt<20 do 
begin
  insert into test_table_1 select max(coalesce(numcol,null,0))+1 from test_table_1;
  set rowcnt = rowcnt + 1;
end;  
end while;
end;

call test_proc();

select * from test_table_1;

,但实际上您只需要一个身份列,这将排除需要插入20次增量值的需求。

For the purposes of running the statement 20 times

create table test_table_1 ( numcol int );

replace procedure test_proc()
begin
  declare rowcnt int;
  set rowcnt = 0;
while rowcnt<20 do 
begin
  insert into test_table_1 select max(coalesce(numcol,null,0))+1 from test_table_1;
  set rowcnt = rowcnt + 1;
end;  
end while;
end;

call test_proc();

select * from test_table_1;

But in reality you would simply need an identity column which would preclude the need to insert incremental value 20 times.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文