Oracle PL/SQL

前端之家收集整理的这篇文章主要介绍了Oracle PL/SQL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

ADA:是一种计算机程序设计语言,具体可以看百度百科http://baike.baidu.com/item/ada/5606819

oracle和它有什么关系呢,只看百度百科有点蒙,在看一下wiki上的https://en.wikipedia.org/wiki/Ada_(programming_language)

摘一段代码就熟悉多了,是不是基本上就是 PL/sql 的风格,不是Oracle抄袭,是因为它就是牛逼。看百度的介绍:ADA源于美国军方的一个计划,旨在整合美军事系统中运行着上百种不同的程序设计语言。 Ada不仅体现了许多现代软件的开发原理,而且将这些原理付诸实现。同时,Ada语言的使用可大大改善软件系统的清晰性、可靠性、有效性、可维护性。Ada是现有的语言中无与伦比的一种大型通用程序设计语言,它是现代计算机语言的成功代表,集中反映了程序语言研究的成果。Ada的出现,标志着软件工程成功地进入了国家和国际的规模。它是迄今为止最复杂、最完备的软件工具。Ada曾是美国国防部指定唯一可用于军用系统开发的语言。

-- while a is not equal to b,loop.
while a /= b loop
  Ada.Text_IO.Put_Line ("Waiting");
end loop;

if a > b then
  Ada.Text_IO.Put_Line ("Condition met");
else
  Ada.Text_IO.Put_Line ("Condition not met");
end if;

for i in 1 .. 10 loop
  Ada.Text_IO.Put ("Iteration: ");
  Ada.Text_IO.Put (i);
  Ada.Text_IO.Put_Line;
end loop;

loop
  a := a + 1;
  exit when a = 10;
end loop;

case i is
  when 0 => Ada.Text_IO.Put ("zero");
  when 1 => Ada.Text_IO.Put ("one");
  when 2 => Ada.Text_IO.Put ("two");
  -- case statements have to cover all possible cases:
  when others => Ada.Text_IO.Put ("none of the above");
end case;

for aWeekday in Weekday'Range loop               -- loop over an enumeration
   Put_Line ( Weekday'Image(aWeekday) );         -- output string representation of an enumeration
   if aWeekday in Working_Day then               -- check of a subtype of an enumeration
      Put_Line ( " to work for " &
               Working_Hours'Image (Work_Load(aWeekday)) ); -- access into a lookup table
   end if;
end loop;

PL/sql(Procedural Language/sql)是一种过程化语言, 就是因为ADA这么牛逼,所以Oracle在ADA的基础上对sql语言进行了扩展,才有了今天的PL/sql百度百科都没说PL/sql是基于ADA的,这个可从Oracle官方查到https://docs.oracle.com/cloud/latest/db112/LNPLS/limits.htm#LNPLS018

PL/sql is based on the programming language Ada. As a result,PL/sql uses a variant of Descriptive Intermediate Attributed Notation for Ada (DIANA),a tree-structured intermediate language. It is defined using a Metanotation called Interface Definition Language (IDL). DIANA is used internally by compilers and other tools.

At compile time,PL/sql source text is translated into system code. Both the DIANA and system code for a subprogram or package are stored in the database. At run time,they are loaded into the shared memory pool. The DIANA is used to compile dependent subprograms; the system code simply runs.

In the shared memory pool,a package specification,ADT specification,standalone subprogram,or anonymous block is limited to 67108864 (2**26) DIANA nodes which correspond to tokens such as identifiers,keywords,operators,and so on. This allows for ~6,000,000 lines of code unless you exceed limits imposed by the PL/sql compiler,some of which are given in Table C-1.

简单翻译一下:

PL/sql是基于编程语言Ada。因此,PL/sql使用了一些DIANA(面向Ada的中间描述属性符),一种树形结构的中间语言(DIANA就是PL/sql到Ada的一种中间语言,就相当于class文件是java和机器语言的中间语言一样)。它定义了一个元符号(语言中的关键字)叫做IDL(接口定义语言)。(也就是说DIANA是一种语言,IDL是语言的关键字和描述符,就像汇编语言中的mov,java中的int)。DIANA供内部编译器使用,或者其他工具。

编译时,PL/sql文件被翻译为机器代码。子程序或者程序包的DIANA和机器代码都会存储到数据库中。在运行时,他们会被加载进共享的内存空间中。DIANA用于编译依赖的子程序,机器码仅仅是运行。

在共享内存中,包的描述,ADT( 个人感觉应该是抽象数据类型,abstract data type )的描述,独立的子程序,无名的程序块会被限制到67108864 (2**26) DIANA节点,这些节点要与标志一致,比如标识符、关键字、运算符等等。它允许~6,000行代码除非你通过PL/sql编译器强加了限制,其他限制见表 Table C-1.

这段话又牵出了我们要说的另外两个概念:DIANA和IDL。DIANA是一种中间语言,IDL是它的描述。IDL是存储在硬盘上的,实际的解析是在内存中建立和存储的,所以DIANA在内存的大小一般要超过在磁盘上的的大小。在内存中调用DIANA的存储过程仅仅是在你创建存储过程的时候需要。在实际的生产系统中,内存中不需要DIANA,只需要机器码。

再看一下wiki上DIANA的解释

DIANA,the Descriptive Intermediate Attributed Notation for Ada,is an intermediate language used to represent the semantics of an Ada program. It was originally designed as an interface between the front end (syntactic analysis) and middle (semantic analysis) of the compiler on the one hand and the back end (code generation and optimization) on the other. It is also used as an internal representation by other language tools.

DIANA is also used by PL/SQL,which is based on Ada.

DIANA is an abstract data type; its concrete implementations are defined using the IDL specification language.

DIANA descends from TCOL and AIDA,earlier representations of Ada programs.

The Ada-0 subset of Ada at Karlsruhe (1980) was first using AIDA,[1] but later AIDA got replaced by DIANA. The full Karlsruhe Ada compilation system used DIANA as well and the IDL External Representation for marshalling between the middle-end and the code generating back-end.

大体翻译一下:DIANA是一种中间语言,用于描述Ada程序的语义。它最初设计是一个前端(语法分析)和中间编译器(语义分析)还有后端(生成代码和最优化)的接口。DIANA也用于基于Ada的PL/sql。DIANA是一个抽象的数据类型,它的具体实现是通过IDL定义的。Ada早期的表示是通过TCOL和AIDA,DIANA是排在最后的,是前面的优化版本。

这是wiki上IDL的解释

IDL (Interface Description Language) is a software interface description language (also referred to as Interface Descriptor Language) created by William Wulf and John Nestor of Carnegie Mellon University and David Lamb of Queen's University,Canada.

Like other interface description languages,IDL defined interfaces in a language- and machine- independent way,allowing the specification of interfaces between components written in different languages,and possibly executing on different machines using remote procedure calls.

The Karlsruhe Ada compilation system used IDL resp. DIANA and its predecessor AIDA,[1][2] and for marshalling the vanilla IDL External Representation.

BiiN's DBMS used IDL as well,and for marshalling a more compact binary IDL External Representation.

大体翻译:IDL是一个软件的接口描述语言。像其他接口描述语言一样,IDL定义了一个独立语言和独立机器间的接口,容许不同语言间的接口规范,还可以通过远程调用运行在不同的机器上。

猜你在找的Oracle相关文章