Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 24, 2016
0 parents
commit 93975cf
Showing
225 changed files
with
6,942 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
PROCEDURE insert_blob_proc IS | ||
Blob_loc BLOB; | ||
BEGIN | ||
SELECT ad_photo INTO Blob_loc | ||
FROM Print_media | ||
WHERE product_id = 3106 AND ad_id=13001; | ||
INSERT INTO Print_media VALUES (2056, 12001, Blob_loc); | ||
END; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <oci.h> | ||
#include <stdio.h> | ||
#include <sqlca.h> | ||
void Sample_Error() | ||
{ | ||
EXEC SQL WHENEVER SQLERROR CONTINUE; | ||
printf(�%.*s\n�, sqlca.sqlerrm.sqlerrml, sqlca.sqlerrm.sqlerrmc); | ||
EXEC SQL ROLLBACK WORK RELEASE; | ||
exit(1); | ||
} | ||
void insertBLOB_proc() | ||
{ | ||
OCIBlobLocator *Lob_loc; | ||
EXEC SQL WHENEVER SQLERROR DO Sample_Error(); | ||
/* Initialize the BLOB Locator: */ | ||
EXEC SQL ALLOCATE :Lob_loc; | ||
EXEC SQL SELECT ad_photo INTO :Lob_loc | ||
FROM Print_media WHERE product_id = 2268 AND ad_id = 21001; | ||
/* Insert into the row where product_id = 3106 and ad_id = 13001: */ | ||
EXEC SQL INSERT INTO Print_media | ||
VALUES (3106, 13001, :Lob_loc); | ||
/* Release resources held by the locator: */ | ||
EXEC SQL FREE :Lob_loc; | ||
} | ||
void main() | ||
{ | ||
char *samp = �pm/pm�; | ||
EXEC SQL CONNECT :pm; | ||
insertBLOB_proc(); | ||
EXEC SQL ROLLBACK WORK RELEASE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
create table customers ( | ||
pin_number number(6) ); | ||
|
||
alter table customers | ||
add constraint customers_pk | ||
primary key (pin_number); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
create or replace | ||
procedure gen_customer is | ||
v_new_cid customers.pin_number%type; | ||
begin | ||
loop | ||
begin | ||
v_new_cid := round(dbms_random.value(1000000,9999999)); | ||
insert into customers | ||
values (v_new_cid); | ||
exit; | ||
exception when dup_val_on_index then | ||
null; | ||
end; | ||
end loop; | ||
end; | ||
/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
set timing on | ||
begin | ||
gen_customer; | ||
commit; | ||
end; | ||
/ | ||
|
||
begin | ||
for i in 1 .. 100000 loop | ||
gen_customer; | ||
end loop; | ||
commit; | ||
end; | ||
/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
alter table CUSTOMERS modify PIN_NUMBER number(12); | ||
create sequence cust_seq cache 1000 | ||
start with 100000; | ||
|
||
create or replace | ||
procedure gen_customer is | ||
v_new_cid customers.pin_number%type; | ||
begin | ||
insert into customers | ||
values (cust_seq.nextval*100000+ | ||
round(dbms_random.value(100000,999999))); | ||
end; | ||
/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
begin | ||
for i in 1 .. 10000 loop | ||
gen_customer; | ||
end loop; | ||
commit; | ||
end; | ||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
alter system set job_queue_processes = 20; | ||
create table CUSTLOG ( elapsed_centiseconds number); | ||
|
||
declare | ||
j number; | ||
job_string varchar2(1000) := | ||
�declare | ||
s number := dbms_utility.get_time; | ||
begin | ||
for i in 1 .. 10000 loop | ||
gen_customer; | ||
end loop; | ||
insert into custlog values (dbms_utility.get_time-s); | ||
commit; | ||
end;�; | ||
begin | ||
for i in 1 .. 20 loop | ||
dbms_job.submit(j,job_string); | ||
end loop; | ||
end; | ||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
create table people( pid primary key ) | ||
organization index | ||
as select rownum from all_objects | ||
where rownum <= 10000; | ||
|
||
create or replace | ||
procedure literals is | ||
c number; | ||
p number; | ||
x number; | ||
x1 number; | ||
begin | ||
for i in 1 .. 10000 loop | ||
c := dbms_sql.open_cursor; | ||
dbms_sql.parse(c, | ||
�select pid from people �|| | ||
�where pid = �||i, dbms_sql.native); | ||
x := dbms_sql.execute(c); | ||
x1 := dbms_sql.fetch_rows(c); | ||
dbms_sql.close_cursor(c); | ||
end loop; | ||
end; | ||
/ | ||
|
||
set timing on | ||
alter session set sql_trace = true; | ||
exec literals; | ||
alter session set sql_trace = false; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
create or replace | ||
procedure literals(tag number) is | ||
c number; | ||
p number; | ||
x number; | ||
x1 number; | ||
begin | ||
for i in 1 .. 10000 loop | ||
c := dbms_sql.open_cursor; | ||
dbms_sql.parse(c, | ||
�select pid t�||tag||� from people �|| | ||
�where pid = �||i, dbms_sql.native); | ||
x := dbms_sql.execute(c); | ||
x1 := dbms_sql.fetch_rows(c); | ||
dbms_sql.close_cursor(c); | ||
end loop; | ||
end; | ||
/ | ||
|
||
|
||
exec literals(1); | ||
exec literals(2); | ||
exec literals(3); | ||
exec literals(4); | ||
|
||
select sid, event, time_waited | ||
from v$session_event | ||
where sid = &sid | ||
and event = �latch free�; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
create or replace | ||
procedure binding is | ||
c number; | ||
p number; | ||
x number; | ||
x1 number; | ||
begin | ||
for i in 1 .. 10000 loop | ||
c := dbms_sql.open_cursor; | ||
dbms_sql.parse(c, | ||
�select pid from people �|| | ||
�where pid = :b1�, dbms_sql.native); | ||
dbms_sql.bind_variable(c,�:b1�,i); | ||
x := dbms_sql.execute(c); | ||
x1 := dbms_sql.fetch_rows(c); | ||
dbms_sql.close_cursor(c); | ||
end loop; | ||
end; | ||
/ | ||
|
||
alter session set sql_trace = true; | ||
exec binding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
create or replace | ||
view V$MYSTATS as | ||
select s.name, m.value | ||
from v$mystat m, v$statname s | ||
where s.statistic# = m.statistic#; | ||
|
||
grant select on V$MYSTATS to public; | ||
create or replace public synonym V$MYSTATS for V$MYSTATS; | ||
select * from v$mystats | ||
where name like �parse%�; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
create or replace | ||
procedure binding is | ||
c number; | ||
p number; | ||
x number; | ||
x1 number; | ||
begin | ||
c := dbms_sql.open_cursor; | ||
dbms_sql.parse(c, | ||
�select pid from people �|| | ||
�where pid = :b1�, dbms_sql.native); | ||
for i in 1 .. 10000 loop | ||
dbms_sql.bind_variable(c,�:b1�,i); | ||
x := dbms_sql.execute(c); | ||
x1 := dbms_sql.fetch_rows(c); | ||
end loop; | ||
dbms_sql.close_cursor(c); | ||
end; | ||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
create or replace | ||
procedure EASY_AS_THAT is | ||
x1 number; | ||
begin | ||
for i in 1 .. 10000 loop | ||
select pid into x1 | ||
from people | ||
where pid = i; | ||
end loop; | ||
end; | ||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
create or replace | ||
procedure UPDATE_EMP(p_empno number, p_decrease number) is | ||
begin | ||
update EMP | ||
set SAL = SAL / p_decrease | ||
where empno = p_empno; | ||
end; | ||
/ | ||
exec UPDATE_EMP(7369,2); | ||
exec UPDATE_EMP(7369,0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
create or replace | ||
procedure UPDATE_EMP(p_empno number, p_decrease number, | ||
p_success out boolean) is | ||
begin | ||
if p_decrease = 0 then | ||
p_success := false; | ||
else | ||
update EMP | ||
set SAL = SAL / p_decrease | ||
where empno = p_empno; | ||
p_success := true; | ||
end if; | ||
end; | ||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
create or replace | ||
function binary_and(x number, y number) return number is | ||
max_bin number(22) := power(2,64); | ||
l_x number := x; | ||
l_y number := y; | ||
result number := 0; | ||
begin | ||
for i in reverse 0 .. 64 loop | ||
if l_x >= max_bin and l_y >= max_bin then | ||
result := result + max_bin; | ||
end if; | ||
if l_x >= max_bin then | ||
l_x := l_x - max_bin; | ||
end if; | ||
if l_y >= max_bin then | ||
l_y := l_y - max_bin; | ||
end if; | ||
max_bin := max_bin/2; | ||
end loop; | ||
return result; | ||
end; | ||
/ | ||
|
||
declare | ||
x number; | ||
begin | ||
for i in 1 .. 50000 loop | ||
x:= binary_and(i,i+1); | ||
end loop; | ||
end; | ||
/ | ||
declare | ||
x number; | ||
begin | ||
for i in 1 .. 50000 loop | ||
x:= bitand(i,i+1); | ||
end loop; | ||
end; | ||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
create table SRC ( x number ) pctfree 0; | ||
insert into SRC | ||
select rownum | ||
from all_objects | ||
where rownum < 10000; | ||
|
||
|
||
create table T1 as | ||
select trunc(created) created | ||
from all_objects; | ||
|
||
select trunc(sysdate)-14+x created, count(created) no_of_obj | ||
from t1, src | ||
where trunc(sysdate)-14+x = t1.created(+) | ||
and x <= 14 | ||
group by trunc(sysdate)-14+x | ||
/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
create or replace | ||
type date_list is table of Date; | ||
/ | ||
create or replace | ||
function pipe_date(p_start date, p_limit number) | ||
return date_list pipelined is | ||
begin | ||
for i in 0 .. p_limit-1 loop | ||
pipe row (p_start + i); | ||
end loop; | ||
return; | ||
end; | ||
/ | ||
|
||
select column_value, count(created) no_of_obj | ||
from t1, table(pipe_date(trunc(sysdate)-14,14)) | ||
where column_value = t1.created(+) | ||
group by column_value | ||
/ | ||
|
||
select /*+ CARDINALITY(t 14) */ column_value, count(created) no_of_obj | ||
from t1, table(pipe_date(trunc(sysdate)-14,14)) t | ||
where column_value = t1.created(+) | ||
group by column_value | ||
/ |
Oops, something went wrong.