<small id='1yhJ3'></small><noframes id='1yhJ3'>

      <legend id='1yhJ3'><style id='1yhJ3'><dir id='1yhJ3'><q id='1yhJ3'></q></dir></style></legend>

        <bdo id='1yhJ3'></bdo><ul id='1yhJ3'></ul>
      <tfoot id='1yhJ3'></tfoot>
      1. <i id='1yhJ3'><tr id='1yhJ3'><dt id='1yhJ3'><q id='1yhJ3'><span id='1yhJ3'><b id='1yhJ3'><form id='1yhJ3'><ins id='1yhJ3'></ins><ul id='1yhJ3'></ul><sub id='1yhJ3'></sub></form><legend id='1yhJ3'></legend><bdo id='1yhJ3'><pre id='1yhJ3'><center id='1yhJ3'></center></pre></bdo></b><th id='1yhJ3'></th></span></q></dt></tr></i><div id='1yhJ3'><tfoot id='1yhJ3'></tfoot><dl id='1yhJ3'><fieldset id='1yhJ3'></fieldset></dl></div>

        如何在 Oracle 中使用枚举?

        How to use enums in Oracle?(如何在 Oracle 中使用枚举?)

            • <bdo id='0frEW'></bdo><ul id='0frEW'></ul>
              <i id='0frEW'><tr id='0frEW'><dt id='0frEW'><q id='0frEW'><span id='0frEW'><b id='0frEW'><form id='0frEW'><ins id='0frEW'></ins><ul id='0frEW'></ul><sub id='0frEW'></sub></form><legend id='0frEW'></legend><bdo id='0frEW'><pre id='0frEW'><center id='0frEW'></center></pre></bdo></b><th id='0frEW'></th></span></q></dt></tr></i><div id='0frEW'><tfoot id='0frEW'></tfoot><dl id='0frEW'><fieldset id='0frEW'></fieldset></dl></div>
              1. <tfoot id='0frEW'></tfoot>
                  <legend id='0frEW'><style id='0frEW'><dir id='0frEW'><q id='0frEW'></q></dir></style></legend>
                • <small id='0frEW'></small><noframes id='0frEW'>

                    <tbody id='0frEW'></tbody>
                • 本文介绍了如何在 Oracle 中使用枚举?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何在仅使用 SQL 的 Oracle 中使用枚举?(无 PSQL)

                  How do you use enums in Oracle using SQL only? (No PSQL)

                  在 MySQL 中你可以:

                  In MySQL you can do:

                  CREATE TABLE sizes (
                     name ENUM('small', 'medium', 'large')
                  );
                  

                  在 Oracle 中执行此操作的类似方法是什么?

                  What would be a similar way to do this in Oracle?

                  推荐答案

                  阅读一些关于 MySQL 枚举,我猜最接近的等价物是一个简单的检查约束

                  Reading a bit about the MySQL enum, I'm guessing the closest equivalent would be a simple check constraint

                  CREATE TABLE sizes (
                    name VARCHAR2(10) CHECK( name IN ('small','medium','large') )
                  );
                  

                  但这不允许您通过索引引用该值.更复杂的外键关系也是可能的

                  but that doesn't allow you to reference the value by the index. A more complicated foreign key relationship would also be possible

                  CREATE TABLE valid_names (
                    name_id   NUMBER PRIMARY KEY,
                    name_str  VARCHAR2(10)
                  );
                  
                  INSERT INTO valid_sizes VALUES( 1, 'small' );
                  INSERT INTO valid_sizes VALUES( 2, 'medium' );
                  INSERT INTO valid_sizes VALUES( 3, 'large' );
                  
                  CREATE TABLE sizes (
                    name_id NUMBER REFERENCES valid_names( name_id )
                  );
                  
                  CREATE VIEW vw_sizes
                    AS 
                    SELECT a.name_id name, <<other columns from the sizes table>>
                      FROM valid_sizes a,
                           sizes       b
                     WHERE a.name_id = b.name_id
                  

                  只要您通过视图进行操作,您似乎就可以相当好地复制功能.

                  As long as you operate through the view, it would seem that your could replicate the functionality reasonably well.

                  现在,如果您接受 PL/SQL 解决方案,您可以创建自定义对象类型,其中可以包含逻辑来限制它们可以保存的值集,并拥有获取 ID 和获取值的方法等.

                  Now, if you admit PL/SQL solutions, you can create custom object types that could include logic to limit the set of values they can hold and to have methods to get the IDs and to get the values, etc.

                  这篇关于如何在 Oracle 中使用枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                  what are the advantages of defining a foreign key(定义外键有什么好处)
                  Music library MySQL database(音乐库 MySQL 数据库)
                  understanding mysql explain(理解mysql解释)
                  Float or decimal for prices?(价格是浮点数还是小数点?)
                  store users and pass in single table or separate table(存储用户并传入单表或单表)

                    <tbody id='KBjpS'></tbody>
                    <bdo id='KBjpS'></bdo><ul id='KBjpS'></ul>
                    <i id='KBjpS'><tr id='KBjpS'><dt id='KBjpS'><q id='KBjpS'><span id='KBjpS'><b id='KBjpS'><form id='KBjpS'><ins id='KBjpS'></ins><ul id='KBjpS'></ul><sub id='KBjpS'></sub></form><legend id='KBjpS'></legend><bdo id='KBjpS'><pre id='KBjpS'><center id='KBjpS'></center></pre></bdo></b><th id='KBjpS'></th></span></q></dt></tr></i><div id='KBjpS'><tfoot id='KBjpS'></tfoot><dl id='KBjpS'><fieldset id='KBjpS'></fieldset></dl></div>
                    1. <tfoot id='KBjpS'></tfoot>
                    2. <small id='KBjpS'></small><noframes id='KBjpS'>

                        <legend id='KBjpS'><style id='KBjpS'><dir id='KBjpS'><q id='KBjpS'></q></dir></style></legend>