我有一个表格式为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=...;
我收到“缺少关键字VALUES”错误。
答案 0 :(得分:1)
您插入的语法已关闭。尝试:
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');
答案 1 :(得分:1)
给出这样的表......
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>