Use Select AI to Generate SQL from Natural Language Prompts (2024)

Explora la integración de la IA selecta de Oracle con varios proveedores de IA como OpenAI, Cohere, Azure Open AI y OCI Generative AI para generar consultas SQL directamente desde el lenguaje natural.

En estos ejemplos, se muestran acciones comunes de selección de IA y se le guía a través de la configuración de su perfil con diferentes proveedores de IA para aprovechar esas acciones.

Ejemplo: selección de acciones de AI

En el siguiente ejemplo, se muestran acciones como runsql, showsql, narrate, chat y explainsql que puede realizar con SELECT AI. En estos ejemplos se utiliza el esquema sh con atributos de perfil y proveedor de AI definidos en la función DBMS_CLOUD_AI.CREATE_PROFILE.

SQL> select ai how many customers exist; CUSTOMER_COUNT-------------- 55500 SQL> select ai showsql how many customers exist; RESPONSE----------------------------------------------------SELECT COUNT(*) AS total_customersFROM SH.CUSTOMERS SQL> select ai narrate how many customers exist; RESPONSE------------------------------------------------------There are a total of 55,500 customers in the database. SQL> select ai chat how many customers exist; RESPONSE--------------------------------------------------------------------------------It is impossible to determine the exact number of customers that exist as it constantly changes due to various factors such as population growth, new businesses, and customer turnover. Additionally, the term "customer" can refer to individuals, businesses, or organizations, making it difficult to provide a specific number.SQL> select ai explainsql how many customers in San Francisco are married; RESPONSE--------------------------------------------------------------------------------SELECT COUNT(*) AS customer_countFROM SH.CUSTOMERS AS cWHERE c.CUST_STATE_PROVINCE = 'San Francisco' AND c.CUST_MARITAL_STATUS = 'Married'; Explanation:- We use the 'SH' table alias for the 'CUSTOMERS' table for better readability.- The query uses the 'COUNT(*)' function to count the number of rows that match the given conditions.- The 'WHERE' clause is used to filter the results: - 'c.CUST_STATE_PROVINCE = 'San Francisco'' filters customers who have 'San Francisco' as their state or province. - 'c.CUST_MARITAL_STATUS = 'Married'' filters customers who have 'Married' as their marital status.The result of this query will give you the count of customers in San Francisco who are married, using the column alias 'customer_count' for the result. Remember to adjust the table and column names based on your actual schema if they differ from the example. Feel free to ask if you have more questions related to SQL or database in general.

Ejemplo: selección de AI con OpenAI

En el siguiente ejemplo se muestra cómo puede utilizar OpenAI para generar sentencias SQL a partir de peticiones de datos en lenguaje natural.

--Grants EXECUTE privilege to ADB_USER--SQL> grant execute on DBMS_CLOUD_AI to ADB_USER;-- Grant Network ACL for OpenAI endpoint--SQL> BEGIN DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE( host => 'api.openai.com', ace => xs$ace_type(privilege_list => xs$name_list('http'), principal_name => 'ADB_USER', principal_type => xs_acl.ptype_db) ); END; / PL/SQL procedure successfully completed. ---- Create Credential for AI provider--SQL> EXEC DBMS_CLOUD.CREATE_CREDENTIAL('OPENAI_CRED', 'OPENAI', '<your api token>'); PL/SQL procedure successfully completed. ---- Create AI profile--SQL> BEGIN DBMS_CLOUD_AI.CREATE_PROFILE( 'OPENAI', '{"provider": "openai", "credential_name": "OPENAI_CRED", "object_list": [{"owner": "SH", "name": "customers"}, {"owner": "SH", "name": "countries"}, {"owner": "SH", "name": "supplementary_demographics"}, {"owner": "SH", "name": "profits"}, {"owner": "SH", "name": "promotions"}, {"owner": "SH", "name": "products"}], "conversation": "true" }'); END; / PL/SQL procedure successfully completed. ---- Enable AI profile in current session--SQL> EXEC DBMS_CLOUD_AI.SET_PROFILE('OPENAI'); PL/SQL procedure successfully completed. ---- Get Profile in current session--SQL> SELECT DBMS_CLOUD_AI.get_profile() from dual; DBMS_CLOUD_AI.GET_PROFILE()--------------------------------------------------------------------------------"OPENAI" ---- Use AI--SQL> select ai how many customers exist; CUSTOMER_COUNT-------------- 55500 SQL> select ai how many customers in San Francisco are married; MARRIED_CUSTOMERS----------------- 18 SQL> select ai showsql how many customers in San Francisco are married; RESPONSE--------------------------------------------------------------------------------SELECT COUNT(*) AS married_customers_countFROM SH.CUSTOMERS cWHERE c.CUST_CITY = 'San Francisco' AND c.CUST_MARITAL_STATUS = 'Married' SQL> select ai narrate what are the top 3 customers in San Francisco; RESPONSE--------------------------------------------------------------------------------The top 3 customers in San Francisco are: 1. Hector Colven - Total amount sold: $52,025.992. Milburn Klemm - Total amount sold: $50,842.283. Gavin Xie - Total amount sold: $48,677.18 SQL> select ai chat what is Autonomous Database; RESPONSE--------------------------------------------------------------------------------Autonomous Database is a cloud-based database service provided by Oracle. It isdesigned to automate many of the routine tasks involved in managing a database,such as patching, tuning, and backups. Autonomous Database uses machine learning and automation to optimize performance, security, and availability, allowing users to focus on their applications and data rather than database administrationtasks. It offers both Autonomous Transaction Processing (ATP) for transactionalworkloads and Autonomous Data Warehouse (ADW) for analytical workloads. Autonomous Database provides high performance, scalability, and reliability, making it an ideal choice for modern cloud-based applications.SQL> select ai explainsql how many customers in San Francisco are married; RESPONSE--------------------------------------------------------------------------------SELECT COUNT(*) AS customer_countFROM SH.CUSTOMERS AS cWHERE c.CUST_STATE_PROVINCE = 'San Francisco' AND c.CUST_MARITAL_STATUS = 'Married'; Explanation:- We use the 'SH' table alias for the 'CUSTOMERS' table for better readability.- The query uses the 'COUNT(*)' function to count the number of rows that match the given conditions.- The 'WHERE' clause is used to filter the results: - 'c.CUST_STATE_PROVINCE = 'San Francisco'' filters customers who have 'San Francisco' as their state or province. - 'c.CUST_MARITAL_STATUS = 'Married'' filters customers who have 'Married' as their marital status.The result of this query will give you the count of customers in San Francisco who are married, using the column alias 'customer_count' for the result. Remember to adjust the table and column names based on your actual schema if they differ from the example. Feel free to ask if you have more questions related to SQL or database in general. SQL> EXEC DBMS_CLOUD_AI.DROP_PROFILE('OPENAI'); PL/SQL procedure successfully completed.

Ejemplo: Seleccionar IA con Cohere

El siguiente ejemplo muestra cómo puede utilizar Cohere para generar sentencias SQL a partir de peticiones de datos de lenguaje natural.

Nota

Solo un usuario ADMIN puede ejecutar el procedimiento de ACL de red y privilegios EXECUTE.

--Grants EXECUTE privilege to ADB_USER--SQL>grant execute on DBMS_CLOUD_AI to ADB_USER;---- Create Credential for AI provider--SQL> EXEC DBMS_CLOUD.CREATE_CREDENTIAL('COHERE_CRED', 'COHERE', '<your api token>'); PL/SQL procedure successfully completed. ---- Grant Network ACL for Cohere endpoint--SQL> BEGIN DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE( host => 'api.cohere.ai', ace => xs$ace_type(privilege_list => xs$name_list('http'), principal_name => 'ADB_USER', principal_type => xs_acl.ptype_db) ); END; / / PL/SQL procedure successfully completed. ---- Create AI profile--SQL> BEGIN DBMS_CLOUD_AI.CREATE_PROFILE( 'COHERE', '{"provider": "cohere", "credential_name": "COHERE_CRED", "object_list": [{"owner": "SH", "name": "customers"}, {"owner": "SH", "name": "sales"}, {"owner": "SH", "name": "products"}, {"owner": "SH", "name": "countries"}] }'); END; / PL/SQL procedure successfully completed. ---- Enable AI profile in current session--SQL> EXEC DBMS_CLOUD_AI.SET_PROFILE('COHERE'); PL/SQL procedure successfully completed. ---- Get Profile in current session--SQL> SELECT DBMS_CLOUD_AI.get_profile() from dual; DBMS_CLOUD_AI.GET_PROFILE()--------------------------------------------------------------------------------"COHERE" ---- Use AI--SQL> select ai how many customers exist; CUSTOMER_COUNT-------------- 55500 SQL> EXEC DBMS_CLOUD_AI.DROP_PROFILE('COHERE'); PL/SQL procedure successfully completed.

Ejemplo: selección de IA con la clave de API de Azure OpenAI Service

En el siguiente ejemplo se muestra cómo puede activar el acceso al servicio OpenAI de Azure mediante su clave de API, crear un perfil de IA y generar SQL a partir de peticiones de datos de lenguaje natural.

-- Create Credential for AI integration--SQL> EXEC DBMS_CLOUD.CREATE_CREDENTIAL('AZURE_CRED', 'AZUREAI', '<your api token>'); PL/SQL procedure successfully completed. ---- Grant Network ACL for OpenAI endpoint--SQL> BEGIN DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE( host => '<azure_resource_name>.openai.azure.com', ace => xs$ace_type(privilege_list => xs$name_list('http'), principal_name => 'ADMIN', principal_type => xs_acl.ptype_db) ); END; / PL/SQL procedure successfully completed. ---- Create AI profile--SQL> BEGIN DBMS_CLOUD_AI.CREATE_PROFILE( 'AZUREAI', '{"provider": "azure", "azure_resource_name": "<azure_resource_name>", "azure_deployment_name": "<azure_deployment_name>" "credential_name": "AZURE_CRED", "object_list": [{"owner": "SH", "name": "customers"}, {"owner": "SH", "name": "countries"}, {"owner": "SH", "name": "supplementary_demographics"}, {"owner": "SH", "name": "profits"}, {"owner": "SH", "name": "promotions"}, {"owner": "SH", "name": "products"}], "conversation": "true" }'); END; / PL/SQL procedure successfully completed. ---- Enable AI profile in current session--SQL> EXEC DBMS_CLOUD_AI.SET_PROFILE('AZUREAI'); PL/SQL procedure successfully completed.---- Get Profile in current session--SQL> SELECT DBMS_CLOUD_AI.get_profile() from dual; DBMS_CLOUD_AI.GET_PROFILE()--------------------------------------------------------------------------------"AZUREAI" ---- Use AI--SQL> select ai how many customers exist; CUSTOMER_COUNT-------------- 55500 SQL> select ai how many customers in San Francisco are married; MARRIED_CUSTOMERS----------------- 18 SQL> select ai showsql how many customers in San Francisco are married; RESPONSE--------------------------------------------------------------------------------SELECT COUNT(*) AS married_customers_countFROM SH.CUSTOMERS cWHERE c.CUST_CITY = 'San Francisco' AND c.CUST_MARITAL_STATUS = 'Married' SQL> select ai narrate what are the top 3 customers in San Francisco; RESPONSE--------------------------------------------------------------------------------The top 3 customers in San Francisco are: 1. Hector Colven - Total amount sold: $52,025.992. Milburn Klemm - Total amount sold: $50,842.283. Gavin Xie - Total amount sold: $48,677.18 SQL> select ai chat what is Autonomous Database; RESPONSE--------------------------------------------------------------------------------Autonomous Database is a cloud-based database service provided by Oracle. It isdesigned to automate many of the routine tasks involved in managing a database,such as patching, tuning, and backups. Autonomous Database uses machine learning and automation to optimize performance, security, and availability, allowing users to focus on their applications and data rather than database administrationtasks. It offers both Autonomous Transaction Processing (ATP) for transactionalworkloads and Autonomous Data Warehouse (ADW) for analytical workloads. Autonomous Database provides high performance, scalability, and reliability, making it an ideal choice for modern cloud-based applications.SQL> select ai explainsql how many customers in San Francisco are married; RESPONSE--------------------------------------------------------------------------------SELECT COUNT(*) AS customer_countFROM SH.CUSTOMERS AS cWHERE c.CUST_STATE_PROVINCE = 'San Francisco' AND c.CUST_MARITAL_STATUS = 'Married'; Explanation:- We use the 'SH' table alias for the 'CUSTOMERS' table for better readability.- The query uses the 'COUNT(*)' function to count the number of rows that match the given conditions.- The 'WHERE' clause is used to filter the results: - 'c.CUST_STATE_PROVINCE = 'San Francisco'' filters customers who have 'San Francisco' as their state or province. - 'c.CUST_MARITAL_STATUS = 'Married'' filters customers who have 'Married' as their marital status.The result of this query will give you the count of customers in San Francisco who are married, using the column alias 'customer_count' for the result. Remember to adjust the table and column names based on your actual schema if they differ from the example. Feel free to ask if you have more questions related to SQL or database in general. SQL> EXEC DBMS_CLOUD_AI.DROP_PROFILE('AZUREAI'); PL/SQL procedure successfully completed.

Ejemplo: selección de IA con el principio de Azure OpenAI Service

Conéctese como ADMIN para proporcionar acceso a la autenticación del principio de servicio de Azure y, a continuación, otorgue los permisos de ACL de red al usuario (ADB_USER) que desea utilizar Select AI. Para proporcionar acceso a los recursos de Azure, consulte Uso de la entidad de servicio de Azure para acceder a los recursos de Azure.

Nota

Solo un usuario ADMIN puede ejecutar el procedimiento de ACL de red y privilegios EXECUTE.

-- Connect as ADMIN user and enable Azure service principal authentication.BEGIN DBMS_CLOUD_ADMIN.ENABLE_PRINCIPAL_AUTH(provider => 'AZURE', params => JSON_OBJECT('azure_tenantid' value 'azure_tenantid'));END;/ -- Copy the consent url from cloud_integrations view and consents the ADB-S application.SQL> select param_value from CLOUD_INTEGRATIONS where param_name = 'azure_consent_url';PARAM_VALUE--------------------------------------------------------------------------------https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/authorize?client_id=<client_id>&response_type=code&scope=User.read -- On the Azure OpenAI IAM console, search for the Azure application name and assign the permission to the application.-- You can get the application name in the cloud_integrations view.SQL> select param_value from CLOUD_INTEGRATIONS where param_name = 'azure_app_name';PARAM_VALUE--------------------------------------------------------------------------------ADBS_APP_DATABASE_OCID ---- Grant Network ACL for Azure OpenAI endpoint--SQL> BEGIN DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE( host => 'azure_resource_name.openai.azure.com', ace => xs$ace_type(privilege_list => xs$name_list('http'), principal_name => 'ADB_USER', principal_type => xs_acl.ptype_db) ); END; / PL/SQL procedure successfully completed. ---- Create AI profile--SQL> BEGIN DBMS_CLOUD_AI.CREATE_PROFILE( 'AZUREAI', '{"provider": "azure", "credential_name": "AZURE$PA", "object_list": [{"owner": "SH", "name": "customers"}, {"owner": "SH", "name": "countries"}, {"owner": "SH", "name": "supplementary_demographics"}, {"owner": "SH", "name": "profits"}, {"owner": "SH", "name": "promotions"}, {"owner": "SH", "name": "products"}], "azure_resource_name": "<azure_resource_name>", "azure_deployment_name": "<azure_deployment_name>" }'); END; / PL/SQL procedure successfully completed. ---- Enable AI profile in current session--SQL> EXEC DBMS_CLOUD_AI.SET_PROFILE('AZUREAI'); PL/SQL procedure successfully completed. ---- Get Profile in current session--SQL> SELECT DBMS_CLOUD_AI.get_profile() from dual; DBMS_CLOUD_AI.GET_PROFILE()--------------------------------------------------------------------------------"AZUREAI" ---- Use AI--SQL> select ai how many customers exist; CUSTOMER_COUNT-------------- 55500 SQL> select ai how many customers in San Francisco are married; MARRIED_CUSTOMERS----------------- 18 SQL> select ai showsql how many customers in San Francisco are married; RESPONSE--------------------------------------------------------------------------------SELECT COUNT(*) AS married_customers_countFROM SH.CUSTOMERS cWHERE c.CUST_CITY = 'San Francisco' AND c.CUST_MARITAL_STATUS = 'Married' SQL> select ai narrate what are the top 3 customers in San Francisco; RESPONSE--------------------------------------------------------------------------------The top 3 customers in San Francisco are: 1. Hector Colven - Total amount sold: $52,025.992. Milburn Klemm - Total amount sold: $50,842.283. Gavin Xie - Total amount sold: $48,677.18 SQL> select ai chat what is Autonomous Database; RESPONSE--------------------------------------------------------------------------------Autonomous Database is a cloud-based database service provided by Oracle. It isdesigned to automate many of the routine tasks involved in managing a database,such as patching, tuning, and backups. Autonomous Database uses machine learning and automation to optimize performance, security, and availability, allowing users to focus on their applications and data rather than database administrationtasks. It offers both Autonomous Transaction Processing (ATP) for transactionalworkloads and Autonomous Data Warehouse (ADW) for analytical workloads. Autonomous Database provides high performance, scalability, and reliability, making it an ideal choice for modern cloud-based applications.SQL> select ai explainsql how many customers in San Francisco are married; RESPONSE--------------------------------------------------------------------------------SELECT COUNT(*) AS customer_countFROM SH.CUSTOMERS AS cWHERE c.CUST_STATE_PROVINCE = 'San Francisco' AND c.CUST_MARITAL_STATUS = 'Married'; Explanation:- We use the 'SH' table alias for the 'CUSTOMERS' table for better readability.- The query uses the 'COUNT(*)' function to count the number of rows that match the given conditions.- The 'WHERE' clause is used to filter the results: - 'c.CUST_STATE_PROVINCE = 'San Francisco'' filters customers who have 'San Francisco' as their state or province. - 'c.CUST_MARITAL_STATUS = 'Married'' filters customers who have 'Married' as their marital status.The result of this query will give you the count of customers in San Francisco who are married, using the column alias 'customer_count' for the result. Remember to adjust the table and column names based on your actual schema if they differ from the example. Feel free to ask if you have more questions related to SQL or database in general. SQL> EXEC DBMS_CLOUD_AI.DROP_PROFILE('AZUREAI'); PL/SQL procedure successfully completed.

Seleccionar IA con clave de API de IA generativa de OCI

En el siguiente ejemplo se muestra cómo puede acceder a OCI Generative AI mediante su clave de API de OCI, crear un perfil de AI y generar SQL a partir de peticiones de datos de lenguaje natural.

Nota

La IA generativa de OCI utiliza cohere.command como modelo por defecto si no especifica model_name. Para obtener más información sobre los parámetros, consulte Atributos de perfil.

-- Create Credential with OCI API key--BEGIN DBMS_CLOUD.CREATE_CREDENTIAL( credential_name => 'GENAI_CRED', user_ocid => 'ocid1.user.oc1..aaaa...', tenancy_ocid => 'ocid1.tenancy.oc1..aaaa...', private_key => '<your_api_key>', fingerprint => '<your_fingerprint>' ); END; / ---- Create AI profile--SQL> BEGIN DBMS_CLOUD_AI.CREATE_PROFILE( 'GENAI', '{"provider": "oci", "credential_name": "GENAI_CRED" }'); END; / PL/SQL procedure successfully completed. ---- Enable AI profile in current session--SQL> EXEC DBMS_CLOUD_AI.SET_PROFILE('GENAI'); PL/SQL procedure successfully completed. ---- Get Profile in current session--SQL> SELECT DBMS_CLOUD_AI.get_profile() from dual; DBMS_CLOUD_AI.GET_PROFILE()--------------------------------------------------------------------------------"GENAI" ---- Use AI-- SQL> select ai chat what is Autonomous Database; RESPONSE--------------------------------------------------------------------------------Autonomous Database is a cloud-based database service provided by Oracle. It isdesigned to automate many of the routine tasks involved in managing a database,such as patching, tuning, and backups. Autonomous Database uses machine learning and automation to optimize performance, security, and availability, allowing users to focus on their applications and data rather than database administrationtasks. It offers both Autonomous Transaction Processing (ATP) for transactionalworkloads and Autonomous Data Warehouse (ADW) for analytical workloads. Autonomous Database provides high performance, scalability, and reliability, making it an ideal choice for modern cloud-based applications.SQL> EXEC DBMS_CLOUD_AI.DROP_PROFILE('GENAI'); PL/SQL procedure successfully completed.

Seleccionar IA con entidad de recurso de IA generativa de OCI

Para utilizar la entidad de recurso con OCI Generative AI, el administrador de arrendamiento de Oracle Cloud Infrastructure debe otorgar acceso a los recursos de Generative AI a un grupo dinámico. Consulte Cumplimiento de requisitos para utilizar la entidad de recurso con Autonomous Database para proporcionar acceso a un grupo dinámico.

Configure las políticas necesarias para obtener acceso a todos los recursos de IA generativa. Consulte https://docs.oracle.com/en-us/iaas/Content/generative-ai/iam-policies.htm para obtener más información sobre las políticas de IA generativa.

  • Para obtener acceso a todos los recursos de IA generativa de todo el arrendamiento, utilice la siguiente política:

    allow group <your-group-name> to manage generative-ai-family in tenancy
  • Para obtener acceso a todos los recursos de IA generativa del compartimento, utilice la siguiente política:

    allow group <your-group-name> to manage generative-ai-family in compartment <your-compartment-name>

Conéctese como administrador y active la entidad de recurso de OCI. Consulte ENABLE_PRINCIPAL_AUTH Procedure para configurar los parámetros.

Nota

La IA generativa de OCI utiliza cohere.command como modelo por defecto si no especifica model_name. Para obtener más información sobre los parámetros, consulte Atributos de perfil.

-- Connect as ADMIN user and enable OCI resource principal.BEGIN DBMS_CLOUD_ADMIN.ENABLE_PRINCIPAL_AUTH(provider => 'OCI');END;/ ---- Create AI profile--SQL>BEGIN DBMS_CLOUD_AI.CREATE_PROFILE( 'GENAI', '{"provider": "oci", "credential_name": "OCI$RESOURCE_PRINCIPAL" }'); END; / PL/SQL procedure successfully completed. ---- Enable AI profile in current session--SQL>EXEC DBMS_CLOUD_AI.SET_PROFILE('GENAI'); PL/SQL procedure successfully completed.---- Get Profile in current session--SQL> SELECT DBMS_CLOUD_AI.get_profile() from dual; DBMS_CLOUD_AI.GET_PROFILE()--------------------------------------------------------------------------------"GENAI" -- Use AI SQL> select ai chat what is Autonomous Database; RESPONSE--------------------------------------------------------------------------------Autonomous Database is a cloud-based database service provided by Oracle. It isdesigned to automate many of the routine tasks involved in managing a database,such as patching, tuning, and backups. Autonomous Database uses machine learning and automation to optimize performance, security, and availability, allowing users to focus on their applications and data rather than database administrationtasks. It offers both Autonomous Transaction Processing (ATP) for transactionalworkloads and Autonomous Data Warehouse (ADW) for analytical workloads. Autonomous Database provides high performance, scalability, and reliability, making it an ideal choice for modern cloud-based applications.SQL> EXEC DBMS_CLOUD_AI.DROP_PROFILE('GENAI'); PL/SQL procedure successfully completed.

Seleccionar IA con OCI Generative AI mediante el modelo LLMA

En este ejemplo se muestra la función chat del modelo LLMA de OCI Generative AI. Destaca las capacidades del modelo a través de dos indicaciones: generar un correo electrónico amigable a los clientes para las recomendaciones de películas y generar un párrafo introductorio sobre la escalada en roca.

SQL> BEGIN DBMS_CLOUD.CREATE_CREDENTIAL( credential_name => 'GENAI_CRED', user_ocid => 'ocid1.user.oc1..aaa',tenancy_ocid => 'ocid1.tenancy.oc1..aaa',private_key => '<your_api_key>',fingerprint => '<your_fingerprint>' ); END; /PL/SQL procedure successfully completed.BEGIN DBMS_CLOUD_AI.CREATE_PROFILE( 'GENAI', '{"provider": "oci","model": "meta.llama-2-70b-chat","oci_runtimetype":"LLAMA"}');END; /PL/SQL procedure successfully completed.SQL> BEGIN DBMS_CLOUD_AI.SET_ATTRIBUTE( 'GENAI', 'credential_name', 'GENAI_CRED'); END; / PL/SQL procedure successfully completed.SQL > BEGIN DBMS_CLOUD_AI.SET_ATTRIBUTE( 'GENAI', 'oci_compartment_id', 'ocid1.compartment.oc1...'); END; /PL/SQL procedure successfully completed.SQL> EXEC DBMS_CLOUD_AI.SET_PROFILE('GENAI'); PL/SQL procedure successfully completed.SQL> set linesize 150 SQL> SELECT AI chat Generate a friendly email to customer Gilbert Lee with two action-thriller movie recommendations available through our MovieStream service;SQL> RESPONSE------------------------------------------------------------------------------------------------------------------------------------------------------.Subject: Action-packed movie recommendations for you!Dear Gilbert,I hope this email finds you well! I wanted to reach out to you today to recommend two action-thriller movies that are currently available on our MovieStream service. I think you'll really enjoy them!The first movie I recommend is "John Wick" starring Keanu Reeves. This movie follows the story of a retired hitman who seeks vengeance against a powerful crime lord and his army of assassins. The action scenes are intense and non-stop, and Keanu Reeves delivers an outstanding performance.RESPONSE------------------------------------------------------------------------------------------------------------------------------------------------------The second movie I recommend is "Mission: Impossible - Fallout" starring Tom Cruise. This movie follows Ethan Hunt and his team as they try to prevent a global catastrophe. The action scenes are heart-stopping and the stunts are truly impressive. Tom Cruise once again proves why he's one of the greatest action stars of all time.Both of these movies are sure to keep you on the edge of your seat and provide plenty of thrills and excitement. They're available to stream now on MovieStream, so be sure to check them out!If you have any questions or need assistance with MovieStream, please don't hesitate to reach out to me. I'm always here to help.Thank you for being a valued customer, and I hope you enjoy the movies!RESPONSE------------------------------------------------------------------------------------------------------------------------------------------------------Best regards,[Your Name]MovieStream Customer ServiceSQL> SELECT AI chat Write an enthusiastic introductory paragraph on how to get started with rock climbing with Athletes as the target audience;RESPONSE------------------------------------------------------------------------------------------------------------------------------------------------------Rock climbing is an exhilarating and challenging sport that's perfect for athletes looking to push their limits and test their strength, endurance, and mental toughness. Whether you're a seasoned athlete or just starting out, rock climbing offers a unique and rewarding experience that will have youhooked from the very first climb. With its combination of physical and mental challenges, rock climbing is a great way to build strength, improve flexibility, and develop problem-solving skills. Plus, with the supportive community of climbers and the breathtaking views from the top of the climb, you'll be hooked from the very first climb. So, if you're ready to take on a new challenge and experience the thrill of adventure, then it's time to getstarted with rock climbing!

Mejorar la generación de consultas SQL agregando comentarios a tablas y columnas de base de datos

En este ejemplo se muestra cómo los comentarios de las tablas y columnas de la base de datos pueden mejorar la generación de consultas SQL a partir de peticiones de datos en lenguaje natural. En este ejemplo, Azure OpenAI Service actúa como proveedor de IA. El parámetro "comments":"true" de la función DBMS_CLOUD_AI.CREATE_PROFILE determina si los comentarios se transfieren al modelo para la generación de SQL.

-- Adding comments to table 1, table 2, and table 3. Table 1 has 3 columns, table 2 has 7 columns, table 3 has 2 columns.-- TABLE1COMMENT ON TABLE table1 IS 'Contains movies, movie titles and the year it was released';COMMENT ON COLUMN table1.c1 IS 'movie ids. Use this column to join to other tables';COMMENT ON COLUMN table1.c2 IS 'movie titles';COMMENT ON COLUMN table1.c3 IS 'year the movie was released';-- TABLE2COMMENT ON TABLE table2 IS 'transactions for movie views - also known as streams';COMMENT ON COLUMN table2.c1 IS 'day the movie was streamed';COMMENT ON COLUMN table2.c2 IS 'genre ids. Use this column to join to other tables';COMMENT ON COLUMN table2.c3 IS 'movie ids. Use this column to join to other tables';COMMENT ON COLUMN table2.c4 IS 'customer ids. Use this column to join to other tables';COMMENT ON COLUMN table2.c5 IS 'device used to stream, watch or view the movie';COMMENT ON COLUMN table2.c6 IS 'sales from the movie';COMMENT ON COLUMN table2.c7 IS 'number of views, watched, streamed';-- TABLE3COMMENT ON TABLE table3 IS 'Contains the genres';COMMENT ON COLUMN table3.c1 IS 'genre id. use this column to join to other tables';COMMENT ON COLUMN table3.c2 IS 'name of the genre';BEGIN DBMS_CLOUD_AI.CREATE_PROFILE( profile_name => 'myprofile', attributes => '{"provider": "azure", "azure_resource_name": "my_resource", "azure_deployment_name": "my_deployment", "credential_name": "my_credential", "comments":"true", "object_list": [ {"owner": "moviestream", "name": "table1"}, {"owner": "moviestream", "name": "table2"}, {"owner": " moviestream", "name": "table3"} ] }' ); DBMS_CLOUD_AI.SET_PROFILE( profile_name => 'myprofile' );END;/--Promptsselect ai what are our total views;RESPONSE-------------------------------------------------TOTAL_VIEWS----------- 97890562select ai showsql what are our total views;RESPONSE -------------------------------------------------------------------------SELECT SUM(QUANTITY_SOLD) AS total_viewsFROM "moviestream"."table"select ai what are our total views broken out by device;DEVICE TOTAL_VIEWS-------------------------- -----------mac 14719238iphone 20793516ipad 15890590pc 14715169galaxy 10587343pixel 10593551lenovo 5294239fire 52969168 rows selected. select ai showsql what are our total views broken out by device;RESPONSE ---------------------------------------------------------------------------------------SELECT DEVICE, COUNT(*) AS TOTAL_VIEWSFROM "moviestream"."table"GROUP BY DEVICE
Use Select AI to Generate SQL from Natural Language Prompts (2024)

References

Top Articles
Latest Posts
Article information

Author: Kareem Mueller DO

Last Updated:

Views: 6001

Rating: 4.6 / 5 (66 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Kareem Mueller DO

Birthday: 1997-01-04

Address: Apt. 156 12935 Runolfsdottir Mission, Greenfort, MN 74384-6749

Phone: +16704982844747

Job: Corporate Administration Planner

Hobby: Mountain biking, Jewelry making, Stone skipping, Lacemaking, Knife making, Scrapbooking, Letterboxing

Introduction: My name is Kareem Mueller DO, I am a vivacious, super, thoughtful, excited, handsome, beautiful, combative person who loves writing and wants to share my knowledge and understanding with you.