Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

scripting - PL/MySQL does it exist?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

As much as I'd hate to refer to Yahoo Answers, there's a good explanation Here

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...