-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6. Indexes.sql
More file actions
53 lines (44 loc) · 1.34 KB
/
6. Indexes.sql
File metadata and controls
53 lines (44 loc) · 1.34 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
---------------------------Index for searching customers by city--------------------
declare
index_exists NUMBER(1) :=0;
Begin
SELECT CASE WHEN EXISTS(SELECT * FROM USER_INDEXES WHERE INDEX_NAME = 'CUST_CITY')
THEN 1
ELSE 0
END CASE INTO index_exists
FROM DUAL;
IF index_exists = 1
THEN
DBMS_OUTPUT.PUT_LINE('INDEX EXIST');
Execute Immediate 'Drop index cust_city';
END IF;
DBMS_OUTPUT.PUT_LINE('NO INDEX EXIST');
Execute Immediate 'CREATE INDEX cust_city
ON customer(c_city)';
END;
/
select * from customer where c_city like 'M%';
--------------------Index for searching managements that are closed-----------------------
declare
index_status NUMBER(1) :=0;
Begin
SELECT CASE WHEN EXISTS(SELECT * FROM USER_INDEXES WHERE INDEX_NAME = 'MANAGEMENT_STATUS')
THEN 1
ELSE 0
END CASE INTO index_status
FROM DUAL;
IF index_status = 1
THEN
DBMS_OUTPUT.PUT_LINE('INDEX EXIST');
Execute Immediate 'Drop index management_status';
END IF;
DBMS_OUTPUT.PUT_LINE('NO INDEX EXIST');
Execute Immediate 'CREATE INDEX management_status
ON management_company(m_enddate)';
END;
/
select m_id Management_no,m_name Management_name,m_city City,m_street Street,
m_state State,m_zipcode Zipcode,m_contact Phone_no, m_websiteurl Website, m_startdate Management_startdate,
m_enddate Management_enddate,
'Closed' as Management_status
from management_company where m_enddate < sysdate;