如何将数据插入到架构中具有多个引用的对象关系表中

发布于 2024-08-30 20:00:42 字数 499 浏览 2 评论 0原文

我有一个表,其模式为 Table(number, ref, ref, varchar2, varchar2,...)。

如何向该表中插入一行数据?

当我这样做时:

insert into table 
values (1, select ref(p), ref(d), '239 F.3d 1343', '35 USC § 283', ... 
           from plaintiff p, defendant d
            where p.name='name1' and d.name='name2');

我收到“缺少表达式”错误。

如果这样做:

insert into table
1, select ref(p), ref(d), ... 
from plaintiff p, defendant 
where p.name=...;

我会收到“缺少关键字值”错误。

I have a table with a schema of Table(number, ref, ref, varchar2, varchar2,...).

How would I insert a row of data into this table?

When I do:

insert into table 
values (1, select ref(p), ref(d), '239 F.3d 1343', '35 USC § 283', ... 
           from plaintiff p, defendant d
            where p.name='name1' and d.name='name2');

I get a "missing expression" error.

If I do:

insert into table
1, select ref(p), ref(d), ... 
from plaintiff p, defendant 
where p.name=...;

I get a "missing keyword VALUES" error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一页 2024-09-06 20:00:42

您的插入语法已关闭。尝试:

insert into table  
(select 1, ref(p), ref(d), '239 F.3d 1343', '35 USC § 283', ... 
   from plaintiff p, defendant d where p.name='name1' and d.name='name2');

一般来说,明确提及要插入的列是一个很好的做法,以避免以后列顺序发生变化时出现问题,并对代码进行自我记录:

insert into table (col1, col2, col3, ...) 
(select 1, ref(p), ref(d), '239 F.3d 1343', '35 USC § 283', ... 
   from plaintiff p, defendant d where p.name='name1' and d.name='name2');

Your syntax on the insert is off. Try:

insert into table  
(select 1, ref(p), ref(d), '239 F.3d 1343', '35 USC § 283', ... 
   from plaintiff p, defendant d where p.name='name1' and d.name='name2');

In general, it's a good practice to explicitly mention the columns you're inserting into as well, to avoid problems later if the column order changes, as well as to self-document the code:

insert into table (col1, col2, col3, ...) 
(select 1, ref(p), ref(d), '239 F.3d 1343', '35 USC § 283', ... 
   from plaintiff p, defendant d where p.name='name1' and d.name='name2');
一片旧的回忆 2024-09-06 20:00:42

给定一个像这样的表...

SQL> create table cases
  2      (case_no number
  3       , plaintiff_ref   REF person_t SCOPE IS plaintiffs
  4       , defendant_ref   REF person_t SCOPE IS defendants
  5       , col1 varchar2(30)
  6       , col2 varchar2(30)
  7       )
  8  /

Table created.

SQL>

我们可以像这样填充它...

SQL> insert into cases
  2  select 1, ref(p), ref(d), '239 F.3d 1343', '35 USC § 283'
  3  from plaintiffs p, defendants d
  4  where p.id = 1000
  5  and d.id=2000
  6  /

1 row created.

SQL>

...或者像这样...

SQL> declare
  2      p_ref REF person_t;
  3      d_ref REF person_t;
  4  begin
  5      select ref(p) into p_ref
  6      from plaintiffs p
  7      where p.id = 1000;
  8      select ref(d) into d_ref
  9      from defendants d
 10      where d.id = 2000;
 11
 12      insert into cases
 13      values
 14      (2, p_ref, d_ref, 'YYT A.2e 789', '26 FTW § 169');
 15  end;
 16  /

PL/SQL procedure successfully completed.

SQL>

REF 长得令人眼花缭乱:

SQL>从案例中选择*
2 /

   CASE_NO
----------
PLAINTIFF_REF
--------------------------------------------------------------------------
DEFENDANT_REF
--------------------------------------------------------------------------
COL1                           COL2
------------------------------ ------------------------------
         1
0000220208771EFF0FAD71409F85A448C831C0C7B041CAA1874D514FDC9D18EF12DA22C12D
0000220208981D65F90A004146A1A390DC1048858777ECAC51136743B39A75F37D22DC1379
239 F.3d 1343                  35 USC § 283

         2
0000220208771EFF0FAD71409F85A448C831C0C7B041CAA1874D514FDC9D18EF12DA22C12D
0000220208981D65F90A004146A1A390DC1048858777ECAC51136743B39A75F37D22DC1379
YYT A.2e 789                   26 FTW § 169


SQL>

Given a table like this ...

SQL> create table cases
  2      (case_no number
  3       , plaintiff_ref   REF person_t SCOPE IS plaintiffs
  4       , defendant_ref   REF person_t SCOPE IS defendants
  5       , col1 varchar2(30)
  6       , col2 varchar2(30)
  7       )
  8  /

Table created.

SQL>

We can populate it like this ...

SQL> insert into cases
  2  select 1, ref(p), ref(d), '239 F.3d 1343', '35 USC § 283'
  3  from plaintiffs p, defendants d
  4  where p.id = 1000
  5  and d.id=2000
  6  /

1 row created.

SQL>

... or like this ...

SQL> declare
  2      p_ref REF person_t;
  3      d_ref REF person_t;
  4  begin
  5      select ref(p) into p_ref
  6      from plaintiffs p
  7      where p.id = 1000;
  8      select ref(d) into d_ref
  9      from defendants d
 10      where d.id = 2000;
 11
 12      insert into cases
 13      values
 14      (2, p_ref, d_ref, 'YYT A.2e 789', '26 FTW § 169');
 15  end;
 16  /

PL/SQL procedure successfully completed.

SQL>

The REFs are eye-wateringly long:

SQL> select * from cases
2 /

   CASE_NO
----------
PLAINTIFF_REF
--------------------------------------------------------------------------
DEFENDANT_REF
--------------------------------------------------------------------------
COL1                           COL2
------------------------------ ------------------------------
         1
0000220208771EFF0FAD71409F85A448C831C0C7B041CAA1874D514FDC9D18EF12DA22C12D
0000220208981D65F90A004146A1A390DC1048858777ECAC51136743B39A75F37D22DC1379
239 F.3d 1343                  35 USC § 283

         2
0000220208771EFF0FAD71409F85A448C831C0C7B041CAA1874D514FDC9D18EF12DA22C12D
0000220208981D65F90A004146A1A390DC1048858777ECAC51136743B39A75F37D22DC1379
YYT A.2e 789                   26 FTW § 169


SQL>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文