The installation procedure is divided into four clips.
This link shows how to create a table.
Views expressed here are solely that of my own. Please make sure that you test the code/queries that appear on my blog before applying them to the production environment.
The installation procedure is divided into four clips.
This link shows how to create a table.
SQL> set serveroutput on SQL> SQL> drop table t purge; Table dropped. SQL> create table t(a number, b varchar2(30), c date); Table created. SQL> declare 2 x number; 3 begin 4 x := dbms_utility.get_time; 5 for i in 1..100000 loop 6 insert into t values(i, 'value = ' || i, sysdate + mod(i,365)); 7 end loop; 8 dbms_output.put_line('Time taken WITHOUT indexes : ' ||to_char(dbms_utility.get_time - x)); 9 end; 10 / Time taken WITHOUT indexes : 475 PL/SQL procedure successfully completed.Now, repeat the same test by creating indexes on all the three columns. Test 2: With Indexes:
SQL> drop table t purge; Table dropped. SQL> SQL> create table t(a number, b varchar2(30), c date); Table created. SQL> SQL> SQL> create index t_idx1 on t(a); Index created. SQL> SQL> create index t_idx2 on t(b); Index created. SQL> SQL> create index t_idx3 on t(c); Index created. SQL> declare 2 x number; 3 begin 4 x := dbms_utility.get_time; 5 for i in 1..100000 loop 6 insert into t values(i, 'value = ' || i, sysdate + mod(i,365)); 7 end loop; 8 dbms_output.put_line('Time taken *WITH* indexes : ' ||to_char(dbms_utility.get_time - x)); 9 end; 10 / Time taken *WITH* indexes : 1006 PL/SQL procedure successfully completed.Well, it’s evident from the above tests that having too many indexes surely affects performance of DML statements. When I had three indexes, time taken to process 100,000 records was more than double compared to process the same number of records without indexes. Moral of the test is to create indexes when required and avoid over-creating them. Oracle documentation discusses some guidelines of using and managing indexes. Happy reading !!!
This question appeared on Project Euler. I thought of giving it a try using PL/SQL. Before I started to code, I thought of simplifying so that I can reach to the solution in most efficient way.
Any number which is divisible 20 is also divisible by 10, 5 and 1. Similarly, any number divisible by 18 is also divisible by 9. Following is the list of numbers:
Number | Divisible by |
20 | 10, 5, 1 |
18 | 9, 1 |
16 | 8, 4, 2, 1 |
14 | 7, 1 |
12 | 6, 3, 2, 1 |
10 | 5, 1 |
8 | 4, 2, 1 |
6 | 3, 2, 1 |
4 | 2, 1 |
Now that the problem is simplified, we can start our PL/SQL code.
SQL> set serveroutput on
SQL>
SQL> set timing on
SQL>
SQL> Declare
2 l_Result Boolean := FALSE;
3 l_Incr Number := 20;
4 l_Solution Number := 0;
5 Begin
6 while NOT l_Result loop
7 l_Solution := l_Solution + l_Incr;
8 If Mod(l_Solution, 11) = 0 And
9 Mod(l_Solution, 12) = 0 And
10 Mod(l_Solution, 13) = 0 And
11 Mod(l_Solution, 14) = 0 And
12 Mod(l_Solution, 15) = 0 And
13 Mod(l_Solution, 16) = 0 And
14 Mod(l_Solution, 17) = 0 And
15 Mod(l_Solution, 18) = 0 And
16 Mod(l_Solution, 19) = 0 And
17 Mod(l_Solution, 20) = 0 Then
18 l_Result := TRUE;
19 End If;
20 end loop;
21 Dbms_output.put_line('Iterations : ' || l_Solution/l_Incr);
22 Dbms_output.put_line('Smallest Number is : ' || l_Solution);
23 End;
24 /
Iterations : 11639628
Smallest Number is : 232792560
PL/SQL procedure successfully completed.
Elapsed: 00:00:10.98
SQL>
Happy reading !!!