想要一种在单行的单列中插入多个数据的最佳解决方案
DROP TABLE District_Info;
CREATE TABLE District_Info(
Dname VARCHAR2(20) primary key,
Boundary_dist VARCHAR2(20)
);
对于此代码,对于每个 Dname,都有多个 Boundary_dist。如果我可以使用 varchar2(20) 数组并根据需要插入尽可能多的 border_dist ,那就更好了。想要一些有用的建议。
DROP TABLE District_Info;
CREATE TABLE District_Info(
Dname VARCHAR2(20) primary key,
Boundary_dist VARCHAR2(20)
);
for this code, for each Dname there are more than one Boundary_dist. it would be better if i could use an array of varchar2(20) and insert as much boundary_dist as i need to. want some helpful suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如已经提到的,执行此操作的理想方法是为每个 DName/Boundary_Dist 组合存储一个附加行。对于如此简单的结构,最简单的方法就是更改主键:
如果您需要该表中与 District 具有 1:1 相关性的其他数据,则最好将 BoundayDist 拆分为单独的数据表:
如果您确实坚持每行存储多个值,则可以使用用户定义的数据类型:
As already mentioned, the ideal way to do this would be to store an additional row for each DName/Boundary_Dist combination. The simplest way to do with a structure this simple is to just change your primary key:
If you're going to need other data in that table that has a 1:1 correlation to District, you would be better off splitting BoundayDist into a separate table:
If you really insist on storing more that one value per row, you can use a user-defined datatype:
您需要为 Boundary_dist 创建一个单独的表,并创建一个引用 District_Info 表的外键。
you need to create a separate table for Boundary_dist and create a foreign key which references the District_Info table.
同意,最好将 Boundary_dist 放在第二个表中,并将它们与 ID 连接起来,但如果您必须这样做,我通常会在代码中将其存储为“1,2,3,4,5”,我可以很容易地使用PHP使用explode或使用MySQL使用IN来操作它。
Agreed, it'd be best to have Boundary_dist in a second table and connect them with an ID, but if you must typically what I do is store it as "1,2,3,4,5" that way in the code I can manipulate that pretty easily with PHP using explode or with mysql using IN.