forked from oracle-devrel/oracle-autonomous-database-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-export-to-datalake.sql
More file actions
58 lines (48 loc) · 1.44 KB
/
data-export-to-datalake.sql
File metadata and controls
58 lines (48 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
-- Copyright (c) 2025 Oracle and/or its affiliates.
-- Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
/** Export data to cloud storage **/
/* PREREQUISITES
Install the sample schema using script
@data-create-sample-schema.sql
*/
@config.sql
-- Create a credential in order to connect to data lake storage
@credential-create.sql storage
-- List the files in that storage container
SELECT object_name, bytes
FROM dbms_cloud.list_objects(
credential_name => '&STORAGE_CREDENTIAL_NAME',
location_uri => '&STORAGE_URL'
);
--
-- Export movie genre data to the data lake
--
-- Check out the data to be exported
SELECT *
FROM genre;
-- Export in CSV format
BEGIN
DBMS_CLOUD.EXPORT_DATA(
credential_name => '&STORAGE_CREDENTIAL_NAME',
file_uri_list => '&STORAGE_URL/data/genre/genre',
query => 'SELECT * FROM genre',
format => JSON_OBJECT('type' VALUE 'csv', 'delimiter' VALUE ',')
);
END;
/
-- Export in parquet format
BEGIN
DBMS_CLOUD.EXPORT_DATA(
credential_name => '&STORAGE_CREDENTIAL_NAME',
file_uri_list => '&STORAGE_URL/data/customer/customer',
query => 'SELECT * FROM genre',
format => JSON_OBJECT('type' VALUE 'parquet')
);
END;
/
-- List the files in that storage container. Notice the new genre data.
SELECT object_name, bytes
FROM dbms_cloud.list_objects(
credential_name => '&STORAGE_CREDENTIAL_NAME',
location_uri => '&STORAGE_URL'
);