當前位置:首頁 » 編程語言 » sql游標結果放進表中
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

sql游標結果放進表中

發布時間: 2022-09-27 09:56:11

sql server將查詢結果放入新表

如果只是套公式
select *into D from (
select * from A
union all
select * from B
union all
select * from C
order by ID,TM
)

⑵ sql 如何把查詢得到的結果如何放入一個新表中

表已經存在;
insert into 表名 (列名1.。。 列名n) select 列名1.。。。列名n from 表 where 條件
表不存在.
oracle
create table 新表明 as select 列名1.。。。列名n from 表 where 條件
sqlserver
select 列名1.。。。列名n
into 新表名
from 表 where 條件

⑶ sql把查詢結果添加到已存在的表中

你的表goods裡面有相同的數據列嗎?
如果有相同的 insert into goods (數據列1,數據列2、、、) values (select from shop where goods.shopid=shop.id)

⑷ sql 如何把查詢得到的結果如何放入一個新表中

oracle crate table 新表名 select collection_date,pub_date,count(*) as 'sum' from r_time group by pub_date,collection_date .

⑸ sql語句怎麼把查詢的結果插入表中

insertintotable1(id,sex,age)select1,'man',agefromtable2wherename='b'

⑹ SQL 中將游標循環查詢的結果插入到臨時表中

你循環時是否用了創建臨時表的語句?如select .... into #temp from ..
先建臨時表,循環用insert
select .... into #temp from .. where 1=2
while 條件
begin
insert into #temp....
end
這樣應該就會沒問題

⑺ plsql中如果我定義一個游標,然後打開這個游標,然後loop循環把查詢出來的數據全部插入自己定義的表中

使用子查詢執行直接裝載
insert /*+APPEND */ into employee(empno,ename,sal,deptno)
select empno,ename,sal,deptno from emp where deptno=20;

注意,要加上「/*+APPEND */",它表示直接裝載方式,當裝載大批量數據時,這是種做法效率很高。

⑻ sql如何將查詢出來的結果寫入一張表中

inswrt into 一張表 as(select * from dajiale where not exists(select 名稱 from guohui where dajiale.名稱=guohui.)

⑼ 在SQL SELECT語句中將查詢結果存放在一個表中應該使用什麼子句

用insert into 或者into語句。
如果插入已有的表:
insert into A(col1,col2)
select c1, c2 from B

生成一個新表:
select c1, c2 into A from B

⑽ 怎麼把下面的的sql語句查詢出來的結果插入到一張新表中去 求大神幫忙

@SQL這個是你生成的sql語句,你在你的sql中增加一個into table,這樣能不能滿足你的需求呢?

關於select into語句我就不多說了,給你參考鏈接,你看看是不是你要的

http://www.w3school.com.cn/sql/sql_select_into.asp

還有就是,你也可以將insert 加到你的@SQL語句的前面直接執行,是不是也行呢?

比如:

現有的@SQL = 'SELECT NAME FROM TABLE UNION ALL SELECT ''ZHANGSNA'' '

你修改成@SQL2 = 'INSERT INTO TABLE2(NAME) ' + @SQL,這樣是不是也行?

我們既然寫存儲過程了,而且目的也只是唯一的,那麼我們就可以考慮直接將所有步驟放在存儲過程中來處理,沒必要再拿出來單獨考慮怎麼用

另外給你一個方式,你看看用得上用不上

--表

create table test

(

name varchar(50)

)

go


--動態sql添加數據

insert into test

exec('select 1')

go


--存儲過程

create proc protest

as

declare @sql nvarchar(100) = ''

declare @s int = 1

while(@s < 5)

begin

select @sql += 'select ' + cast(@s as varchar(20)) + ' union all '

set @s += 1

end

select @sql += 'select 999'

exec(@sql)

go


--存儲過程添加數據

insert into test

exec protest