Update语句中的“单行子查询返回多行”

时间:2017-08-15 07:31:58

标签: oracle sql-update ora-01427

我一直在努力研究如何让我的select声明发挥作用。 ORA-01427 single-row subquery returns more than one row语句似乎按预期工作,但当我尝试更新列值时,出现UPDATE tbl_metrics SET act_end_time = (WITH base AS (SELECT caseid, entry_timestamp FROM activity WHERE act_id IN (100, 700, 300) ) SELECT t1.entry_timestamp FROM base t1, tbl_metrics t2 WHERE t1.caseid = t2.caseid AND t2.act_start_time < (SELECT MIN(t1.entry_timestamp) FROM base t1 WHERE t1.caseid = t2.caseid)) 错误。

以下是代码:

tbl_metrics.act_end_time

我们的想法是使用entry_timestamp表中activityactivity.caseid=tbl_metrics.caseid以及activity.entry_timestamp>tbl_metrics.act_start_time的最低activity.act_id值更新tree_node *insert_node_in_tree(tree_node *root, node new_node) { if(root == NULL) return new_node; queue <tree_node * > qu; tree_node *temp; qu.push(root); while(!(qu.empty())) { temp = qu.front(); qu.pop(); if(temp->left == NULL || temp->right == NULL) break; qu.push(temp->left); qu.push(temp->right); } if(temp->left == NULL) temp->left = new_node; else temp->right = new_node; return root; } 列}是100,700或300。

1 个答案:

答案 0 :(得分:1)

我认为应该是这样的:

UPDATE tbl_metrics t2
SET act_end_time = 
    (SELECT MIN(t1.entry_timestamp) 
    FROM activity t1 
    WHERE act_id IN (100, 700, 300)
        AND t1.entry_timestamp > t2.act_start_time
        AND t1.caseid = t2.caseid)