I'm working on a Django project where I need to execute a complex Oracle SQL query that involves multiple database links. I have already configured the database credentials for both databases in my Django settings, but I'm struggling with how to correctly execute a query that fetches data from different databases through these links.
Here's a sample of the type of query I'm trying to execute:
SELECT
CASE
WHEN ACDMH_LOC_CODE LIKE '02%' THEN 'KHOBAR'
WHEN ACDMH_LOC_CODE LIKE '03%' THEN 'RIYADH'
ELSE 'JEDDAH'
END AS Region,
ACDMH_INTF_YN,
ACDMH_TRANSACTION_TYPE AS TRANSACTION_TYPE,
ACDMH_SOURCE_DOC_NO AS SOURCE_DOC_NO,
TO_CHAR(ACDMH_TRANSACTION_DATE, 'dd-MM-yyyy') AS TRANSACTION_DATE,
ACDMH_CUSTOMER_ID AS CUSTOMER_No,
CUSTOMER_NAME,
TO_CHAR(ACDMH_CRE_DATE, 'dd-mm-yyyy') AS Pushed_date_WinIT,
TO_CHAR(ACDMH_CRE_DATE, 'hh:mi:ss AM') AS Pushed_time_WinIT,
ACDMH_INTF_ORA_REF AS ERP_REF,
ACDMH_LOC_CODE AS LOC_CODE,
ACDMD_ORIGINAL_INVOICE_NO AS ORIGINAL_INVOICE_NO,
ACDMD_OLD_VALUE AS fake_PRICE,
ACDMD_NEW_VALUE AS selling_price,
ACDMD_TOTAL AS tran_value,
ACDMD_TAX_AMOUNT AS TAX_AMOUNT
FROM
AX_CREDIT_DEBIT_MEMO_HEADERS@erpbridge
INNER JOIN AX_CREDIT_DEBIT_MEMO_LINES@erpbridge ON ACDMH_HEADER_ID = ACDMD_HEADER_ID
LEFT JOIN AXKSA_ORACLE_CUSTOMER ON CUSTOMER_NUMBER = ACDMH_CUSTOMER_ID
WHERE
[some conditions];
This query involves database links (@erpbridge) to other sources. I'm unsure how to execute such a query in Django, especially considering the database links.
I have the following questions:
How can I execute this Oracle SQL query in Django, given the use of multiple database links? Are there any specific configurations or considerations in Django for handling Oracle database links? Is using Django's raw SQL query execution the right approach for this, or is there a more efficient method? Any guidance or examples would be greatly appreciated!