Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Esegui una stored procedure
Questo esempio mostra come eseguire una stored procedure quando utilizzi una connessione al database.
L'esempio presuppone che tu abbia familiarità con i seguenti concetti:
Tutte le procedure memorizzate in una connessione al database sono esposte come azioni nell'attività del connettore. Un'azione è una funzione di prima
classe resa disponibile all'integrazione tramite l'interfaccia del connettore. Le azioni
ti consentono di apportare modifiche a una o più entità e variano da un connettore all'altro. Tuttavia, è possibile
che un connettore non supporti alcuna azione, nel qual caso l'elenco Actions sarà vuoto.
I seguenti connettori supportano le stored procedure:
Supponiamo di avere un database MySQL con la seguente stored procedure che recupera le informazioni di un cliente dalla tabella 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
Questa stored procedure restituisce il nome e l'email del cliente specificato. Prende
l'ID cliente tramite la variabile di input p_customer_id e restituisce
il nome e l'email nelle variabili di output p_name e p_email, rispettivamente.
Supponiamo ora che tu voglia ottenere il nome e l'ID indirizzo email del cliente con customer_id=1001.
Devi svolgere le seguenti attività:
Nella sezione Configurazione, fai clic su Configura attività per aprire il riquadro Configura attività di collegamento.
Configura l'attività Connectors in modo che utilizzi la connessione creata nel passaggio 1.
Nella colonna Connessione, seleziona la connessione richiesta dall'elenco delle connessioni disponibili.
Dopo aver selezionato una connessione, viene visualizzata la colonna Tipo con i valori
Entities e Actions. Tutte le procedure memorizzate verranno elencate
in Azioni.
Seleziona Azioni > get_customer_info.
Fai clic su Fine per completare la configurazione della connessione e chiudere il riquadro.
Fai clic sull'elemento dell'attività Connectors e poi su connectorInputPayload
nella sezione Task Input.
Specifica il seguente payload JSON nel campo Default Value:
{
"customer_id": 1001
}
Fai clic sul pulsante Testa nella barra degli strumenti dell'Editor integrazioni per eseguire l'integrazione.
Se l'integrazione viene eseguita correttamente, la variabile connectorOutputPayload
avrà un payload JSON simile al seguente:
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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 ```"]]