web-dev-qa-db-fra.com

PL/MySQL existe-t-il?

Dans Oracle, il existe PL/SQL, un puissant langage impératif. Y a-t-il quelque chose de similaire pour MySQL?

27
user1081596

While MySQL does have similar components, no, you cannot use PL\SQL 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 PL\SQL 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.

13
Michael Capobianco

Je ne sais pas à quel point ils sont puissants, mais ce site donne des informations sur l'écriture de procédures stockées MySQL avec SQL;

http://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspx

Par exemple.

http://www.mysqltutorial.org/sql-cursor-in-stored-procedures.aspx

3
Rory Hunter

Non. Pl/sql est un langage de procédure stockée spécifique à Oracle. Différentes bases de données utilisent différentes langues pour les procédures stockées. Voir cette page de la documentation mySql pour obtenir des informations sur les procédures stockées.

1
user1271208

Google pour " Débuter avec les procédures stockées mysql ", la syntaxe n’est pas très éloignée de celle de PLSQL. 

    DELIMITER //     
    CREATE PROCEDURE GetAllProducts()
       BEGIN
       SELECT *  FROM products;
    END //
    DELIMITER ;
0
Petar

Problème de terminologie

Certains fournisseurs de bases de données relationnelles suivent la définition traditionnelle de SQL, qui le définit comme un langage déclaratif . PostgreSQL, IBM et Oracle sont des exemples de ces fournisseurs. Pour ces fournisseurs de bases de données, vous écrivez du code procédural dans leurs propres langages procéduraux qu’ils fournissent, ce qui peut ou non rendre le code SQL disponible.

Certains fournisseurs voient cependant leur langage procédural comme une extension de SQL. Ces vendeurs n'ont pas une telle différenciation. Par exemple, dans MySQL, un "Programme enregistré" est déclaré avec LANGUAGE SQL même s'il fournit différentes fonctionnalités de langage ( comme LEAVE, REPEAT et UNTIL qui ne sont pas fournies ailleurs ). Donc, vous avez essentiellement un "langage SQL" différent dans une "routine SQL", alors que vous avez une expression de requête. D'autres fournisseurs comme Microsoft appellent tout ce qu'ils font avec un seul terme - "T-SQL". Cette suppression d'un terme rend difficile la recherche de fonctionnalités équivalentes dans d'autres bases de données, ou le choix des fonctionnalités susceptibles d'être différentes.

Les procédures procédurales étant entièrement normalisées sont susceptibles d’être différentes. Alors que la syntaxe de requête déclarative est susceptible d'être similaire car il y a une spécification sur elle.

0
Evan Carroll