Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL—如何从表中检索多行,然后获取该信息并将其转储到另一个表的新行中_Sql_Database_Insert Into - Fatal编程技术网

SQL—如何从表中检索多行,然后获取该信息并将其转储到另一个表的新行中

SQL—如何从表中检索多行,然后获取该信息并将其转储到另一个表的新行中,sql,database,insert-into,Sql,Database,Insert Into,我希望根据typeID号从一个表中获取行,并使用来自第一个表查询的数据和一些静态变量的组合将新行插入到另一个表中 有没有一个简单的方法可以做到这一点 代码编辑:(我无法使其工作-获取缺少的表达式错误) 差不多 Insert SomeTable(SomeCol1, SomeCol2,SomeCol29) Select 'SomeText', SomeCol3,963.45 From SomeOtherTable Where SomeKey = 876 还有另一种味道叫选择进入。无法准确理解语法,

我希望根据typeID号从一个表中获取行,并使用来自第一个表查询的数据和一些静态变量的组合将新行插入到另一个表中

有没有一个简单的方法可以做到这一点

代码编辑:(我无法使其工作-获取缺少的表达式错误)

差不多

Insert SomeTable(SomeCol1, SomeCol2,SomeCol29)
Select 'SomeText', SomeCol3,963.45 From SomeOtherTable Where SomeKey = 876
还有另一种味道叫
选择进入
。无法准确理解语法,因为您从未提到正在使用的DBMS。

类似于

Insert SomeTable(SomeCol1, SomeCol2,SomeCol29)
Select 'SomeText', SomeCol3,963.45 From SomeOtherTable Where SomeKey = 876
还有另一种味道叫
选择进入
。无法准确理解语法,因为您从未提到您正在使用的DBMS。

是的,当然

    INSERT INTO yourTable
    (column1,column2)
    SELECT '' ,column FROM SecondTa
当然可以

    INSERT INTO yourTable
    (column1,column2)
    SELECT '' ,column FROM SecondTa

如果第二个表不存在,您可以使用
create table as
select into
创建它,具体取决于您使用的数据库

例如:

select col1, 123 as value
into NewTable
from t
where flag = 0
在某些数据库中,语法为:

create table as
    select col1, 123 as value
    from t
    where flag = 0

Tony已经回答了关于第二个表已经存在的情况的问题。

如果第二个表不存在,您可以使用
create table as
select into
创建它,具体取决于您使用的数据库

例如:

select col1, 123 as value
into NewTable
from t
where flag = 0
在某些数据库中,语法为:

create table as
    select col1, 123 as value
    from t
    where flag = 0

Tony已经回答了关于第二个表已经存在的情况的问题。

使用oracle sql developer来解决这个问题。我将使用oracle sql developer对您的代码进行一次快照。我会给你的代码一个快照,默认是一个列名,如果是的话,它也是一个关键字,所以你要把它包装成“,[]或者`根据后端的偏好这里的问题是表有一个sequence.nextval函数,所以我没有使用default关键字,而是为pk_colIs default调用tablename.nextval作为列名,如果是的话,它也是一个关键字,所以您需要将其包装为“,[]根据后端的偏好,这里的问题是表有一个sequence.nextval函数,因此我不得不调用tablename.nextval来获取pk_col,而不是使用默认关键字