Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.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_Oracle_Oracle Sqldeveloper - Fatal编程技术网

SQL复制和替换记录

SQL复制和替换记录,sql,oracle,oracle-sqldeveloper,Sql,Oracle,Oracle Sqldeveloper,我对SQL非常陌生,代码也有问题。我一直在尝试复制表中的一行并替换部分记录。然而,我不断得到错误: ORA-00907:缺少右括号 以下代码给出了错误: insert into mi_structure select replace parent_mi_id, (child_mi_id,'GR','GR_V') child_mi_id, startdate, enddate, mutnr from mi_structure where parent_mi_id like 'MIP

我对SQL非常陌生,代码也有问题。我一直在尝试复制表中的一行并替换部分记录。然而,我不断得到错误:

ORA-00907:缺少右括号

以下代码给出了错误:

  insert into mi_structure
  select replace parent_mi_id, (child_mi_id,'GR','GR_V') child_mi_id, startdate, enddate, mutnr
  from mi_structure
  where parent_mi_id like 'MIPFV%29'
    and sysdate between startdate and enddate;
具有以下代码的表mi_结构如下所示

  select *
  from mi_structure
  where parent_mi_id like 'MIPFV%29'
    and sysdate between startdate and enddate;


PARENT_MI_ID   ||   CHILD_MI_ID       ||   STARTDATE   ||   ENDDATE   || MUTNR
MIPFV_POOL 29  ||   CSLLXXXX.USD.GR   ||   42917       ||   36526     ||   11
我做错了什么?你能试试这个吗

  insert into mi_structure
  select parent_mi_id, replace (child_mi_id,'GR','GR_V') child_mi_id, startdate, enddate, mutnr from mi_structure
  where parent_mi_id like 'MIPFV%29'
  and sysdate between startdate and enddate;
选择替换父对象id、(子对象id、'GR'、'GR V')子对象id, 起始日期、结束日期、来自mi_结构的mutnr

似乎您使用的替换功能错误,应该如下所示

insert into mi_structure (parent_mi_id_col,child_mi_id_col,startdate_col,enddate,mutnr) 
  select parent_mi_id, replace(child_mi_id,'GR','GR_V') child_mi_id, startdate, enddate, mutnr
  from mi_structure
      where parent_mi_id like 'MIPFV%29'
      and sysdate between startdate and enddate;

顺便说一句,我建议您在insert中添加上述列。

(child\u mi\u id、'GR'、'GR\u V')
像函数一样编写,但不是。可能是这导致了错误。是否尝试使用替换函数?它的用法类似于替换('Atestword','word','Phrase')=谢谢你帮助我。这就提供了我所期望的更新行。这是否也会将记录添加到表中?这是唯一的选择部分,您还应该编写插入部分。我还添加了插入部分。您是否可以编写所有需要插入的列,例如
insert-into-mi_-structure(col1,col2,…)
而不是
insert-into-mi_-structure
我发现了问题,与另一个表中缺少子mi_-id有关。谢谢你的帮助!但是标题的顺序不正确。这不是个问题吗?这是否会将行添加到表中?如果有插入。那么是的,这是一个问题,我将添加插入部分。顺便说一句,我建议您像我的示例一样在insert中添加列