从一个表中选择,插入另一个表oracle sql查询

时间:2022-10-21 23:37:06

I am trying to select data from one table
and insert the data into another table

我试图从一个表中选择数据并将数据插入另一个表

    SELECT ticker FROM tickerdb;

Using OracleSql I am trying to
get the ticker symbol "GOOG" from the tickerdb table,
and insert the t.ticker into the stockdb table.

使用OracleSql我试图从tickerdb表中获取股票代码“GOOG”,并将t.ticker插入到stockdb表中。

select from tickerdb table --> insert into quotedb table

从tickerdb表中选择 - >插入到quotedb表中

    INSERT INTO quotedb
    (t.ticker, q.prevclose, q.opn, q.rnge,
    q.volume, q.marketcap, q.dividend, q.scrapedate)
    VALUES (?,?,?,?,?,?,?,?,SYSDATE)
    tickerdb t inner JOIN quotedb q
    ON t.ticker = q.ticker

4 个解决方案

#1


36  

From the oracle documentation, the below query explains it better

从oracle文档中,以下查询更好地解释了它

INSERT INTO tbl_temp2 (fld_id)
SELECT tbl_temp1.fld_order_id
FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;

You can read this link

你可以阅读这个链接

Your query would be as follows

您的查询如下

//just the concept    
    INSERT INTO quotedb
    (COLUMN_NAMES) //seperated by comma
    SELECT COLUMN_NAMES FROM tickerdb,quotedb WHERE quotedb.ticker = tickerdb.ticker

Note: Make sure the columns in insert and select are in right position as per your requirement

注意:确保插入和选择中的列根据您的要求处于正确位置

Hope this helps!

希望这可以帮助!

#2


10  

You can use

您可以使用

insert into <table_name> select <fieldlist> from <tables>

#3


3  

You will get useful information from here.

您将从此处获得有用的信息。

SELECT ticker
INTO quotedb
FROM tickerdb;

#4


-1  

try this query below:

尝试以下查询:

Insert into tab1 (tab1.column1,tab1.column2) 
select tab2.column1, 'hard coded  value' 
from tab2 
where tab2.column='value';

#1


36  

From the oracle documentation, the below query explains it better

从oracle文档中,以下查询更好地解释了它

INSERT INTO tbl_temp2 (fld_id)
SELECT tbl_temp1.fld_order_id
FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;

You can read this link

你可以阅读这个链接

Your query would be as follows

您的查询如下

//just the concept    
    INSERT INTO quotedb
    (COLUMN_NAMES) //seperated by comma
    SELECT COLUMN_NAMES FROM tickerdb,quotedb WHERE quotedb.ticker = tickerdb.ticker

Note: Make sure the columns in insert and select are in right position as per your requirement

注意:确保插入和选择中的列根据您的要求处于正确位置

Hope this helps!

希望这可以帮助!

#2


10  

You can use

您可以使用

insert into <table_name> select <fieldlist> from <tables>

#3


3  

You will get useful information from here.

您将从此处获得有用的信息。

SELECT ticker
INTO quotedb
FROM tickerdb;

#4


-1  

try this query below:

尝试以下查询:

Insert into tab1 (tab1.column1,tab1.column2) 
select tab2.column1, 'hard coded  value' 
from tab2 
where tab2.column='value';