Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Kindly check my code below for the above project attached befor this Question, I have issue in the fact table F _ ORDERS and D

Kindly check my code below for the above project attached befor this Question, I have issue in the fact table F_ORDERS and D_SALESMAN , thay are empty no data inside the tables and I make sure every things correct. please help me with this issues.
check the code below:
-- Project 1:
SELECT * from OE.CUSTOMERS;
CREATE TABLE CUSTOMER_COPY AS
SELECT
CUSTOMER_ID,
CUST_FIRST_NAME,
CUST_LAST_NAME,
NLS_LANGUAGE,
NLS_TERRITORY,
CREDIT_LIMIT,
CUST_EMAIL,
ACCOUNT_MGR_ID,
CUST_GEO_LOCATION,
DATE_OF_BIRTH,
MARITAL_STATUS,
GENDER,
INCOME_LEVEL
FROM OE.CUSTOMERS;
DESCRIBE CUSTOMER_COPY
ALTER TABLE CUSTOMER_COPY
ADD TURNOVER NUMBER(12,2);
SELECT * from CUSTOMER_COPY;
ALTER TABLE CUSTOMER_COPY
ADD CUST_TYPE VARCHAR2(1);
SELECT * from CUSTOMER_COPY;
select * from customer_copy order by customer_ID;
select * from OE.Orders order by customer_ID;
UPDATE CUSTOMER_COPY c
SET TURNOVER =(SELECT SUM(o.ORDER_TOTAL)
FROM OE.ORDERS o
WHERE o.CUSTOMER_ID = c.CUSTOMER_ID
GROUP BY o.CUSTOMER_ID);
SELECT * FROM customer_copy;
DECLARE
avg_turnover NUMBER(12,2);
BEGIN
-- Calculate average turnover
SELECT AVG(TURNOVER) INTO avg_turnover FROM CUSTOMER_COPY;
-- Update customer type
FOR cust_rec IN (SELECT * FROM CUSTOMER_COPY) LOOP
IF cust_rec.TURNOVER >= avg_turnover THEN
UPDATE CUSTOMER_COPY
SET CUST_TYPE ='A'
WHERE CUSTOMER_ID = cust_rec.CUSTOMER_ID;
ELSIF cust_rec.TURNOVER >= avg_turnover/2 THEN
UPDATE CUSTOMER_COPY
SET CUST_TYPE ='B'
WHERE CUSTOMER_ID = cust_rec.CUSTOMER_ID;
ELSE
UPDATE CUSTOMER_COPY
SET CUST_TYPE ='C'
WHERE CUSTOMER_ID = cust_rec.CUSTOMER_ID;
END IF;
END LOOP;
END;
/
SELECT * FROM customer_copy;
SELECT CUST_TYPE, COUNT(*) AS NUM_CUSTOMERS
FROM CUSTOMER_COPY
GROUP BY CUST_TYPE;
SELECT COUNT(*) AS TOTAL_CUSTOMERS
FROM CUSTOMER_COPY;
SELECT COUNT(DISTINCT NLS_TERRITORY) AS NUM_COUNTRIES
FROM OE.CUSTOMERS;
CREATE TABLE CURRENCY_RATES(
CUR_SIGN CHAR(3),
COUNTRY VARCHAR2(30),
CUR_QTY NUMBER(4),
EURO_RATE NUMBER(8,6)
)
;
INSERT INTO CURRENCY_RATES (CUR_SIGN, COUNTRY, CUR_QTY, EURO_RATE)
VALUES ('CNY', 'CHINA', 1,0.13)
;
INSERT INTO CURRENCY_RATES (CUR_SIGN, COUNTRY, CUR_QTY, EURO_RATE)
VALUES ('INR', 'INDIA', 1,0.011)
;
INSERT INTO CURRENCY_RATES (CUR_SIGN, COUNTRY, CUR_QTY, EURO_RATE)
VALUES ('CHF', 'SWITZERLAND', 1,0.92)
;
INSERT INTO CURRENCY_RATES (CUR_SIGN, COUNTRY, CUR_QTY, EURO_RATE)
VALUES ('THB', 'THAILAND', 1,0.027)
;
INSERT INTO CURRENCY_RATES (CUR_SIGN, COUNTRY, CUR_QTY, EURO_RATE)
VALUES ('JPY', 'JAPAN', 1,0.0079)
;
INSERT INTO CURRENCY_RATES (CUR_SIGN, COUNTRY, CUR_QTY, EURO_RATE)
VALUES ('EUR', 'ITALY', 1,1)
;
INSERT INTO CURRENCY_RATES (CUR_SIGN, COUNTRY, CUR_QTY, EURO_RATE)
VALUES ('USD', 'AMERICA', 1,0.81)
;
INSERT INTO CURRENCY_RATES (CUR_SIGN, COUNTRY, CUR_QTY, EURO_RATE)
VALUES ('EUR', 'GERMANY', 1,1)
;
SELECT * FROM CURRENCY_RATES
;
CREATE TABLE ORDERS_IN_EURO AS
SELECT
O.ORDER_ID,
O.CUSTOMER_ID,
C.NLS_TERRITORY AS COUNTRY,
O.ORDER_TOTAL,
O.ORDER_TOTAL * CR.EURO_RATE AS ORDER_TOTAL_EURO
FROM
OE.ORDERS O
JOIN
OE.CUSTOMERS C ON O.CUSTOMER_ID = C.CUSTOMER_ID
JOIN
CURRENCY_RATES CR ON C.NLS_TERRITORY = CR.COUNTRY
;
CREATE OR REPLACE FUNCTION CONVERT_TO_EURO(
p_order_total IN NUMBER,
p_country IN VARCHAR2
) RETURN NUMBER AS
v_euro_rate NUMBER;
BEGIN
SELECT EURO_RATE INTO v_euro_rate
FROM CURRENCY_RATES
WHERE COUNTRY = p_country;
RETURN p_order_total * v_euro_rate;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN NULL;
END CONVERT_TO_EURO;
/
UPDATE ORDERS_IN_EURO
SET ORDER_TOTAL_EURO = CONVERT_TO_EURO(ORDER_TOTAL, COUNTRY)
;
SELECT * FROM ORDERS_IN_EURO
;
-
---------Project 2 and 3 in the attached pictures because it is not allowed here to write more. and for more clarification the project 1 & 2 is corrected and I submitted now I need to resolve project 3.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

Students also viewed these Databases questions

Question

1. Describe the factors that lead to productive conflict

Answered: 1 week ago