例如:
表1:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>Clothing mixer</h1>
<div class="container">
<div id="avatar_box">
<div id="base"><img src="https://i.imgur.com/FBCF5Mq.png"></div>
</div>
<div id="roulette">
<div id="categoryBar">
<div class="categoryButton ThisOneIsActive">
Hair
</div>
<div class="categoryButton">
Skin
</div>
<div class="categoryButton">
Pants
</div>
<div class="categoryButton">
Skirt
</div>
<div class="categoryButton" id="youreWearing">
Wearing
</div>
</div>
<div id="wardrobe_content">
<div class="categoryContent ThisOneIsActive" id="c0">
<div class="window hair"><img class="category hair" id="item_id_1" src="https://i.imgur.com/k0TXwzN.png"></div>
<div class="window hair"><img class="category hair" id="item_id_2" src="https://i.imgur.com/ZdrNHKy.png"></div>
</div>
<div class="categoryContent" id="c1">
<div class="window skin"><img class="category skin" id="item_id_3" src="https://i.imgur.com/lf8WdTw.png"></div>
</div>
<div class="categoryContent" id="c2">
boxes of items pants
</div>
<div class="categoryContent" id="c3">
boxes of items skirts
</div>
</div>
<div class="items_on_doll" id="c4">
</div>
</div>
</div>
表2
c1,c2,c3 (1,10,'123')
现在我想从table1中选择记录,如果c3列值开始两位数是12那么我必须填充AA,如果是34那么表2中的BB c4列:
答案 0 :(得分:0)
OP已在原帖中的评论中提供了其他信息。特别是,c3
为VARCHAR2
,始终以12
或34
开头。
以下内容应该有效。如果c3
不以12
或34
开头,则c4
列中插入的值将为NULL
。这是CASE
表达式的默认行为,因此不需要明确编码;如果在这种情况下需要类似'ZZ'
的内容,那么我们可以向else
添加CASE
子句。 (OP说c3
始终以12
或34
开头;如果是,则这是一个没有实际意义的点。)
insert into table2 ( c1, c2, c3, c4 )
select c1, c2, c3,
case when c3 like '12%' then 'AA'
when c3 like '34%' then 'BB'
end
from table1
;
<强>演示强>:
SQL> create table table1 ( c1 number, c2 number, c3 varchar2(25) );
Table created.
SQL> insert into table1 ( c1, c2, c3 ) values ( 1, 10, '123' );
1 row created.
SQL> insert into table1 ( c1, c2, c3 ) values ( 1, 10, '3444' );
1 row created.
SQL> commit;
Commit complete.
SQL> select * from table1;
C1 C2 C3
---------- ---------- -------------------------
1 10 123
1 10 3444
2 rows selected.
然后:
SQL> create table table2 ( c1 number, c2 number, c3 varchar2(25), c4 varchar2(10) );
Table created.
SQL> select * from table2;
no rows selected
SQL> insert into table2 ( c1, c2, c3, c4 )
2 select c1, c2, c3,
3 case when c3 like '12%' then 'AA'
4 when c3 like '34%' then 'BB'
5 end
6 from table1
7 ;
2 rows created.
SQL> select * from table2;
C1 C2 C3 C4
---------- ---------- ------------------------- ----------
1 10 123 AA
1 10 3444 BB
2 rows selected.