Oracle.Database

D

T

The M Code Behind the Power Query M function Oracle.Database

Introduction to Oracle.Database function

The Oracle.Database function is part of the Power Query M language. It’s used to connect to and retrieve data from Oracle databases. This function takes several parameters such as server, database, username, and password. Once connected, you can use other M functions to query and transform data.

M Code Behind Oracle.Database

The M code behind the Oracle.Database function is quite complex. It includes several steps to connect to the Oracle database and retrieve data. The following is a breakdown of the M code behind the Oracle.Database function:

1. Create a connection string: The first step is to create a connection string. This string includes information about the Oracle server, database, username, and password. The connection string is created using the following M code:


let

server = “OracleServerName”,

database = “OracleDatabaseName”,

user = “OracleUserName”,

password = “OraclePassword”,

connectionstring = “Provider=OraOLEDB.Oracle;Data Source=” & server & “;User Id=” & user & “;Password=” & password & “;”

in

connectionstring


2. Connect to the Oracle database: The next step is to connect to the Oracle database using the connection string. This is done using the following M code:


let

connectionstring = [connection string created in step 1],

db = Oracle.Database(connectionstring)

in

db


3. Retrieve data from a table: Once connected to the Oracle database, you can retrieve data from a table using the Table.SelectRows function. This function takes two parameters - the table to retrieve data from and the criteria for selecting rows. The following M code retrieves all rows from a table named "Employees":


let

db = [database connection created in step 2],

employees = db{[Schema=”dbo”,Item=”Employees”]}[Data]

in

employees


4. Transform data: Once you have retrieved data from a table, you can use other M functions to transform the data. For example, you can use the Table.TransformColumns function to change the data type of a column. The following M code changes the data type of a column named "Salary" to a number:


let

employees = [data retrieved in step 3],

transformed = Table.TransformColumns(employees,{{“Salary”, type number}})

in

transformed


The Oracle.Database function is a powerful tool for connecting to and retrieving data from Oracle databases. Its M code is complex but can be broken down into several steps. Understanding the M code behind this function is essential for working with Oracle databases in Power Query M. With this knowledge, you can easily connect to and retrieve data from Oracle databases and use other M functions to transform and analyze the data.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)