Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Exécuter une procédure stockée
Cet exemple montre comment exécuter une procédure stockée lorsque vous utilisez une connexion de base de données.
Pour cet exemple, nous partons du principe que vous connaissez les concepts suivants :
Toutes les procédures stockées dans une connexion de base de données vous sont présentées sous forme d'actions dans la tâche "Connecteurs". Une action est une fonction de première classe mise à la disposition de l'intégration par le biais de l'interface du connecteur. Les actions vous permettent de modifier une ou plusieurs entités, et varient d'un connecteur à l'autre. Toutefois, il est possible qu'un connecteur n'accepte aucune action, auquel cas la liste Actions est vide.
Les connecteurs suivants sont compatibles avec les procédures stockées :
Supposons que vous disposiez d'une base de données MySQL. Elle contient la procédure stockée suivante qui obtient les informations d'un client à partir de la table customers :
CREATE PROCEDURE get_customer_info
(IN p_customer_id INT, OUT p_name VARCHAR(50), OUT p_email VARCHAR(255))
BEGIN
SELECT name, email INTO p_name, p_email
FROM customers
WHERE id = p_customer_id;
END
Cette procédure stockée renvoie le nom et l'adresse e-mail du client spécifié. Elle récupère l'ID client à l'aide de la variable d'entrée p_customer_id, et renvoie le nom et l'adresse e-mail dans les variables de sortie p_name et p_email, respectivement.
Supposons maintenant que vous souhaitiez obtenir le nom et l'ID d'adresse e-mail du client avec customer_id=1001. Pour ce faire, vous devez effectuer les tâches suivantes :
Dans la section Configuration, cliquez sur Configurer la tâche pour ouvrir le volet Configurer la tâche "Connecteurs".
Configurez la tâche "Connecteurs" pour qu'elle utilise la connexion que vous avez créée à l'étape 1.
Dans la colonne Connexion, sélectionnez la connexion requise dans la liste des connexions disponibles.
Une fois que vous avez sélectionné une connexion, la colonne Type s'affiche avec les valeurs Entities et Actions. Toutes les procédures stockées sont listées dans Actions.
Sélectionnez Actions > get_customer_info.
Cliquez sur OK pour terminer la configuration de la connexion et fermer le volet.
Cliquez sur l'élément de tâche Connectors, puis sur connectorInputPayload dans la section Task Input.
Spécifiez la charge utile JSON suivante dans le champ Default Value :
{
"customer_id": 1001
}
Cliquez sur le bouton Tester dans la barre d'outils de l'éditeur d'intégration pour exécuter l'intégration.
Si l'intégration aboutit, la variable connectorOutputPayload aura une charge utile JSON semblable à la suivante :
{
"name": "John",
"email": "john@test.com"
}
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eStored procedures in a database connection are accessible as actions within the Connector task in Application Integration.\u003c/p\u003e\n"],["\u003cp\u003eConnectors such as BigQuery, Cloud SQL, MySQL, Oracle DB, PostgreSQL, SQL Server, MariaDB, AlloyDB, Snowflake, and Redshift support stored procedures.\u003c/p\u003e\n"],["\u003cp\u003eTo execute a stored procedure, you need to configure a Connector task with a database connection and select the desired procedure from the list of available actions.\u003c/p\u003e\n"],["\u003cp\u003eInput parameters for a stored procedure can be specified through a JSON payload in the Connector task's \u003ccode\u003econnectorInputPayload\u003c/code\u003e section.\u003c/p\u003e\n"],["\u003cp\u003eThe output of a successfully executed stored procedure will be returned as a JSON payload in the \u003ccode\u003econnectorOutputPayload\u003c/code\u003e variable.\u003c/p\u003e\n"]]],[],null,["# Execute a stored procedure\n==========================\n\nThis example shows how to run a stored procedure when you are using a database connection.\nThe example assumes that you are familiar with the following concepts:\n\n- [Creating integrations using Application Integration](/application-integration/docs/try-sample-integration-ecommerce)\n- [Connector task](/application-integration/docs/configure-connectors-task)\n- [Integration Connectors](/integration-connectors/docs/overview)\n- Database stored procedures\n\nAll stored procedures in a database connection are exposed to you as actions in the\n[Connector task](/application-integration/docs/configure-connectors-task). An action is a first\nclass function that is made available to the integration through the connector interface. Actions\nlet you make changes to an entity or entities, and vary from connector to connector. However, it is possible\nthat a connector doesn't support any action, in which case the `Actions` list will be empty.\n\nThe following connectors support stored procedures:\n\n- [BigQuery](/integration-connectors/docs/connectors/bigquery/configure)\n- [Cloud SQL - MySQL](/integration-connectors/docs/connectors/cloudsqlformysql/configure)\n- [Cloud SQL - PostgreSQL](/integration-connectors/docs/connectors/cloudsqlforpostgresql/configure)\n- [Cloud SQL - SQL Server](/integration-connectors/docs/connectors/cloudsqlforsqlserver/configure)\n- [MySQL](/integration-connectors/docs/connectors/mysql/configure)\n- [Oracle DB](/integration-connectors/docs/connectors/oracledb/configure)\n- [PostgreSQL](/integration-connectors/docs/connectors/postgresql/configure)\n- [SQL Server](/integration-connectors/docs/connectors/sqlserver/configure)\n- [MariaDB](/integration-connectors/docs/connectors/mariadb/configure)\n- [AlloyDB](/integration-connectors/docs/connectors/alloydb/configure)\n- [Snowflake](/integration-connectors/docs/connectors/snowflake/configure)\n- [Redshift](/integration-connectors/docs/connectors/redshift/configure)\n\n### Example\n\nConsider you have a MySQL database which has the following stored procedure that gets a\ncustomer's information from the `customers` table: \n\n```\nCREATE PROCEDURE get_customer_info\n(IN p_customer_id INT, OUT p_name VARCHAR(50), OUT p_email VARCHAR(255))\nBEGIN\n SELECT name, email INTO p_name, p_email\n FROM customers\n WHERE id = p_customer_id;\nEND\n```\n\nThis stored procedure returns the name and email for the specified customer. It takes\nin the customer ID through the `p_customer_id` input variable and returns the\nname and email in the `p_name` and `p_email` output variables, respectively.\n\nNow suppose you want to get the name and email id of the customer with `customer_id=1001`,\nyou must do the following tasks:\n\n1. Create a [connection to your MySQL database](/integration-connectors/docs/connectors/mysql/configure).\n2. Open or create a new [integration](/application-integration/docs/quickstarts).\n3. Add the [Connectors task](/application-integration/docs/configure-connectors-task) to your integration.\n4. In the **Configuration** section, click **Configure task** to open the **Configure connector task** pane.\n5. Configure the Connectors task to use the connection you created in step 1.\n 1. In the **Connection** column, select the required connection from the list of available connections.\n\n\n After you select a connection, the **Type** column appears with the values\n `Entities` and `Actions`. All the stored procedures will be listed\n in **Actions**.\n 2. Select **Actions \\\u003e get_customer_info**.\n 3. Click **Done** to complete the connection configuration and close the pane.\n6. Click the `Connectors` task element, and then click `connectorInputPayload` in the `Task Input` section.\n7. Specify the following JSON payload in the `Default Value` field: \n\n ```\n {\n \"customer_id\": 1001\n }\n ```\n8. Click the **Test** button in the integration editor toolbar to run the integration.\n\n If the integration runs successfully, the `connectorOutputPayload`\n vairable will have a JSON payload similar to the following: \n\n ```\n {\n \"name\": \"John\",\n \"email\": \"john@test.com\"\n }\n ```"]]