“按表索引”和“按表索引”有什么区别?和“记录表索引”?

发布于 2024-11-07 10:40:31 字数 35 浏览 1 评论 0原文

我遇到过这两个术语,但它们听起来是同义词。两者有区别吗?

I've come across both terms, but they sound synonymous. Is there a distinction between the two?

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

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

发布评论

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

评论(2

怎言笑 2024-11-14 10:40:31

“索引表”是 Oracle 中“关联数组”的术语。这些数组包含可以通过整数或字符串寻址(或索引)的元素。之所以这样称呼它们,可能是因为在定义数组时使用了 INDEX BY 关键字。

Oracle 文档中给出的示例的缩写< /a>:

DECLARE  
  TYPE population_type IS TABLE OF NUMBER INDEX BY VARCHAR2(64);
  country_population population_type;
  howmany NUMBER;
BEGIN
  country_population('Greenland') := 100000; -- Creates new entry
  howmany := country_population('Greenland');
  ...

您可以创建包含记录的索引表,其中记录本质上是包含多种类型的结构。例如,一条记录通常包含与表中的行相同的类型。

再次,来自 Oracle 文档

DECLARE
   TYPE EmpTabTyp IS TABLE OF employees%ROWTYPE
      INDEX BY PLS_INTEGER;
   emp_tab EmpTabTyp;
BEGIN
   /* Retrieve employee record. */
   SELECT * INTO emp_tab(100) FROM employees
     WHERE employee_id = 100;
END;

这里, emp_tab是一个index-by表,以整数索引,包含employees%ROWTYPE的记录。

An "index-by table" is Oracle's term for "associative array". These are arrays that contain elements that you can address (or index by) either an integer or string. They're probably called that because of the use of the INDEX BY keywords when defining the array.

An abbreviation of the example given in the Oracle documentation:

DECLARE  
  TYPE population_type IS TABLE OF NUMBER INDEX BY VARCHAR2(64);
  country_population population_type;
  howmany NUMBER;
BEGIN
  country_population('Greenland') := 100000; -- Creates new entry
  howmany := country_population('Greenland');
  ...

You can create index-by tables containing records, where records are essentially a structure containing multiple types. A record, for example, often contains the same types as a row in a table.

Again, from the Oracle documentation:

DECLARE
   TYPE EmpTabTyp IS TABLE OF employees%ROWTYPE
      INDEX BY PLS_INTEGER;
   emp_tab EmpTabTyp;
BEGIN
   /* Retrieve employee record. */
   SELECT * INTO emp_tab(100) FROM employees
     WHERE employee_id = 100;
END;

Here, emp_tab is an index-by table, indexed by integers, containing records of employees%ROWTYPE.

二智少女 2024-11-14 10:40:31

我不确定您从哪里获得这些短语,但 TABLE OFINDEX BY 是集合类型声明的单独部分。 TABLE OF 定义集合字段的类型,可以是数据类型(即 TABLE OF NUMBER)或记录类型(即 TABLE OF MY_TABLE %类型)。

INDEX BY 指的是查找这个集合的方法,几乎​​就像一个键值对。例如,我可能会使用 INDEX BY VARCHAR2(10) ,以便可以使用文本键从集合类型中检索值。

这是一个例子:

DECLARE
  TYPE my_type IS TABLE OF NUMBER INDEX BY VARCHAR2(10);
  n_my_value NUMBER;
BEGIN
  my_type ('the key') := 99;
  n_my_value := my_type ('the key');
END;
/

I'm not sure where you got the phrases from, but TABLE OF and INDEX BY are separate parts of a collection type declaration. TABLE OF defines the type of a collection's field(s), which can be a datatype (i.e. TABLE OF NUMBER) or a record type (i.e. TABLE OF MY_TABLE%TYPE).

INDEX BY refers to the method of looking up this collection, almost like a key-value pair. For example, I might use INDEX BY VARCHAR2(10) so that I can use a textual key to retrieve a value from the collection type.

Here's an illustration:

DECLARE
  TYPE my_type IS TABLE OF NUMBER INDEX BY VARCHAR2(10);
  n_my_value NUMBER;
BEGIN
  my_type ('the key') := 99;
  n_my_value := my_type ('the key');
END;
/
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文