|
| 1 | +--run as aiuser |
| 2 | + |
| 3 | +CREATE TABLE aivision_results |
| 4 | + (id RAW (16) NOT NULL, |
| 5 | + date_loaded TIMESTAMP WITH TIME ZONE, |
| 6 | + label varchar2(20), |
| 7 | + jsondata CLOB |
| 8 | + CONSTRAINT ensure_aivision_results_json CHECK (jsondata IS JSON)); |
| 9 | +create index aivisionresultsindex on aivision_results(jsondata) indextype is ctxsys.context; |
| 10 | +--select index_name, index_type, status from user_indexes where index_name = 'AIVISIONAIRESULTSINDEX'; |
| 11 | +--select idx_name, idx_table, idx_text_name from ctx_user_indexes; |
| 12 | +--select token_text from dr$aivisionresultsindex$i; |
| 13 | + |
| 14 | + |
| 15 | +CREATE TABLE aispeech_results |
| 16 | + (id RAW (16) NOT NULL, |
| 17 | + date_loaded TIMESTAMP WITH TIME ZONE, |
| 18 | + label varchar2(20), |
| 19 | + jsondata CLOB |
| 20 | + CONSTRAINT aispeech_results_json CHECK (jsondata IS JSON)); |
| 21 | +create index aispeechresultsindex on aispeech_results(jsondata) indextype is ctxsys.context; |
| 22 | +--select index_name, index_type, status from user_indexes where index_name = 'AISPEECHRESULTSINDEX'; |
| 23 | +--select idx_name, idx_table, idx_text_name from ctx_user_indexes; |
| 24 | +--select token_text from dr$aispeechresultsindex$i; |
| 25 | + |
| 26 | +CREATE OR REPLACE FUNCTION execute_dynamic_sql(p_sql IN VARCHAR2) RETURN VARCHAR2 IS |
| 27 | + v_result VARCHAR2(4000); |
| 28 | +BEGIN |
| 29 | + EXECUTE IMMEDIATE p_sql INTO v_result; |
| 30 | + RETURN v_result; |
| 31 | +EXCEPTION |
| 32 | + WHEN OTHERS THEN |
| 33 | + RETURN SQLERRM; |
| 34 | +END execute_dynamic_sql; |
| 35 | +/ |
| 36 | + |
| 37 | +BEGIN |
| 38 | + ORDS.ENABLE_OBJECT( |
| 39 | + P_ENABLED => TRUE, |
| 40 | + P_SCHEMA => 'AIUSER', |
| 41 | + P_OBJECT => 'EXECUTE_DYNAMIC_SQL', |
| 42 | + P_OBJECT_TYPE => 'FUNCTION', |
| 43 | + P_OBJECT_ALIAS => 'EXECUTE_DYNAMIC_SQL', |
| 44 | + P_AUTO_REST_AUTH => FALSE |
| 45 | + ); |
| 46 | + COMMIT; |
| 47 | +END; |
| 48 | + |
| 49 | +--Easy Text Search over Multiple Tables and Views with DBMS_SEARCH in 23c |
| 50 | +--workshop: https://apexapps.oracle.com/pls/apex/r/dbpm/livelabs/view-workshop?wid=3721 |
| 51 | + |
| 52 | +BEGIN |
| 53 | +dbms_cloud.create_credential ( |
| 54 | + credential_name => 'OCI_KEY_CRED', |
| 55 | + user_ocid => 'ocid1.user.oc1..[youruserocid]', |
| 56 | + tenancy_ocid => 'ocid1.tenancy.oc1..[yourtenancyocid]', |
| 57 | + private_key => '[yourprivatekey you can read this from file or put the contents of your pem without header, footer, and line wraps]' |
| 58 | + fingerprint => '[7f:yourfingerprint]' |
| 59 | +); |
| 60 | +END; |
| 61 | + |
| 62 | + |
| 63 | +create or replace FUNCTION call_analyze_image_api_objectstore ( |
| 64 | + p_endpoint VARCHAR2, |
| 65 | + p_compartment_ocid VARCHAR2, |
| 66 | + p_namespaceName VARCHAR2, |
| 67 | + p_bucketName VARCHAR2, |
| 68 | + p_objectName VARCHAR2, |
| 69 | + p_featureType VARCHAR2, |
| 70 | + p_label VARCHAR2 |
| 71 | +) RETURN CLOB IS |
| 72 | + resp DBMS_CLOUD_TYPES.resp; |
| 73 | + json_response CLOB; |
| 74 | +BEGIN |
| 75 | + resp := DBMS_CLOUD.send_request( |
| 76 | + credential_name => 'OCI_KEY_CRED', |
| 77 | + uri => p_endpoint || '/20220125/actions/analyzeImage', |
| 78 | + method => 'POST', |
| 79 | + body => UTL_RAW.cast_to_raw( |
| 80 | + JSON_OBJECT( |
| 81 | + 'features' VALUE JSON_ARRAY( |
| 82 | + JSON_OBJECT('featureType' VALUE p_featureType) |
| 83 | + ), |
| 84 | + 'image' VALUE JSON_OBJECT( |
| 85 | + 'source' VALUE 'OBJECT_STORAGE', |
| 86 | + 'namespaceName' VALUE p_namespaceName, |
| 87 | + 'bucketName' VALUE p_bucketName, |
| 88 | + 'objectName' VALUE p_objectName |
| 89 | + ), |
| 90 | + 'compartmentId' VALUE p_compartment_ocid |
| 91 | + ) |
| 92 | + ) |
| 93 | + ); |
| 94 | + json_response := DBMS_CLOUD.get_response_text(resp); |
| 95 | +-- dbms_output.put_line('json_response: ' || json_response); |
| 96 | + INSERT INTO aivision_results VALUES (SYS_GUID(), SYSTIMESTAMP, p_label, json_response ); |
| 97 | + RETURN json_response; |
| 98 | +EXCEPTION |
| 99 | + WHEN OTHERS THEN |
| 100 | + RAISE; |
| 101 | +END call_analyze_image_api_objectstore; |
| 102 | +/ |
| 103 | + |
| 104 | +BEGIN |
| 105 | + ORDS.ENABLE_OBJECT( |
| 106 | + P_ENABLED => TRUE, |
| 107 | + P_SCHEMA => 'AIUSER', |
| 108 | + P_OBJECT => 'CALL_ANALYZE_IMAGE_API_OBJECTSTORE', |
| 109 | + P_OBJECT_TYPE => 'FUNCTION', |
| 110 | + P_OBJECT_ALIAS => 'call_analyze_image_api_objectstore', |
| 111 | + P_AUTO_REST_AUTH => FALSE |
| 112 | + ); |
| 113 | + COMMIT; |
| 114 | +END; |
| 115 | +/ |
0 commit comments