PL/MySQL 是否存在?

2021-12-24 00:00:00 mysql scripting plsql

在 Oracle 中有 PL/SQL,这是一种强大的命令式语言.MySQL 有没有类似的东西?

解决方案

虽然 MySQL 确实有类似的组件,但不能在 MySQL 中使用 PLSQL.MS SQL Server 使用的 T-SQL 也是如此.

MySQL 在在其网站上有大量相关文档.

您会看到 PLSQL 和 T-SQL 都是图灵完备的,并且可能提供更多的功能.但是 MySQL 有很多方法可以执行类似的任务.

以下是 Yahoo Answers 帖子中的内容:

<块引用>

MySQL 是一个多线程、多用户的 SQL 数据库管理系统(DBMS)1,根据 MySQLAB,1000万以上安装.

用于访问 MySQL 数据库的库可用于所有主要具有特定语言 API 的编程语言.此外,一个名为 MyODBC 的 ODBC 接口允许使用其他编程语言支持 ODBC 接口与 MySQL 数据库通信,例如 ASP 或 Coldfusion.MySQL 服务器和官方库是主要在 ANSI C 中实现.

MySQL 在 Web 应用程序中很流行并充当数据库LAMP、MAMP 和 WAMP 平台的组件(Linux/Mac/Windows-Apache-MySQL-PHP/Perl... 和开源错误跟踪工具,如 Bugzilla.它作为 Web 应用程序的受欢迎程度是与 PHP 的流行密切相关,它通常与MySQL.PHP 和 MySQL 是运行流行的必要组件WordPress 博客平台.

以下功能由 MySQL 实现,但不是由其他一些关系型数据库:

  • 多个存储引擎,允许您选择对应用程序中的每个表最有效的一个(在 MySQL 5.0 中,必须编译存储引擎;在 MySQL 5.1 中,存储引擎可以在运行时动态加载): o 本机存储引擎(MyISAM,Falcon、合并、内存(堆)、联合、存档、CSV、黑洞、簇)- 合作伙伴开发的存储引擎(InnoDB、solidDB、NitroEDB、BrightHouse)-社区开发的存储引擎
  • 自定义存储引擎
  • 提交分组,将来自多个连接的多个事务收集在一起以增加每秒提交的数量.

注意:: MySQL 是用 C 和 C++ 编写的.SQL 解析器使用 yacc 和自制词法分析器.描述一些内部的文件代码的结构和编码指南可从MySQL 网站.

SQL

<块引用>


SQL 通常扩展为结构化查询语言,是一种计算机用于检索和管理数据的语言关系数据库管理系统、数据库模式创建和修改、数据库对象访问控制管理.

SQL 语言细分为几个语言元素,包括:

  • 可能对模式和数据产生持久影响的语句,或者可能控制事务、程序流、连接、会话或诊断.
  • 根据特定条件检索数据的查询.
  • 可以生成标量值或由数据的列和行组成的表的表达式.
  • 谓词指定可以评估为 SQL 三值逻辑 (3VL) 布尔真值的条件,通常用于限制语句和查询的影响,或改变程序流.
  • 作为语句和查询的组成部分(在某些情况下是可选的)的子句<​​/li>

它在查询数据操作数据定义的概念下工作事务控制

SQL:2003 标准对所有部分进行了微小的修改SQL:1999,并正式引入了一些新特性,例如:1

  • XML 相关功能
  • 窗口函数
  • 序列生成器,允许标准化序列
  • 两种新的列类型:自动生成的值和标识列
  • 新的 MERGE 语句
  • CREATE TABLE 语句的扩展,以允许CREATE TABLE AS"和创建表格"
  • 删除执行不力的BIT";和位变化"数据类型

PL/SQL

<块引用>


PL/SQL 是 Oracle Corporation 专有的基于服务器的过程扩展SQL 数据库语言.(其他一些 SQL 数据库管理系统提供类似于 PL/SQL 的语言.)它的语法非常类似于艾达.

PL/SQL 支持变量、条件、数组和异常.Oracle RDBMS 第 8 版以后的实现具有包括与面向对象相关的功能.

底层 SQL 用作声明性语言.标准SQL——不像一些函数式编程语言——不需要将尾调用转换为跳转的实现.SQL 不容易提供第一行"和桌子的其余部分"访问器,它不能轻松执行某些结构,例如循环.然而,PL/SQL 作为图灵完备的程序语言填补了这些空白,允许Oracle 数据库开发人员与底层关系的接口以命令式的方式使用数据库.SQL 语句可以使显式对 PL/SQL 函数的内嵌调用,或者可能导致 PL/SQL 触发器触发预定义的数据操作语言 (DML) 事件.

PL/SQL 存储过程(函数、过程、包和触发器)执行 DML 被编译到 Oracle 数据库中:在这个范围内,他们的 SQL 代码可以进行语法检查.程序员在 Oracle 数据库环境中工作可以构建 PL/SQL 块将此类功能用作程序、功能;或者他们可以在 SQL*Plus 脚本中编写 PL/SQL 的内嵌段.

虽然程序员可以很容易地将 SQL DML 语句合并到PL/SQL(例如,作为游标定义,或使用 SELECT ...INTO 语法)、数据定义语言 (DDL) 语句,例如 CREATETABLE/DROP INDEX 等需要使用动态 SQL".早些时候版本的 Oracle 需要使用复杂的内置 DBMS_SQL系统需要显式解析的动态 SQL 包并执行一条 SQL 语句.后来的版本包含了一个 EXECUTE称为本机动态 SQL"的 IMMEDIATE 语法其中相当简化问题.在 Oracle 中使用 DDL 将导致隐式提交.程序员也可以使用动态 SQL 来执行 DML他们事先不知道声明的确切内容.

PL/SQL 提供了几个用于特定目的的预定义包.这样的PL/SQL 包包括:

  • DBMS_OUTPUT - 用于对非数据库目标的输出操作
  • DBMS_JOB - 用于在特定时间运行特定程序/功能(即调度)
  • DBMS_XPLAN - 用于格式化解释计划";输出
  • DBMS_SESSION - 提供对 SQL ALTER SESSION 和 SET ROLE 语句以及其他会话信息的访问.
  • DBMS_METADATA - 用于从数据字典中提取元数据(例如 DDL 语句)
  • UTL_FILE - 用于在磁盘上读写文件
  • UTL_HTTP - 用于从数据库向 Web 服务器发出请求
  • UTL_SMTP - 用于从数据库发送邮件(通过 SMTP 服务器)

Oracle Corporation 通常会添加更多包和/或扩展将功能与 Oracle DBMS 的每个后续版本打包在一起.

In Oracle there is PL/SQL, a powerful imperative language. Is there anything similar for MySQL?

解决方案

While MySQL does have similar components, no, you cannot use PLSQL in MySQL. The same goes for T-SQL used by MS SQL Server.

MySQL has plenty of documentation on it at their website.

You'll see that both PLSQL and T-SQL are Turing-complete, and probably provide slightly more functionality. But MySQL has plenty of ways to perform similar tasks.

Here is the content from the Yahoo Answers post:

MySQL is a multithreaded, multi-user SQL database management system (DBMS)1 which has, according to MySQL AB, more than 10 million installations.

Libraries for accessing MySQL databases are available in all major programming languages with language-specific APIs. In addition, an ODBC interface called MyODBC allows additional programming languages that support the ODBC interface to communicate with a MySQL database, such as ASP or Coldfusion. The MySQL server and official libraries are mostly implemented in ANSI C.

MySQL is popular for web applications and acts as the database component of the LAMP, MAMP, and WAMP platforms (Linux/Mac/Windows-Apache-MySQL-PHP/Perl... and for open-source bug tracking tools like Bugzilla. Its popularity as a web application is closely tied to the popularity of PHP, which is often combined with MySQL. PHP and MySQL are essential components for running the popular WordPress blogging platform.

The following features are implemented by MySQL but not by some other RDBMSes:

  • Multiple storage engines, allowing you to choose the one which is most effective for each table in the application (in MySQL 5.0, storage engines must be compiled in; in MySQL 5.1, storage engines can be dynamically loaded at run time): o Native storage engines (MyISAM, Falcon, Merge, Memory (heap), Federated, Archive, CSV, Blackhole, Cluster) -Partner-developed storage engines (InnoDB, solidDB, NitroEDB, BrightHouse) -Community-developed storage engines
  • Custom storage engines
  • Commit grouping, gathering multiple transactions from multiple connections together to increase the number of commits per second.

Note:: MySQL is written in C and C++. The SQL parser uses yacc and home-brewed lexer. A document describing some of the internal structures of the code and the coding guidelines is available from the MySQL web site.

SQL


SQL commonly expanded as Structured Query Language, is a computer language designed for the retrieval and management of data in relational database management systems, database schema creation and modification, and database object access control management.

The SQL language is sub-divided into several language elements, including:

  • Statements which may have a persistent effect on schemas and data, or which may control transactions, program flow, connections, sessions, or diagnostics.
  • Queries which retrieve data based on specific criteria.
  • Expressions which can produce either scalar values or tables consisting of columns and rows of data.
  • Predicates which specify conditions that can be evaluated to SQL three-valued logic (3VL) Boolean truth values and are commonly used to limit the effects of statements and queries, or to change program flow.
  • Clauses which are (in some cases optional) constituent components of statements and queries

it works under..concept of query data manipulation data defination transaction control

The SQL:2003 standard makes minor modifications to all parts of SQL:1999, and officially introduces a few new features such as:1

  • XML-related features
  • window functions
  • the sequence generator, which allows standardized sequences
  • two new column types: auto-generated values and identity-columns
  • the new MERGE statement
  • extensions to the CREATE TABLE statement, to allow "CREATE TABLE AS" and "CREATE TABLE LIKE"
  • removal of the poorly-implemented "BIT" and "BIT VARYING" data types

PL/SQL


PL/SQL is Oracle Corporation's proprietary server-based procedural extension to the SQL database language. (Some other SQL database management systems offer languages similar to PL/SQL.) Its syntax strongly resembles that of Ada.

PL/SQL supports variables, conditions, arrays, and exceptions. Implementations from version 8 of the Oracle RDBMS onwards have included features associated with object-orientation.

The underlying SQL functions as a declarative language. Standard SQL—unlike some functional programming languages—does not require implementations to convert tail calls to jumps. SQL does not readily provide "first row" and "rest of table" accessors, and it cannot easily perform some constructs such as loops. PL/SQL, however, as a Turing-complete procedural language which fills in these gaps, allows Oracle database developers to interface with the underlying relational database in an imperative manner. SQL statements can make explicit in-line calls to PL/SQL functions, or can cause PL/SQL triggers to fire upon pre-defined Data Manipulation Language (DML) events.

PL/SQL stored procedures (functions, procedures, packages, and triggers) which perform DML get compiled into an Oracle database: to this extent their SQL code can undergo syntax-checking. Programmers working in an Oracle database environment can construct PL/SQL blocks of such functionality to serve as procedures, functions; or they can write in-line segments of PL/SQL within SQL*Plus scripts.

While programmers can readily incorporate SQL DML statements into PL/SQL (as cursor definitions, for example, or using the SELECT ... INTO syntax), Data Definition Language (DDL) statements such as CREATE TABLE/DROP INDEX etc require the use of "Dynamic SQL". Earlier versions of Oracle required the use of a complex built-in DBMS_SQL package for Dynamic SQL where the system needed to explicitly parse and execute an SQL statement. Later versions have included an EXECUTE IMMEDIATE syntax called "Native Dynamic SQL" which considerably simplifies matters. Any use of DDL in Oracle will result in an implicit commit. Programmers can also use Dynamic SQL to execute DML where they do not know the exact content of the statement in advance.

PL/SQL offers several pre-defined packages for specific purposes. Such PL/SQL packages include:

  • DBMS_OUTPUT - for output operations to non-database destinations
  • DBMS_JOB - for running specific procedures/functions at a particular time (i.e. scheduling)
  • DBMS_XPLAN - for formatting "Explain Plan" output
  • DBMS_SESSION - provides access to SQL ALTER SESSION and SET ROLE statements, and other session information.
  • DBMS_METADATA - for extracting meta data from the data dictionary (such as DDL statements)
  • UTL_FILE - for reading and writing files on disk
  • UTL_HTTP - for making requests to web servers from the database
  • UTL_SMTP - for sending mail from the database (via an SMTP server)

Oracle Corporation customarily adds more packages and/or extends package functionality with each successive release of the Oracle DBMS.

相关文章