Documente Academic
Documente Profesional
Documente Cultură
upper('SQL%'),'SQL*PLUS',
upper(substr(program,instr(program,'\',-1,1)+1))
) program,
logon_time,
status,
host_name 'Server Name'
FROM v$session
WHERE username = USER
/*where audsid = USERENV('SESSIONID') in the connect machine*/
/*******************************************************************************
*****/
--get server name
SELECT host_name FROM v$instance;
/*******************************************************************************
*****/
--get connection and server detail
set linesize 120
set feedback off
set serveroutput on
DECLARE
my_name varchar2(15);
my_ip
varchar2(15);
my_server varchar2(15);
v_host_name varchar2(15);
v_ip_address varchar2(15);
BEGIN
DBMS_OUTPUT.PUT_LINE('MY NAME
MY IP ADDRESS SERVER NAME
SERVER_I
P
SERVER');
DBMS_OUTPUT.PUT_LINE('--------------- --------------- --------------- -------------- ---------------');
SELECT UTL_INADDR.GET_HOST_NAME(v_host_name) into v_host_name FROM DUAL;
SELECT UTL_INADDR.GET_HOST_ADDRESS(v_host_name) into v_ip_address FROM DUAL;
SELECT RPAD(sys_context('USERENV','SESSION_USER'),15,' ') MY_NAME,
RPAD(sys_context('USERENV','IP_ADDRESS'),15,' ') MY_IP ,
RPAD(SYS_CONTEXT('USERENV', 'DB_NAME'),15,' ') SERVER
INTO my_name, my_ip, my_server
FROM DUAL;
DBMS_OUTPUT.PUT_LINE(rpad(my_name,15,' ')||' '||
rpad(my_ip,15,' ')||' '||
rpad(my_server,15,' ')||' '||
rpad(v_ip_address,15,' ')||' '||
rpad(v_host_name,15,' '));
END;
.
/
select
.
set feedback on
/*******************************************************************************
*****/
-- order by terminal
3 - to stop any connected user from using oracle :
alter system kill session '18,2161';
where - 18 is the SID and - 2161 is SERIAL#
4 - form builder :
forms_ddl('alter system kill session
'''||:sid||','||:serial#||'''');
do_key('execute_query');
*/
------------------------database version
select BANNER from v$version;
----------------------report with many distination
----------------------PROCEDURE Run_Report(P_destination varchar default 'screen') IS
PL_ID Paramlist;
Where_Clause Varchar2(250);
BEGIN
pl_id := Get_Parameter_List('Report');
IF NOT Id_Null(pl_id) THEN
Destroy_Parameter_List( pl_id );
END IF;
pl_ID := Create_Parameter_List('Report');
Add_Parameter(pl_id,'Paramform',Text_PARAMETER,'NO');
If User_Can_Print(:parameter.P_User_ID,:System.Current_Form) Then
Add_Parameter(pl_id,'DISABLEPRINT',Text_PARAMETER,'NO');
Add_Parameter(pl_id,'DISABLEMAIL',Text_PARAMETER,'NO');
Add_Parameter(pl_id,'DISABLEFILE',Text_PARAMETER,'NO');
Add_Parameter(pl_id,'DISABLENEW',Text_PARAMETER,'NO');
Else
Add_Parameter(pl_id,'DISABLEPRINT',Text_PARAMETER,'YES');
Add_Parameter(pl_id,'DISABLEMAIL',Text_PARAMETER,'YES');
Add_Parameter(pl_id,'DISABLEFILE',Text_PARAMETER,'YES');
Add_Parameter(pl_id,'DISABLENEW',Text_PARAMETER,'YES');
End If;
/*hamdy*/
if P_destination ='xls' then
Add_Parameter(pl_id,'DESFORMAT',Text_PARAMETER,'csv');
Add_Parameter(pl_id,'DESTYPE',Text_PARAMETER,'FILE');
Add_Parameter(pl_id,'MODE',Text_PARAMETER,'BITMAP');
Add_Parameter(pl_id,'DESNAME',Text_PARAMETER,'C:\TEMP\EXCEL.csv');
ELSif P_destination ='pdf' then
Add_Parameter(pl_id,'DESFORMAT',Text_PARAMETER,'pdf');
Add_Parameter(pl_id,'DESTYPE',Text_PARAMETER,'FILE');
Add_Parameter(pl_id,'MODE',Text_PARAMETER,'BITMAP');
Add_Parameter(pl_id,'DESNAME',Text_PARAMETER,'C:\TEMP\pdf.pdf');
ELSif P_destination ='rtf' then
Add_Parameter(pl_id,'DESFORMAT',Text_PARAMETER,'RTF');
Add_Parameter(pl_id,'DESTYPE',Text_PARAMETER,'FILE');
Add_Parameter(pl_id,'MODE',Text_PARAMETER,'BITMAP');
Add_Parameter(pl_id,'DESNAME',Text_PARAMETER,'C:\TEMP\word.rtf');
end if;
/*hamdy*/
Add_Parameter(pl_id,'P_Company_ID',Text_PARAMETER,:Params.level);
Where_Clause := ' and e.level_id='||:Params.level;
If :Params.Employee is not Null Then
Where_Clause :=Where_Clause||' And E.Emp_ID = '||
:Params.Employee ;
-message ('i will add the emp_id'||Where_Clause);
-message ('i will add the emp_id'||Where_Clause);
End If;
Add_Parameter(pl_id,'Where_Clause',Text_PARAMETER,Where_Clause);
Run_Product(REPORTS, 'HR_EMP_DTL', SYNCHRONOUS, RunTime,FILESYSTEM,
pl_id, NULL);
DESTROY_PARAMETER_LIST(pl_id);
END;
-----------------------------------------------------------------------------------PROCEDURE Open_application(app varchar2 default 'xls') IS
-- app_Path Varchar2(500):=
Win_API_Environment.Read_Registry('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\
8.0\Excel\InstallRoot', 'path',
TRUE);
File_Name Varchar2(150);
AppID PLS_INTEGER;
Begin
if app = 'xls' then
File_Name := 'D:\Program Files\Microsoft Office\Office\Excel
C:\temp\excel.xls';
Elsif app = 'rtf' then
File_Name := 'D:\Program Files\Microsoft Office\Office\winword
C:\temp\word.rtf';
Elsif app = 'pdf' then
File_Name := 'D:\Program Files\Adobe\Acrobat 5.0\Reader\acrord32
C:\temp\pdf.pdf';
End If;
if not file_name is null then
AppID := DDE.App_Begin(File_Name,DDE.App_Mode_Maximized);
end if;
Exception
when others then
Message(SQLCode||'-'||SQLErrm);
End;
-------------------------------------------------------------------------------calling the preceding 2 procedures:
--------------------------create a button labeld "Excel" with a when_button_pressed trigger:
RUN_Report('xls');
if form_success then
Open_application('xls');
end if;
-----------------------------------------------------------------------------------------------how to encrypt/decrypt passwords
--------------------------CREATE OR REPLACE FUNCTION hamdy_encrypt( p_psw varchar2) RETURN
varchar2 AS
v_return varchar2(50);
BEGIN
if p_psw is not null then
v_return := translate(p_psw,'
0123456789abcdefghijklmnopqrstuvwxyz','-9876543210zyxwvutsrqponmlkjihgfedcba');
RETURN v_return;
else
return null;
end if;
END;
/
-------------------------------CREATE OR REPLACE FUNCTION hamdy_decode( p_psw varchar2) RETURN
varchar2 AS
v_return varchar2(50);
BEGIN
if p_psw is not null then
v_return :=
translate(p_psw,'-9876543210zyxwvutsrqponmlkjihgfedcba',' 0123456789abcdefghijkl
mnopqrstuvwxyz');
RETURN v_return;
else
return null;
end if;
END;
/
---------------------------------------------------------------------------------------------------------------------------how to unify all symobles of a text to a unique symoble
---------------------------------------------------------CREATE OR REPLACE FUNCTION nosymbols (
p_text
VARCHAR2
,p_length NUMBER
)
RETURN VARCHAR2 IS
v_clean VARCHAR2 (2000);
BEGIN
v_clean := TRANSLATE (
p_text
,'~`!@#$%^&*()_-+={}|[]\:";''<>?,./'
,';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;'
);
RETURN (v_clean);
END nosymbols;
/
PLS_INTEGER;
'Trillion ' ,
'Quadrillion ' ,
'Quintillion ' ,
'Sextillion ' ,
'Septillion ' ,
'Octillion ' ,
'Nonillion ' ,
'Decillion ' ,
'Undecillion ' ,
'Duodecillion ');
--- Function
function D3_To_Wordar (P1_number in number)
return varchar2 as
-- Pass only three digits
-- This function return word equivalent to its number
-- Accepted values are 0 to 999
-L1_Return2 varchar2(500) := NULL ;
-n1 Number := 0 ;
i1 Number := 0 ;
j1 Number := 0 ;
k1 Number := 0 ;
V1_inp_Number Number := 0 ;
V1_temp Varchar2(50) := NULL;
--type OneArray is table of varchar2(50);
type TenArray is table of varchar2(50);
type hanArray is table of varchar2(50);
-OneStr OneArray := OneArray('', ' ', '', '',
'', '', '', '', '', '', '', '', '
', ' ', ' ', ' ', ' ', ' ', '
');
TenStr TenArray := TenArray('', '', '', '' , '',
'', '','', '');
hanStr hanArray := hanArray('', '', '' , '',
'', '','', '','');
-BEGIN
-V1_inp_Number := P1_Number ;
if V1_inp_number > 999 then
V1_inp_number := 0 ;
end if ;
-V1_temp := LPAD(to_char(V1_inp_number),3,0) ;
---- Find Hundredth position
n1 := to_number(substr(V1_temp,1,1));
-if n1 > 0 then L1_Return2 := hanStr(n1) ;
end if ;
---i1 := to_number(substr(V1_temp,2,2));
j1 := to_number(substr(V1_temp,2,1));
k1 := to_number(substr(V1_temp,3,1));
-if n1>0 AND (j1>0 OR k1>0) then L1_Return2 := L1_Return2 ||' ';
End if;
-if i1 > 0 and i1 < 20 then L1_Return2 :=L1_Return2 || OneStr(i1) ;
END IF;
---if j1 >= 2 then
if k1 > 0 then
L1_Return2 := L1_Return2|| OneStr(k1)|| ' ' ;
end if;
-L1_Return2 := L1_Return2 || TenStr(j1) ;
-end if;
if V1_inp_number=0 Then L1_Return2:='';
End If;
-Return L1_Return2 ;
--END D3_To_Wordar;
-- another function
-function Digits3_To_Word (P_number in number)
return varchar2 as
-- Pass only three digits
-- This function return word equivalent to its number
-- Accepted values are 0 to 999
-L_Return2 varchar2(500) := NULL ;
-i Number := 0 ;
j Number := 0 ;
k Number := 0 ;
-V_inp_Number Number := 0 ;
V_temp Varchar2(50) := NULL;
-type OneArray is table of varchar2(50);
type TenArray is table of varchar2(50);
OneStr OneArray := OneArray('One ',
'Two ',
'Three ',
'Four ',
'Five ',
'Six ',
'Seven ',
'Eight ',
'Nine ',
'Ten ',
'Eleven ',
'Twelve ',
'Thirteen ',
'Fourteen ',
'Fifteen ',
'Sixteen ',
'Seventeen ',
'Eighteen ',
'Nineteen ');
TenStr TenArray := TenArray('',
'Twenty ',
'Thirty ',
'Forty ' ,
'Fifty ',
'Sixty ',
'Seventy ',
'Eighty ',
'Ninety ');
-BEGIN
-V_inp_Number := P_Number ;
if V_inp_number > 999 then
V_inp_number := 0 ;
end if ;
-V_temp := LPAD(to_char(V_inp_number),3,0) ;
--- Find Hundredth position
i := to_number(substr(V_temp,1,1));
if i > 0 then
L_Return2 := OneStr(i)||'Hundred ' ;
end if ;
--- Find last 2 digits
i := to_number(substr(V_temp,2,2));
j := to_number(substr(V_temp,2,1));
k := to_number(substr(V_temp,3,1));
if i > 0 and i < 20 then
L_Return2 := L_Return2 || OneStr(i) ;
end if ;
if j >= 2 then
L_Return2 := L_Return2 || TenStr(j) ;
if k > 0 then
L_Return2 := L_Return2|| OneStr(k) ;
end if;
end if;
-Return L_Return2 ;
-END Digits3_To_Word;
---Begin
-IF v_lan ='AR' Then
V_inp_Num := ABS(P_inp_Num) ;
V_inp_Int := Trunc(V_inp_Num) ;
V_inp_Dec := V_inp_Num - V_inp_Int ;
--- To abort to 100
if V_inp_Dec > 0 then
V_inp_dec := V_inp_dec * 100 ;
V_inp_Dec := to_number(substr(to_char(V_inp_Dec),1,2)) ;
end if ;
--V_char := to_char(V_inp_Int) ;
-for m in 1..In_Str.Count Loop Exit when V_char is NULL ;
-V_Temp := To_Number(Substr(V_char,(Length(V_char)-2), 3));
-if V_temp > 0 then
L_Return := D3_To_WordAR(V_Temp) || In_str(m)||' ' || L_Return ;
end if ;
-V_char := Substr(V_char,1,(Length(V_Char)-3));
-End Loop ;
-L_return :=Substr(L_return,1,(Length(L_return)-1));
-IF P_inp_num>=1000 and P_inp_num<2000 Then
L_return:=Substr(L_return,5,Length(L_return));
End if ;
-IF P_inp_num>=2000 and P_inp_num<3000 Then
L_return:=''||Substr(L_return,11,Length(L_return));
End if ;
-IF P_inp_num>=3000 and P_inp_num<=10000 Then
-L_return:=Substr(L_return,1,(INSTR(L_return,'')-1)) || '' ||
Substr(L_return,(INSTR(L_return,'')+3),Length(L_return));
-End if ;
-if v_det=1 then
if V_inp_Dec > 0 then
L_return := L_return ||v_ce||' ' || to_char(V_inp_Dec)||v_de;
ELSE L_return := L_return ||' '||v_ce;
end if;
Else
if V_inp_Dec > 0 then
L_return := L_return ||v_ce||' ' ||D3_To_WordAR(V_inp_Dec)||'
'||v_de;
ELSE L_return := L_return ||' '||v_ce;
end if;
End if;
-if V_inp_Int > 0 then
L_Return := L_Return;
elsif V_inp_Int = 0 then
L_return := '===' ;
end if ;
Return L_return;
-ELSE
if P_inp_num < 0 then
eV_inp_Num := (P_inp_Num * -1) ;
else
eV_inp_Num := P_inp_Num;
end if;
eV_inp_Int := Trunc(eV_inp_Num) ;
eV_inp_Dec := eV_inp_Num - eV_inp_Int ;
if eV_inp_Dec > 0 then
eV_inp_dec := eV_inp_dec * 100 ;
eV_inp_Dec := to_number(substr(to_char(eV_inp_Dec),1,2)) ;
end if ;
-eV_char := to_char(eV_inp_Int) ;
-for em in 1..eIn_Str.Count Loop
exit when eV_char is NULL ;
eV_Temp := To_Number(Substr(eV_char,(Length(eV_char)-2), 3));
-if eV_temp > 0 then
eL_Return := Digits3_To_Word(eV_Temp) || eIn_str(em) || eL_Return ;
end if ;
-eV_char := Substr(V_char,1,(Length(eV_Char)-3));
-End Loop ;
-if eV_inp_Int > 0 then
eL_Return := v_ce||' '||eL_Return ||' and ';
elsif eV_inp_Int = 0 then
eL_return := v_ce||' Zero and ' ;
end if ;
--- Concatenate the word for decimal digits
if v_det=1 then
if eV_inp_Dec > 0 then
eL_return := eL_return || Digits3_To_Word(eV_inp_Dec) ||' '||v_de;
elsif eV_inp_Dec = 0 then
eL_Return := eL_return ||' Zero '||v_de;
End if ;
ELSE
if eV_inp_Dec > 0 then
eL_return := eL_return || to_char(eV_inp_Dec) ||' '||v_de;
elsif eV_inp_Dec = 0 then
eL_Return := eL_return ||' Zero '||v_de;
End if ;
END if;
Return eL_return;
End IF;
END ;
/
--------------------------------------------------------------------------------------------declare
v_empno employees.employee_id%type := 100;
begin
merge into copy_emp c
using employees e
on (e.employee-id = v_emono)
when matched then
update set
c.first_name = e.first_name,
c.last_name = e.last_name,
c.email
= e.email,
....
when not matched then
insert values(e.employee_id,e.first_name,e.last_name...);
end;
---------------------------------------------------------------------------begin
delete from emp;
dbms_output.put_line('count of rows deleted ='||sql%rowcount);
end;
/
---------------------------------------------------------------------------sql%rowcount
sql%found
sql%notfound
sql%isopen
---------------------------------------------------------------------------CASE (LIKE IF)
---------------SET SERVEROUTPUT ON
DECLARE
V_GRADE char(1) := upper('&p_grade');
v_appraisal
varchar2(20);
begin
v_appraisal :=
case v_grade
when 'A' then 'Excellent'
when 'B' then 'very Good'
when 'C' then 'Good'
Else 'No such grade'
end;
dbms_output.put_line('Grade: '||v_grade||' Appraisal '||v_appraisal');
end;
/
-------------------------------------------------------reverse loop
-------------begin
for i in reverse 1..100 loop
dbms_output.put_line(i);
end loop;
end;
/
-------------------------------------------------------idea
--------set serveroutput on
begin
for i in (select * from emp) loop
dbms_output.put_line(i.ename||' with salary of'||i.sal);
end loop;
end;
/
-------------------------------------------------------index by tables
--------------EX 1:
---declare
type dept_table_type is table of
dept%rowtype
index by binary_integer;
dept_table dept_table_type;
x number;
c number;
begin
x:=10;
select count(*) into c from dept;
for i in 1..c loop
select * into dept_table(i) from dept where deptno = x;
x := x+10;
end loop;
x := 1;
for m in dept_table.first..dept_table.last loop
dbms_output.put_line(dept_table(m).dname||'
'||dept_table(m).loc);
end loop;
exception
when no_data_found then
dbms_output.put_line(dept_table.count);
end;
/
--------------------------------Ex 2:
----declare
type numlist is table of number;
mgrs numlist := numlist(100,101,102,103,..); -- managers numbers
begin
forall i in mgrs.first..mgrs.last loop
delete from employees where manager_id = mgrs(i);
end loop;
end;
loop
if emp_record.sal<5000 then
update emp
set sal= emp_record.sal * 1.1
where currenct of sal_cursor;
end if;
end loop;
end;
/
note: you have to include the for update clause in the curosr in order
to be able to use
where current of clause.
------------------------------------------------------Exception handling
---------------------trap for oracle server error number -2292,an
integrity constraint biolation.
------------------------------------------define p_deptno = 10
declare
e_emps_remaining exception;
pragma exception_init
(e_emps_remaining,-2292);
begin
delete from dept where deptno = &p_deptno;
commit;
exception
when e_emps_remaining then
dbms_output.put_line('cannot remove dept '||
to_char(&p_deptno)||'. Employees exist. ');
end;
-------------------------------------------------------------------SQLCODE
SQLERRM
----------------------------------------------user-defined exceptions
----------------------define p_dnm = 'Information Technology'
define p_dept_no = 300
declare
e-invalid_dept exception;
begin
update dept
set dname = '&p_dnm'
where deptno = &p_dept_no;
if SQL%NOTFOUND THEN
RAISE e_invalid_dept;
end if;
commit;
exception
when e_invalid_dept then
dbms_output.put_line('No such deptno.');
end;
--------------------------------------------------raise_application_error:-------------------------use within the stored program units either in:
- the executable section or
- the exception section
Executable section:
------------------begin
.....
delete from emp where mgr = 9000;
if sql%notfound then
raise_application_error(-20202,
'This is not a valid manager');
end if;
.......
----------------------exception section
----------------.....
exception
when no_data_found then
raise_application_error(-20201,
'Manager is not a valid employee.');
end;
------------------------------------------------------------------create or replace procedure format_phone
(p_phone_no in out varchar2)
is
begin
p_phone_no :='('||substr(p_phone_no,1,3||
')'||substr(p_phone_no,4,3)||
'-'||'('||substr(p_phone_no,7);
end format_phone;
/
----------------------------------------------------------------------------HOW TO PASS PARAMETERS TO PROCEDURES WHICH HAS DEFAULT VALUES:
--------------------------------------------------procedure add_dept
(p_nm in varchar2 default 'unknown',
p_loc in number default 'cairo')
is
begin
insert into dept values(dept_seq.next_val,p_nm,p_loc);
end;
/
examles of how to pass parameters to this procedure:
----------------------------------------------------------------------begin
add_dept;
add_dept('training','Giza');
end loop;
end read_emp_table;
end emp_package;
/
--------------------------------------------------------------------------------------------how to use the preceding package:
_------------------------------------------declare
v_emp_table
emp_package.emp_table_type;
begin
emp_package.read_emp_table (v_emp_table);
dbms_output.put_line('an example'||v_emp_table(4).last_name);
end;
/
------------------------------------------------------------------------------------------------DYNAMIC SQL
-----------------------forms_ddl('create or replace function get_data return varchar2 is'||
' rslt varchar2(100); begin select '||:tt||' into rslt from dept where
deptno=10; RETURN RSLT; end;');
:tt := get_data;
-------------------------------------------------------------------------------------------------------------------------dynamic insert statement
-------------------------------------select 'insert into dept values('
||deptno||','''||dname||''','''||loc||''');' from dept;
'INSERTINTODEPTVALUES('||DEPTNO||','||DNAME||','||LOC||');'
----------------------------------------------------------------------------------------insert into dept values(10,ACCOUNTING,NEW YORK);
insert into dept values(20,RESEARCH,DALLAS);
insert into dept values(30,SALES,CHICAGO);
insert into dept values(40,OPERATIONS,BOSTON);
-----------------------------------------------------scripts for hr
---------------------C:\oracle\ora92\demo\schema\human_resources
-------------------------------------------------------------------------------------------------------------------------------------------tab pages
--------------when-tab-page-changed (form level)
----------------------------------begin
if :system.tab_new_page = 'ADDRESS' then
go_item('s_customer.name');
else
if :system.tab_new_page = 'BILLING' then
go_item('s_customer.credit_rating');
else
go_item('s_customer.comments');
end if;
end if;
end;
------------------------------------------------------------------------------when-new-record-instance (block level)
-------------------------------------Declare
tb_pg_id TAB_PAGE;
Begin
tb_pg_id := FIND_TAB_PAGE('COMMENTS');
if :s_customer.comments is null then
SET_TAB_PAGE_PROPERTY(tb_pg_id, enabled, propert
y_false);
else
SET_TAB_PAGE_PROPERTY(tb_pg_id, enabled, property_true);
End If;
:global.custid := :s_customer.id;
End;
---------------------------------------------------------------------------------when-checkbox-changed
=======================
IF NVL(:CONTROL.case_sensitive, 'Y') = 'Y' THEN
SET_ITEM_PROPERTY('S_CUSTOMER.name', CASE_INSENSITIVE_QUERY,
PROPERTY_FALSE);
ELSE
SET_ITEM_PROPERTY('S_CUSTOMER.name',CASE_INSENSITIVE_QUERY,
PROPERTY_TRUE);
END IF;
================================================================================
=====
dynamic sorting
==============
1 - create on top of every column item a button as a label of the
column but with the same name of the column ending
by ( _btn)
2 - when-button-pressed (block level of the buttons) type the following
code:
set_block_property('emp',order_by,substr(:system.cursor_item,1,instr(:system.cur
sor_item,'_',1)-1) );
go_block('emp');
execute_query;
================================================================================
=====
hide and show tab pages
=====================
DECLARE
tb_pg_id TAB_PAGE;
BEGIN
tb_pg_id := FIND_TAB_PAGE('P2');
IF GET_TAB_PAGE_PROPERTY(tb_pg_id, visible) = 'FALSE' THEN
SET_TAB_PAGE_PROPERTY(tb_pg_id, visible, property_true);
set_item_property('btn',label,'Hide');
else
SET_TAB_PAGE_PROPERTY(tb_pg_id, visible, property_false);
set_item_property('btn',label,'Show');
END IF;
END;
================================================================================
====
synchronize
=============
go_block('emp');
execute_query;
first_record;
loop
:tt := 'currently processing Employee -who works as "'||:job||'"';
for i in 1..20000 loop
synchronize;
end loop;
exit when :System.Last_Record = 'TRUE';
next_record;
end loop;
first_record;
================================================================================
====
size window in motion
=================
IF GET_ITEM_PROPERTY('BTN',LABEL) = 'VIEW' THEN
for i in 1..125 loop
SET_ITEM_PROPERTY('BTN',LABEL,'HIDE');
for i in 1 .. 200 loop
null; synchronize;
end loop;
SET_WINDOW_PROPERTY('WINDOW1',HEIGHT,get_window_property('WINDOW1',HEIGHT)+1);
end loop;
ELSE
SET_ITEM_PROPERTY('BTN',LABEL,'VIEW');
SET_WINDOW_PROPERTY('WINDOW1',HEIGHT,175);
END IF;
================================================================================
=====
extracting the date of a tabular datablock to a text file:
===========================================
1 - create a procedure in the program unit like that :
=======================================
PROCEDURE CREATE_FLAT_FILE(Save_To VARCHAR2) IS
in_file TEXT_IO.FILE_TYPE;
text_line VARCHAR2(400);
AppID PLS_INTEGER;
BEGIN
in_file := TEXT_IO.FOPEN(Save_To, 'W');
GO_BLOCK('dept');
FIRST_RECORD;
LOOP
text_line := :deptno||';'||:dname||';'||:loc;
TEXT_IO.PUT_LINE(in_file, text_line);
exit when :SYSTEM.LAST_RECORD = 'TRUE';
NEXT_RECORD;
END LOOP;
TEXT_IO.FCLOSE(in_file);
AppID := DDE.App_Begin('"C:\Program Files\Microsoft
Office\Office\EXCEL.EXE" '||Save_To,
DDE.APP_MODE_Maximized);
EXCEPTION
WHEN NO_DATA_FOUND THEN
TEXT_IO.FCLOSE(in_file);
END;
---------------------------------------2 - create a button with a when button pressed trigger :
========================================
declare
fle varchar2(200);
begin
fle:= get_file_name('D:\'/*default directory*/,'hm.csv'/*default file
name*/,file_filter =>'Excel Files (*.csv)/*.csv',dialog_type =>
SAVE_FILE);
CREATE_FLAT_FILE(fle);
end;
================================================================================
====
moving and copying system files :
---------------------------------------------1- we need to attach the d2kwutil.pll to the form
2 - a button with this trigger:
Win_Api_Utility.Move_File
('c:\test.doc'/*the file which is needed to
be moved*/,'d:\hamdy.doc' /*this is the new file name and location*/);
================================================================================
=====
to cancel a report if the ouput is null
-------------------------------------------------befor report trigger:
==================
Function BEF_REP_TRG return boolean is
count_inv number;
begin
select count(*) into count_inv from EMP
where DEPTNO= :P_DEPTNO ;
if count_inv = 0 then
srw.message (0, 'No DATA found for printing');
--return false;
/* or use SRW.PRORAM_ABORT;
RAise srw.program_abort;
*/
end if;
return true;
End;
================================================================================
=====
to dynamically show only the number of records specified in a group
filter:
--------------in the data model:
-----------------select the group then F11
and put the following code:
function G_CUSTOMER_IDGroupFilter return boolean is
begin
:P_COUNT_CUST/* a parameter */ := nvl(:P_COUNT_CUST,0) + 1;
IF :P_COUNT_CUST <= :P_CUTOFF /*this the parameter that's showed for
the user so he can enter the number of records he needs to desplay*/
THEN
return (TRUE);
ELSE return(FALSE);
END IF;
end;
----------------------------------------------------------------------------------------------to run a drill - down report :
--------------------------------in the master report create a button and set its type to pl/sql then
put the following code :
-------------------------------------------------------------procedure U_1ButtonAction is
begin
srw.run_report
('report=s18q2c.rep
p_customer=' ||to_char(:customer_id)|| ' paramform=no');
-- The paramform argument is optional, default=no, but it
-- shows how to enter multiple arguments in this command
end;
-- srw.run_report
-- ('report=p2q8_det.rep p_custid=' ||to_char(:id)|| ' paramform=no');
Export a report to excel from within the report run time itself
---------------------------------------------------------------procedure U_1ButtonAction is
begin
srw.run_report(
'report=GLR931 BAL_EXP=' ||:BAL_EXP||
select
sys.user_tab_columns.table_name,
sys.user_tab_columns.column_name,
sys.user_tab_columns.data_type,
sys.user_tab_columns.data_length,
sys.user_tab_columns.data_precision,
sys.user_tab_columns.data_scale/*,
sys.user_tab_columns.table_type*/
from sys.user_tab_columns,sys.user_catalog
where(sys.user_tab_columns.table_name=sys.user_catalog.table_name)
and sys.user_tab_columns.table_name like upper('%&tab%')
order by sys.user_tab_columns.table_name
/
---------------------------------------------------------------------------------To import specific tables from a dmp file:
----------------------------------imp userid=xyz/xyz file=c:\scott.dmp fromuser=scott
tables=('emp','dept')
To import all tables from a dmp file:
----------------------------------imp userid=xyz/xyz file=c:\scott.dmp fromuser=scott tables=*
---------------------------------------------------------------------------------Dynamic List-Item
---------------------1 - create a group named rg with the following query:
select dname,to_char(deptno) from dept
2 - create a list item called lst
3 - create a form level trigger (when-new-form-instance) with the
following code :
declare
pg number;
begin
pg := populate_group('rg'); /*returns 0 if executed succefully */
populate_list('lst','rg');
end;
----------------------------------------------------------------------------------------------openning a report from within a form or a menu:
------------------------------------------------declare
pl_id
begin
ParamList;
pl_id := Get_Parameter_List('emps');
IF NOT Id_Null(pl_id) THEN
Destroy_Parameter_List( pl_id );
end if;
pl_ID := Create_Parameter_List('emps');
Add_Parameter(pl_id,'Paramform',Text_PARAMETER,'NO');
Add_Parameter(pl_id,'MAXIMIZE',Text_PARAMETER,'Yes');
Run_Product(REPORTS, 'port_cash_available', SYNCHRONOUS,
RunTime,FILESYSTEM, pl_id, NULL);
end;
--------------------------------------------------------------------------------------------dynamically select the first n rows from a query:
---------------------------------------------------1 - create a parameter called mx
2 - before report trigger
function BeforeReport return boolean is
begin
srw.set_maxrow('Q_1'/*query name from the data model*/,:mx);
return (TRUE);
end;
--------------------------------------------------------------------------------------------dynamic order by
--------------------------------create a listitem with all the names of the table names then
type the following trigger:
when-list-changed
----------------------set_block_property('EMP', ORDER_BY, :control.sort_by);
go_block('EMP');
execute_query;
----------------------------------------------------------------------------dynamic backup
------------* - create a form with a button.
* - create a WHEN-BUTTON-PRESSED trigger with the following code:
host('exp userid=system/manager file=c:\backup.dmp full=yes
log=c:\backup.txt');
----------------------------------------------------------------------------to create an O'clock on your form :
-----------------------------1 - when-new-form-instance
-------------------DECLARE
timer_id Timer;
one_minute NUMBER(5) := 1000;
BEGIN
timer_id := CREATE_TIMER('HM', one_minute,REPEAT);
END;
2 - when-timer-expired
------------------DECLARE
time VARCHAR2(20);
BEGIN
else
SET_TAB_PAGE_PROPERTY(tb_pg_id, enabled, property_true);
End If;
:global.custid := :s_customer.id;
End;
----------------------------------------------------------------------------dynamic sorting
==============
1 - create on top of every column item a button as a label of the
column but with the same name of the column ending
by ( _btn)
2 - when-button-pressed (block level of the buttons) type the following
code:
set_block_property('emp',order_by,substr(:system.cursor_item,1,instr(:system.cur
sor_item,'_',1)-1) );
go_block('emp');
execute_query;
----------------------------------------------------------------------------PACKAGE emp_proc
AS
TYPE emp_t IS RECORD(
NAME emp.ename%TYPE,
ID emp.empno%TYPE);
-- For SELECT
TYPE rec_t IS TABLE OF emp_t
INDEX BY BINARY_INTEGER ;
PROCEDURE emp_rec(
p_table IN OUT rec_t);
END;
------------------------------PACKAGE BODY emp_proc
AS
PROCEDURE emp_rec(
p_table IN OUT rec_t)
IS
v_ct NUMBER := 1;
BEGIN
FOR emp_r IN (SELECT * FROM EMP)
LOOP
p_table(v_ct).name := emp_r.ename;
p_table(v_ct).id := emp_r.empno;
v_ct := v_ct + 1;
END LOOP;
END;
END;
---------------------------------------------------------------------------------------------
PLS_INTEGER;
-----------------------------------------------------------------------------------drilldown report
-------------1- Create two reports DEPTS and EMPS - in the EMPS report create a
parameter named P_DEPTNO in the where clause of the report query (in the
Data Model)
2- in the layout create a button
3- in the property pallete of that button set the (TYPE) property to be
PL/SQL
4- in the property pallete of that button set the (PL/SQL TRIGGER) TO
THE FOLLOWING:
function U_1ButtonAction return boolean is
begin
srw.run_report('report=c:\emps_rep '||
' P_DEPTNO='||:DEPT_ID );
return true;
EXCEPTION
when srw.run_report_failure then
srw.message(30, 'Error mailing reports.');
raise srw.program_abort;
end;
-----------------------------------------------------------------------------------declare
v_empno employees.employee_id%type := 100;
begin
merge into copy_emp c
using employees e
on (e.employee-id = v_emono)
when matched then
update set
c.first_name = e.first_name,
c.last_name = e.last_name,
c.email
= e.email,
....
when not matched then
insert values(e.employee_id,e.first_name,e.last_name...);
end;
---------------------------------------------------------------------------begin
delete from emp;
dbms_output.put_line('count of rows deleted ='||sql%rowcount);
----------end;
/
---------------------------------------------------------------------------sql%rowcount
sql%found
sql%notfound
sql%isopen
---------------------------------------------------------------------------CASE (LIKE IF)
---------------SET SERVEROUTPUT ON
DECLARE
V_GRADE char(1) := upper('&p_grade');
v_appraisal
varchar2(20);
begin
v_appraisal :=
case v_grade
when 'A' then 'Excellent'
when 'B' then 'very Good'
when 'C' then 'Good'
Else 'No such grade'
end;
dbms_output.put_line('Grade: '||v_grade||' Appraisal '||v_appraisal');
end;
/
-------------------------------------------------------reverse loop
-------------begin
for i in reverse 1..100 loop
dbms_output.put_line(i);
end loop;
end;
/
-------------------------------------------------------idea
--------set serveroutput on
begin
for i in (select * from emp) loop
-----------------------------------------------------------------------------------current of in a cursor
----------------------declare
cursor sal_cursor is
select e.deptno,empno,ename,sal
from emp e,dept d
where d.deptno=e.deptno
and d.deptno=30
for update of sal nowait;
begin
for emp_record in sal_cursor
loop
if emp_record.sal<5000 then
update emp
set sal= emp_record.sal * 1.1
where currenct of sal_cursor;
end if;
end loop;
end;
/
note: you have to include the for update clause in the curosr in order
to be able to use
where current of clause.
------------------------------------------------------Exception handling
---------------------trap for oracle server error number -2292,an
integrity constraint biolation.
------------------------------------------define p_deptno = 10
declare
e_emps_remaining exception;
pragma exception_init
(e_emps_remaining,-2292);
begin
delete from dept where deptno = &p_deptno;
commit;
exception
when e_emps_remaining then
dbms_output.put_line('cannot remove dept '||
to_char(&p_deptno)||'. Employees exist. ');
end;
-------------------------------------------------------------------SQLCODE
SQLERRM
----------------------------------------------user-defined exceptions
----------------------define p_dnm = 'Information Technology'
define p_dept_no = 300
declare
e-invalid_dept exception;
begin
update dept
set dname = '&p_dnm'
where deptno = &p_dept_no;
if SQL%NOTFOUND THEN
RAISE e_invalid_dept;
end if;
commit;
exception
when e_invalid_dept then
dbms_output.put_line('No such deptno.');
end;
--------------------------------------------------raise_application_error:-------------------------use within the stored program units either in:
- the executable section or
- the exception section
Executable section:
------------------begin
.....
delete from emp where mgr = 9000;
if sql%notfound then
raise_application_error(-20202,
'This is not a valid manager');
end if;
.......
----------------------exception section
----------------.....
exception
when no_data_found then
raise_application_error(-20201,
'Manager is not a valid employee.');
end;
-------------------------------------------------------------------
/
----------------------------------------------------------------------------HOW TO PASS PARAMETERS TO PROCEDURES WHICH HAS DEFAULT VALUES:
--------------------------------------------------procedure add_dept
(p_nm in varchar2 default 'unknown',
p_loc in number default 'cairo')
is
begin
insert into dept values(dept_seq.next_val,p_nm,p_loc);
end;
/
examles of how to pass parameters to this procedure:
----------------------------------------------------------------------begin
add_dept;
add_dept('training','Giza');
add_dept(p_loc => 'Giza',p_nm =>'Education');
add_dept(p_loc =>'Alex');
end;
/
--------------------------------------------------------------------------Extract the source code from the database:
--------------------------------------------------------VARIABLE SRC VARCHAR2(2000);
BEGIN
FOR I IN (SELECT TEXT FROM USER_SOURCE WHERE NAME ='GET_HOLIDAYS'
ORDER BY LINE)
LOOP
IF :SRC IS NULL THEN
:SRC := I.TEXT;
ELSE
:SRC :=:SRC||CHR(13)||I.TEXT;
END IF;
END LOOP;
END;
/
----------------------------------------------------------------------------------------------------------declaring a bodiless package
---------------------------------------create or replace package global_consts is
mile_2_kilo
constant number := 1.6093;
kilo_2_mile
constant number := 0.6214;
yard_2_meter
constant number := 0.9144;
meter_2_yard
constant number := 1.0936;
mile_2_kilo
constant number := 1.6093;
end global_consts;
/
to try the package:
-------------------------execute dbs_output.put_line('20 miles = '||20*
global.consts.mile_2_kilo||' km');
------------------------------------------------------------------------------------
scripts for hr
---------------------C:\oracle\ora92\demo\schema\human_resources
-------------------------------------------------------------------------------------------------------------------------------------------Using DBMS_SQL
----------------------------create or replace procedure delete_all_rows
(p_tab_name in varchar2,p_rows_del out number)
is
cursor_name integer;
begin
cursor_name := dbms_sql.open_cursor;
dbms_sql.parse(cursor_name,'delete from 'p_tab_name,dbms_sql.native);
p_rows_del := dbms_sql.execute(cursor_name);
dbms_sql.close_cursor(cursor_name);
end;
/
using the preceding procedure:
---------------------------------------variable deleted number
execute delete_all-rows('emp',:deleted)
print deleted
deleted
14
----------------------------------------------------------------------------------Dynamic sql using execute immediate
----------------------------------------------------create procedure del_rows
(p_table_name in
varchar2,
p_rows_del
out number)
is
begin
execute immediate 'delete from '||p_table_name;
p_rows_del :=sql%rowcount;
end;
/
variable deleted number
execute del_rows('emp',:deleted);
print deleted
deleted
14
--------------------------------------------------------------how to add jobs
---------------------variable x number;
begin
dbms_job.submit(job >= :x,
what >='delete from mx where empno=(select max(empno) from mx);',
next_date >= trunc(sysdate + 1),
interval >= 'trunc(sysdate+1)'
);
commit;
end;
/
----------------variable x number;
begin
dbms_job.submit(
job >= :x, -- this is to hold the job number in the job queue
what >='over_pack.add_dept(''education'',80);',
next_date >= trunc(sysdate + 1),
interval >= 'trunc(sysdate+1)' -- to work every midnight
);
end;
/
print x
x
1
----------------------------------------the following code changes job number 1 to execute on the following day
at 6:00 a.m. and every four hours after that.
begin
dbms_job.change(1,null
/*what*/,trunc(sysdate+1)+6/24,'sysdate+4/24');
end;
/
note : if the parameter what,next_date,or interval is null then the
last values assigned to those parameters are used.
------------------------------------------------------------------------------------execute dbms_job.run(1) ;
-- to run the job number 1 in the queue
immediatly
execute dbms_job.remove(1); -- to remove a job from the queue
execute dbms_job.break(1,true); -- to stop temprarly this job to let
working again set the second parameter to false
--------------------------------------------------------------------------------------------viewing information on submitted jobs
----------------------------------------------------select job,log_user,next_date,next_sec,brocken,what from dba_jobs;
job
log_user
next_date
next_sec
broken what
1
plsql 28-sep-2003
06:00:00
N
over_pack.add_dept('educ
ation',80);
* use the dba_jobs_running dictionary view to display jobs that are
currently running.
--------------------------------------------------------------------------------------------procedure and functions
--------------------------SELECT ALL USER_SOURCE.NAME, USER_SOURCE.TYPE, USER_SOURCE.LINE,
USER_SOURCE.TEXT
FROM USER_SOURCE
WHERE USER_SOURCE.NAME = :P_Name
----------------------------------dependencies
----------------SELECT ALL USER_DEPENDENCIES.NAME, USER_DEPENDENCIES.TYPE,
USER_DEPENDENCIES.REFERENCED_OWNER, USER_DEPENDENCIES.REFERENCED_NAME,
USER_DEPENDENCIES.REFERENCED_TYPE,
USER_DEPENDENCIES.REFERENCED_LINK_NAME,
USER_DEPENDENCIES.SCHEMAID, USER_DEPENDENCIES.DEPENDENCY_TYPE
FROM USER_DEPENDENCIES
Where Name = :P_Name
ORDER BY REFERENCED_TYPE, USER_DEPENDENCIES.NAME ASC
-------------------------------------Triggers
-------------------------SELECT ALL USER_TRIGGERS.TRIGGER_NAME, USER_TRIGGERS.TRIGGER_BODY ,
USER_TRIGGERS.DESCRIPTION,
Decode(WHEN_CLAUSE,null,'','When '|| USER_TRIGGERS.WHEN_CLAUSE
)WHEN_CLAUSE
FROM USER_TRIGGERS
Where TRIGGER_NAME = :P_Name
---------------------------------views
-------------SELECT TEXT FROM USER_VIEWS
WHERE VIEW_NAME = :P_NAME
------------------------------------Excel:
-----------Sub Update_Data()
' Create and initialize the necessary objects
Dim OraSession As Object
Dim OraDatabase As Object
Dim EmpDynaset As Object
Dim ColNames As Object
Set OraSession = CreateObject("OracleInProcServer.XOraSession")
Set OraDatabase = OraSession.OpenDatabase("2:", "scott/tiger", 0&)
Set EmpDynaset = OraDatabase.DbCreateDynaset("select * from emp", 0&)
Set ColNames = EmpDynaset.Fields
i = 2
' the BeginTrans and CommitTrans are optional
OraSession.BeginTrans
While Worksheets("DataSheet").Cells(i, 1).Value <> ""
EmpDynaset.dbedit
For j = 1 To ColNames.Count
----------------------------------------------------excel2
-------Sub Get_Data()
' Create and initialize the necessary objects
Dim OraSession As Object
Dim OraDatabase As Object
Dim EmpDynaset As Object
Dim ColNames As Object
Set OraSession = CreateObject("OracleInProcServer.XOraSession")
Set OraDatabase = OraSession.OpenDatabase("2:", "scott/tiger", 0&)
Set EmpDynaset = OraDatabase.DbCreateDynaset("select * from emp", 0&)
' Using field array, ie. ColNames("ename").value, is significantly
faster than using
' field lookup, ie. EmpDynaset.fields("ename").value
Set ColNames = EmpDynaset.Fields
' Place column headings on sheet
For icols = 1 To ColNames.Count
Worksheets("DataSheet").Cells(1, icols).Value = ColNames(icols 1).Name
Next
' Place data on sheet using CopyToClipboard
EmpDynaset.CopyToClipboard -1
Sheets("DataSheet").Select
Range("A2").Select
ActiveSheet.Paste
End Sub
-----------------------------------------excel array
-------------Sub Get_Array()
Const ORAPARM_INPUT = 1
Const ORAPARM_OUTPUT = 2
Const ORATYPE_VARCHAR2 = 1
Const ORATYPE_NUMBER = 2
Dim
Dim
Dim
Dim
Dim
Dim
OraSession As Object
OraDatabase As Object
OraDynaset As Object
OraPLSQLStmt As Object
OraPArray1 As Object
OraPArray2 As Object
Dim
Dim
Set
Set
PLSQLStmt1 As String
PLSQLStmt2 As String
OraSession = CreateObject("OracleInProcServer.XOraSession")
OraDatabase = OraSession.OpenDatabase("2:", "scott/tiger", 0&)
PACKAGE emp_proc
AS
TYPE emp_t IS RECORD(
NAME emp.ename%TYPE,
ID emp.empno%TYPE);
-- For SELECT
TYPE rec_t IS TABLE OF emp_t
INDEX BY BINARY_INTEGER ;
PROCEDURE emp_rec(
p_table IN OUT rec_t);
END;
------------------------------PACKAGE BODY emp_proc
AS
PROCEDURE emp_rec(
p_table IN OUT rec_t)
IS
v_ct NUMBER := 1;
BEGIN
FOR emp_r IN (SELECT * FROM EMP)
LOOP
p_table(v_ct).name := emp_r.ename;
p_table(v_ct).id := emp_r.empno;
v_ct := v_ct + 1;
END LOOP;
END;
END;
--------------------------------------query-procedure trigger on the datablock scope
---------------------------------------------------- Automatically generated trigger for procedure data source.
-- Do not edit.
-- If this trigger fails to compile, verify the block procedure data
source is correct.
DECLARE
bk_data EMP_PROC.REC_T;
BEGIN
emp_proc.emp_rec(bk_data);
PLSQL_TABLE.POPULATE_BLOCK(bk_data, 'BLOCK2');
END;
-------------------------------------------------------
dynamic order by
--------------------------------create a listitem with all the names of the table names then
type the following trigger:
when-list-changed
----------------------set_block_property('EMP', ORDER_BY, :control.sort_by);
go_block('EMP');
execute_query;
--------------------------------------------------------------------------------------------TREE QUERY (in the data_query property of the tree item
-----------------------SELECT decode(level, 1, 1, -1),
level,
INITCAP(ename),
'tbrun',
empno
FROM emp
START WITH mgr IS NULL
CONNECT BY PRIOR empno = mgr
--WHEN-NEW-FORM-INSTANCE
---------------------ftree.populate_tree('CONTROL.EMP_TREE');
--WHEN-TREE-NODE-SELECTED
-------------------------go_block('EMP');
set_block_property('EMP', DEFAULT_WHERE, 'EMPNO='||
ftree.get_tree_node_property('CONTROL.EMP_TREE',
:SYSTEM.TRIGGER_NODE,
FTREE.NODE_VALUE));
execute_query;
---------------------------------------------------------------------------------------DYNAMIC TREE
--------------------PRE-FORM
--------ftree.populate_tree('CONTROL.EMP_TREE');
ftree.set_tree_property('CONTROL.EMP_TREE', FTREE.QUERY_TEXT,
'SELECT decode(level, 1, 1, -1), level, INITCAP(ename), ''tbrun'','
||
'empno FROM emp ' ||
'START WITH mgr IS NULL CONNECT BY PRIOR empno = mgr');
-----------------WHEN-TREE-NODE-SELECTED (BLOCK SCOPE
------------------------------------
go_block('EMP');
set_block_property('EMP', DEFAULT_WHERE, 'EMPNO='||
ftree.get_tree_node_property('CONTROL.EMP_TREE',
:SYSTEM.TRIGGER_NODE,
FTREE.NODE_VALUE));
execute_query;
----------------------------------------------------------------------------------------run report object
--------------------DECLARE
v_repid REPORT_OBJECT := find_report_object('dept_rep');
v_rep VARCHAR2(100);
BEGIN
IF :run_rep.destype = 'FILE'
THEN
set_report_object_property(v_repid, REPORT_DESFORMAT, 'PDF');
set_report_object_property(v_repid, REPORT_DESNAME,
'c:\dept_rep.pdf');
set_report_object_property(v_repid, REPORT_DESTYPE, FILE);
-ELSE
set_report_object_property(v_repid, REPORT_DESFORMAT,
TO_CHAR(NULL));
set_report_object_property(v_repid, REPORT_DESNAME,
TO_CHAR(NULL));
set_report_object_property(v_repid, REPORT_DESTYPE, PREVIEW);
END IF;
-v_rep := run_report_object(v_repid);
-IF :run_rep.destype = 'FILE'
THEN
message('File has been written to C:\DEPT_REP.PDF');
message(' ');
END IF;
END;
-- Other syntax that can be used if the Reports Server is running
-v_rep_status VARCHAR2(20);
-- v_rep_status := report_object_status(v_rep);
-- IF v_rep_status = 'FINISHED' THEN
-message('Report Completed');
-copy_report_object_output(v_rep, 'c:\dept_rep.pdf');
-- ELSE
-message('Error when running report. '||rep_status);
-- END IF;
---------------------------------------------------------------------------------what is the mouse button pressed and with what key (shift - ctrl)
---------------------------:control.shift_state := :system.mouse_button_shift_state;
:control.mouse_button := :system.mouse_button_pressed;
------------------------------------------------------------------------------------to run a report from forms
1 - in the object navigator of the forms builder create a new report
and specify an existing
report path and name then change the
properties of that report object
execution mode = runtime - communication mode = synchronous report distination type = preview
2 - create a button with the following code :
declare
v_rep varchar2(100);
v_rp_id report_object;
begin
v_rp_id := find_report_object('dept');--the name of the report
object not the report
v_rep := run_report_object(v_rp_id);
end;
---------------------------------------------------------------------------------------------to run a report against a remote server:
repid
:= find_report_object('barcode');
v_rep
:= run_report_object(repid);
rep_status := report_object_status(v_rep);
if rep_status = 'FINISHED' then
copy_report_object_output(v_rep,'c:\local.pdf');
host('netscape c:\local.pdf');
end if;
---------------------------------------------------------------------------------------------to run a report on the web:
web.show_document('url','target');
ex:
web.show_docment('http://www.summit.com/repts/emps.pdf','_self');
---------------------------------------------------------------------------------------------set_alert_property('myalert',mesage,'Are u sure u want to delete?');
if show_alert('myalert') = alert_button1 then
delete_record;
end if;
----------------------------------------------------------------------------------------------if the form has many windows but we want it to be closed only from the
win_order window :when-window-closed
if :system.event_window='WIN_ORDER' THEN
DO_KEY('EXIT_FORM');
ELSE
GO_BLOCK('S_ORDER');
END IF;
----------------------------------------------------------------------------------------------TO KNOW ALL THE NLS_PARAMETERS
-----------------------------------SELECT * FROM NLS_SESSION_PARAMETERS
----------------------------------------------------------------------------------------------declare
v_empno employees.employee_id%type := 100;
begin
merge into copy_emp c
using employees e
on (e.employee-id = v_emono)
when matched then
update set
c.first_name = e.first_name,
c.last_name = e.last_name,
c.email
= e.email,
....
when not matched then
insert values(e.employee_id,e.first_name,e.last_name...);
end;
---------------------------------------------------------------------------begin
delete from emp;
dbms_output.put_line('count of rows deleted ='||sql%rowcount);
end;
/
---------------------------------------------------------------------------sql%rowcount
sql%found
sql%notfound
sql%isopen
---------------------------------------------------------------------------CASE (LIKE IF)
---------------SET SERVEROUTPUT ON
DECLARE
V_GRADE char(1) := upper('&p_grade');
v_appraisal
varchar2(20);
begin
v_appraisal :=
case v_grade
when 'A' then 'Excellent'
when 'B' then 'very Good'
when 'C' then 'Good'
Else 'No such grade'
end;
dbms_output.put_line('Grade: '||v_grade||' Appraisal '||v_appraisal');
end;
/
-------------------------------------------------------reverse loop
-------------begin
for i in reverse 1..100 loop
dbms_output.put_line(i);
end loop;
end;
/
-------------------------------------------------------idea
--------set serveroutput on
begin
for i in (select * from emp) loop
dbms_output.put_line(i.ename||' with salary of'||i.sal);
end loop;
end;
/
-------------------------------------------------------index by tables
--------------EX 1:
---declare
type dept_table_type is table of
dept%rowtype
index by binary_integer;
dept_table dept_table_type;
x number;
c number;
begin
x:=10;
select count(*) into c from dept;
for i in 1..c loop
select * into dept_table(i) from dept where deptno = x;
x := x+10;
end loop;
x := 1;
for m in dept_table.first..dept_table.last loop
dbms_output.put_line(dept_table(m).dname||'
'||dept_table(m).loc);
end loop;
exception
when no_data_found then
dbms_output.put_line(dept_table.count);
end;
/
--------------------------------Ex 2:
----declare
type numlist is table of number;
mgrs numlist := numlist(100,101,102,103,..); -- managers numbers
begin
-------------------------------------------------------------------
:global.custid := :s_customer.id;
End;
---------------------------------------------------------------------------------when-checkbox-changed
=======================
IF NVL(:CONTROL.case_sensitive, 'Y') = 'Y' THEN
SET_ITEM_PROPERTY('S_CUSTOMER.name', CASE_INSENSITIVE_QUERY,
PROPERTY_FALSE);
ELSE
SET_ITEM_PROPERTY('S_CUSTOMER.name',CASE_INSENSITIVE_QUERY,
PROPERTY_TRUE);
END IF;
================================================================================
=====
dynamic sorting
==============
1 - create on top of every column item a button as a label of the
column but with the same name of the column ending
by ( _btn)
2 - when-button-pressed (block level of the buttons) type the following
code:
set_block_property('emp',order_by,substr(:system.cursor_item,1,instr(:system.cur
sor_item,'_',1)-1) );
go_block('emp');
execute_query;
================================================================================
=====
hide and show tab pages
=====================
DECLARE
tb_pg_id TAB_PAGE;
BEGIN
tb_pg_id := FIND_TAB_PAGE('P2');
IF GET_TAB_PAGE_PROPERTY(tb_pg_id, visible) = 'FALSE' THEN
SET_TAB_PAGE_PROPERTY(tb_pg_id, visible, property_true);
set_item_property('btn',label,'Hide');
else
SET_TAB_PAGE_PROPERTY(tb_pg_id, visible, property_false);
set_item_property('btn',label,'Show');
END IF;
END;
================================================================================
====
synchronize
=============
go_block('emp');
execute_query;
first_record;
loop
:tt := 'currently processing Employee -who works as "'||:job||'"';
EXCEPTION
WHEN NO_DATA_FOUND THEN
TEXT_IO.FCLOSE(in_file);
END;
---------------------------------------2 - create a button with a when button pressed trigger :
========================================
declare
fle varchar2(200);
begin
fle:= get_file_name('D:\'/*default directory*/,'hm.csv'/*default file
name*/,file_filter =>'Excel Files (*.csv)/*.csv',dialog_type =>
SAVE_FILE);
CREATE_FLAT_FILE(fle);
end;
================================================================================
====
moving and copying system files :
---------------------------------------------1- we need to attach the d2kwutil.pll to the form
2 - a button with this trigger:
Win_Api_Utility.Move_File
('c:\test.doc'/*the file which is needed to
be moved*/,'d:\hamdy.doc' /*this is the new file name and location*/);
================================================================================
=====
to cancel a report if the ouput is null
-------------------------------------------------befor report trigger:
==================
Function BEF_REP_TRG return boolean is
count_inv number;
begin
select count(*) into count_inv from EMP
where DEPTNO= :P_DEPTNO ;
if count_inv = 0 then
srw.message (0, 'No DATA found for printing');
--return false;
/* or use SRW.PRORAM_ABORT;
RAise srw.program_abort;
*/
end if;
return true;
End;
================================================================================
=====
to dynamically show only the number of records specified in a group
filter:
--------------in the data model:
-----------------select the group then F11
and put the following code:
function G_CUSTOMER_IDGroupFilter return boolean is
begin
:P_COUNT_CUST/* a parameter */ := nvl(:P_COUNT_CUST,0) + 1;
end;
----------------------------------------------------------------------------------------------openning a report from within a form or a menu:
------------------------------------------------declare
pl_id
begin
ParamList;
pl_id := Get_Parameter_List('emps');
IF NOT Id_Null(pl_id) THEN
Destroy_Parameter_List( pl_id );
end if;
pl_ID := Create_Parameter_List('emps');
Add_Parameter(pl_id,'Paramform',Text_PARAMETER,'NO');
Add_Parameter(pl_id,'MAXIMIZE',Text_PARAMETER,'Yes');
Run_Product(REPORTS, 'port_cash_available', SYNCHRONOUS,
RunTime,FILESYSTEM, pl_id, NULL);
end;
--------------------------------------------------------------------------------------------dynamically select the first n rows from a query:
---------------------------------------------------1 - create a parameter called mx
2 - before report trigger
function BeforeReport return boolean is
begin
srw.set_maxrow('Q_1'/*query name from the data model*/,:mx);
return (TRUE);
end;
--------------------------------------------------------------------------------------------To output the report to many extensions
-------------------------------1-create 3 buttons with the label of (excel - word - pdf - print)
2-create 2 procedures with the following code :
PROCEDURE Open_application(app varchar2) IS
File_Name Varchar2(150);
AppID PLS_INTEGER;
Begin
if app = 'xls' then
File_Name := 'D:\Program Files\Microsoft Office\Office\Excel
C:\temp\excel.xls';
Elsif app = 'rtf' then
File_Name := 'D:\Program Files\Microsoft Office\Office\winword
C:\temp\word.rtf';
end if;
-------------------------------------------------------------------------------------------If you know that the value in the WHERE clause of your query appears in
a very small percentage of the rows, you can use the INDEX hint to
force the optimizer to choose an index scan. In this statement, the INDEX
hint explicitly chooses an index scan on the SEX_INDEX, the index on the
SEX column
using index in a query
---------------------------SELECT /*+ INDEX(patients sex_index) Use SEX_INDEX, since there are few
male patients */
name, height, weight
FROM patients
WHERE sex = 'M';
-----------------------------using full table scan
----------------For example, Oracle performs a full table scan on the ACCOUNTS table to
execute this statement, even if there is an index on the ACCNO column
that is made available by the condition in the WHERE clause:
SELECT /*+ FULL(a) Don't use the index on ACCNO */ accno, bal
FROM accounts a
WHERE accno = 7086854;
Note: Because the ACCOUNTS table has an alias, A, the hint must refer
to the table by its alias, rather than by its name. Also, do not specify
schema names in the hint, even if they are specified in the FROM clause
-------------------------------------------------------------------------------------------declare
v_repid REPORT_OBJECT;
vc_rep VARCHAR2(20);
vc_rep_status VARCHAR2(20);
vc_URL VARCHAR2(100);
BEGIN
v_repid := FIND_REPORT_OBJECT('RP2RRO');
SET_REPORT_OBJECT_PROPERTY(v_repid,REPORT_FILENAME,'order_invoice');
SET_REPORT_OBJECT_PROPERTY(v_repid, REPORT_OTHER, 'porder_id=' ||
:orders.order_id);
vc_rep := RUN_REPORT_OBJECT(v_repid);
vc_rep_status := REPORT_OBJECT_STATUS(vc_rep);
WHILE vc_rep_status in ('RUNNING', 'OPENING_REPORT', 'ENQUEUED') LOOP
vc_rep_status := report_object_status(vc_rep);
END LOOP;
if vc_rep_status = 'FINISHED' then
message('Report Completed');
vc_URL :=
'/reports/rwservlet/getjobid'||substr(vc_rep,8)||'?server=RepSRV';
Web.show_document(vc_URL,'_blank');
else
message('Error when running report.');
end if;
END;
-------------------------------------------------------------------------------------------declare
mi_id MenuItem;
Cursor menu_items is
Select ITM_NM
from ITEMS where itm_id in (select ITM_ID from USER_ITEMS where
USR_ID=:global.user_id and OK = 'Y');
Begin
For m_i in menu_items Loop
mi_id := Find_Menu_Item(m_i.itm_id);
If Not ID_Null(MI_ID) Then
Set_Menu_Item_Property(mi_id,Enabled/*visible*/,PROPERTY_true);
End If;
End Loop;
End;
-------------------------------------------------------------------------------------------showing output in sql+.txt
--------------------------in SQL*Plus add :
-----------------SET SERVEROUTPUT ON SIZE 1000000 FORMAT WRAPPED
SET ECHO ON
-------------------------------------------------------------------------------------------TO KNOW IF THE NUMBER IS DOUBLE OR ODD SO WE CAN CONDITIONAL FORMAT THE
LINES OF THE REPORT TO
BE ON HILIGHTED AND THE NEXT IS NOT ..
--------------------------------------1 - IN THE REPORT WE CREATE A SUMMARY COLUMN CALLED "CS_ROWNUM"
TO SEQUENCE THE LINES (OR USE ROWNUM).
2 - CREATE A FORMULA COLUMN CALLED "CF_ODD_DOUBLE" WITH THE NEXT CODE :
function CF_1Formula return Number is
begin
IF MOD(:CS_ROWNUM/2,1) = 0 THEN
RETURN 0; -- IF IT'S DOUBLE NUMBER
ELSE
RETURN 1; -- IF IT'S ODD NUMBER
END IF;
end;
3 - USE THE CONDITIONAL FORMATING :
CF_ODD_DOUBLE EQUALS 0 THEN BACKGROUND = GREY12
-------------------------------------------------------------------------------------------/***************************************************************************
ALTER SYSTEM COMMAND :
************************
Keywords and Parameters
You can use the following options regardless of whether your instance
has the database dismounted or mounted, open or closed:
RESTRICTED SESSION
specifies whether logon to Oracle is restricted
ENABLE
allows only users with RESTRICTED SESSION system privilege to logon to
Oracle.
DISABLE
reverses the effect of the ENABLE RESTRICTED SESSION option, allowing
all users with CREATE SESSION system privilege to log on to Oracle.
For more information, see "Restricting Logons".
FLUSH SHARED_POOL
clears all data from the shared pool in the system global area (SGA).
For more information, see "Clearing the Shared Pool".
You can use the following options when your instance has the database
mounted, open or closed:
CHECKPOINT
performs a checkpoint.
GLOBAL
performs a checkpoint for all instances that have opened the database.
LOCAL
performs a checkpoint only for the thread of redo log file groups for
your instance. You can use this option only when your instance has the
database open.
If you omit both the GLOBAL and LOCAL options, Oracle performs a
global checkpoint. For more information, see "Performing a Checkpoint".
CHECK DATAFILES
GLOBAL
verifies that all instances that have opened the database can access
all online datafiles.
LOCAL
verifies that your instance can access all online datafiles.
If you omit both the GLOBAL and LOCAL options, Oracle uses GLOBAL by
default. For more information, see "Checking Datafiles".
You can use the following parameters and options only when your
instance has the database open:
RESOURCE_LIMIT
controls resource limits. TRUE enables resource limits; FALSE disables
resource limits. See also "Using Resource Limits".
GLOBAL_NAMES
controls the enforcement of global name resolution for your session.
TRUE enables the enforcement of global names; FALSE disables the
enforcement of global names. For more information, see "Global Name
Resolution".
SCAN_INSTANCES
in a parallel server, specifies the number of instances to participate
in parallelized operations. This syntax will be obsolete in the next
major release.
CACHE_INSTANCES
in a parallel server, specifies the number of instances that will
cache a table. This syntax will be obsolete in the next major release.
For more information on parallel operations, see Oracle8 Tuning.
SWITCH LOGFILE
switches redo log file groups. For more information, see "Switching
Redo Log File Groups".
DISTRIBUTED RECOVERY
specifies whether or not distributed recovery is enabled.
ENABLE
enables distributed recovery. In a single-process environment, you
must use this option to initiate distributed recovery.
DISABLE
switches redo log files.
For more information, see "Enabling and Disabling Distributed
Recovery".
ARCHIVE LOG
manually archives redo log files or enables or disables automatic
archiving. See the "ARCHIVE LOG clause".
KILL SESSION
terminates a session and any ongoing transactions. You must identify
the session with both of the following values from the V$SESSION view:
integer1
is the value of the SID column.
integer2
is the value of the SERIAL# column.
For more information, see "Terminating a Session".
DISCONNECT SESSION
disconnects the current session by destroying the dedicated server
process (or virtual circuit if the connection was made via MTS). If
configured, application failover will take effect. For more information about
application failover see Oracle8 Tuning and Oracle8 Parallel Server
Concepts and Administration. You must identify the session with both of
the following values from the V$SESSION view:
integer1
is the value of the SID column.
integer2
is the value of the SERIAL# column.
POST_TRANSACTION
allows ongoing transactions to complete before the session is
disconnected. This keyword is required when DISCONNECT SESSION is specified.
For more information, see "Disconnecting a Session".
PLSQL_V2_COMPATIBILITY
modifies the compile-time behavior of PL/SQL programs to allow
language constructs that are illegal in Oracle8 (PL/SQL V3), but were legal in
Oracle7 (PL/SQL V2). See the PL/SQL User's Guide and Reference and
Oracle8 Reference for more information about this system parameter.
TRUE
enables Oracle8 PL/SQL V3 programs to execute Oracle7 PL/SQL V2
constructs.
FALSE
disallows illegal Oracle7 PL/SQL V2 constructs. This is the default.
MAX_DUMP_FILE_SIZE
specifies the trace dump file size upper limit for all user sessions.
Specify the maximum size as either a nonnegative integer that
represents the number of blocks, or as 'UNLIMITED'. If you specify 'UNLIMITED',
no upper limit is imposed.
DEFERRED
modifies the trace dump file size upper limit for future user sessions
only.
Restricting Logons
By default, any user granted CREATE SESSION system privilege can log on
to Oracle. The ENABLE RESTRICTED SESSION option of the ALTER SYSTEM
command prevents logons by all users except those having RESTRICTED
SESSION system privilege. Existing sessions are not terminated.
You may want to restrict logons if you are performing application
maintenance and you want only application developers with RESTRICTED SESSION
system privilege to log on. To restrict logons, issue the following
statement:
ALTER SYSTEM
ENABLE RESTRICTED SESSION;
You can then terminate any existing sessions using the KILL SESSION
clause of the ALTER SYSTEM command.
After performing maintenance on your application, issue the following
statement to allow any user with CREATE SESSION system privilege to log
on:
ALTER SYSTEM
DISABLE RESTRICTED SESSION;
Clearing the Shared Pool
The FLUSH SHARED_POOL option of the ALTER SYSTEM command clears all
information from the shared pool in the system global area (SGA). The
shared pool stores this information:
cached data dictionary information
shared SQL and PL/SQL areas for SQL statements, stored procedures,
functions, packages, and triggers
You might want to clear the shared pool before beginning performance
analysis. To clear the shared pool, issue the following statement:
ALTER SYSTEM
FLUSH SHARED_POOL;
The above statement does not clear shared SQL and PL/SQL areas for SQL
statements, stored procedures, functions, packages, or triggers that
are currently being executed, or for SQL SELECT statements for which all
rows have not yet been fetched.
Performing a Checkpoint
The CHECKPOINT clause of the ALTER SYSTEM command explicitly forces
Oracle to perform a checkpoint. You can force a checkpoint if you want to
ensure that all changes made by committed transactions are written to
the data files on disk. For more information on checkpoints, see the
"Recovery Structures" chapter of Oracle8 Concepts.
If you are using Oracle with the Parallel Server option in parallel
mode, you can specify either the GLOBAL option to perform a checkpoint on
all instances that have opened the database or the LOCAL option to
perform a checkpoint on only your instance.
The following statement forces a checkpoint:
ALTER SYSTEM
CHECKPOINT;
Oracle does not return control to you until the checkpoint is complete.
Checking Datafiles
The CHECK DATAFILES clause of the ALTER SYSTEM command verifies access
to all online datafiles. If any datafile is not accessible, Oracle
writes a message to an ALERT file. You may want to perform this operation
after fixing a hardware problem that prevented an instance from
accessing a datafile. For more information on using this clause, see Oracle8
Parallel Server Concepts and Administration.
The following statement verifies that all instances that have opened
the database can access all online datafiles:
ALTER SYSTEM
CHECK DATAFILES GLOBAL;
Using Resource Limits
When you start an instance, Oracle enables or disables resource limits
based on the value of the initialization parameter RESOURCE_LIMIT. You
can issue an ALTER SYSTEM statement with the RESOURCE_LIMIT option to
enable or disable resource limits for subsequent sessions.
Enabling resource limits only causes Oracle to enforce the resource
limits already assigned to users. To choose resource limit values for a
user, you must create a profile, or a set of limits, and assign that
profile to the user. For more information on this process, see "CREATE
PROFILE" and "CREATE USER".
This ALTER SYSTEM statement dynamically enables resource limits:
ALTER SYSTEM
SET RESOURCE_LIMIT = TRUE;
Global Name Resolution
When you start an instance, Oracle determines whether to enforce global
name resolution for remote objects accessed in SQL statements based on
the value of the initialization parameter GLOBAL_NAMES. You can
subsequently enable or disable global name resolution while your instance is
running with the GLOBAL_NAMES parameter of the ALTER SYSTEM command. You
can also enable or disable global name resolution for your session with
the GLOBAL_NAMES parameter of the ALTER SESSION command discussed
earlier in this chapter.
Oracle recommends that you enable global name resolution if you use or
plan to use distributed processing. For more information on global name
resolution and how Oracle enforces it, see "Referring to Objects in
Remote Databases" and Oracle8 Distributed Database Systems.
Managing Processes for the Multithreaded Server
When you start your instance, Oracle creates shared server processes
and dispatcher processes for the multithreaded server architecture based
on the values of the following initialization parameters: MTS_SERVERS
specifies the initial and minimum number of shared server processes.
Oracle may automatically change the number of shared server processes if
the load on the existing processes changes. While your instance is
running, the number of shared server processes can vary between the values
of the initialization parameters MTS_SERVERS and MTS_MAX_SERVERS.
MTS_DISPATCHERS
specifies one or more network protocols and the number of dispatcher
processes for each protocol.
VARCHAR2(40);
NUMBER;
NUMBER;
IF COMMA_POS = 0 THEN
FIRST_TOKEN := LINEBUF;
LINEBUF := null;
ELSE
FIRST_TOKEN := SUBSTR(LINEBUF, 1, COMMA_POS - 1);
LINEBUF := SUBSTR(LINEBUF, COMMA_POS + 1);
END IF;
RETURN FIRST_TOKEN;
END;
------------------------------------------------------------------------------------------2- this script to open prowser on txt file only
:FILE_PATH := GET_FILE_NAME(File_Filter=>'Text Files (*.txt)|*.txt|');
-------------------------------------------------------------------------------------------3- this script read data from text file
declare
MYFILE TEXT_IO.FILE_TYPE;
LINEBUF VARCHAR(255);
emp_num number;
s_min
number;
e_min
number;
no_hr
number;
co_num number;
col_nm varchar2(30);
c_in
varchar2(10);
c_out
varchar2(10);
h_late varchar2(10);
h_early varchar2(10);
d_abs
varchar2(10);
str_hr
varchar2(10);
end_hr
varchar2(10);
file_date date;
f_date
varchar2(20);
shift_no number;
orv_tim varchar2(10);
ovr_vac varchar2(10);
BEGIN
if :FILE_PATH is null then
message('File Must be Selected First');
message('File Must be Selected First');
go_block('CG$CTRL');
go_item('FILE_PATH');
RAISE FORM_TRIGGER_FAILURE;
end if;
MYFILE := TEXT_IO.FOPEN(:FILE_PATH, 'R');
TEXT_IO.GET_LINE(MYFILE, LINEBUF);
GO_BLOCK('EXCEL_FILE');
CLEAR_BLOCK;
first_record;
LOOP
TEXT_IO.GET_LINE(MYFILE, LINEBUF);
emp_num
f_date
file_date
c_in
c_out
h_late
h_early
d_abs
end loop;
EXCEPTION
:=
:=
:=
:=
:=
:=
:=
:=
TO_NUMBER(TOKEN(LINEBUF));
TOKEN(LINEBUF);
to_date(f_date,'dd/mm/yyyy');
TOKEN(LINEBUF);
TOKEN(LINEBUF);
TOKEN(LINEBUF);
TOKEN(LINEBUF);
TOKEN(LINEBUF);
end ;
EXCEPTION WHEN NO_DATA_FOUND THEN TEXT_IO.FCLOSE(MYFILE
);
/***************************************************************************/
// set color filed in report
srw.attr.mask := srw.weight_attr+srw.gcolor_attr+srw.fillpatt_attr+srw.ffcolor
_attr;
srw.attr.weight := srw.bold_weight ;
srw.attr.gcolor := 'red' ;
srw.attr.fillpatt := 'GRAY20';
srw.attr.ffcolor := 'BLUE';
srw.set_attr(0,srw.attr);
/*change item color in report************************************************/
SRW.SET_TEXT_COLOR('white');
srw.set_foreground_fill_color('red');
srw.set_fill_pattern('solid');
/***************************************************************************/
select * from user_tab_comments;
select * from user_col_comments;
/***************************************************************************/
/*update with sub query
update EMP_BAL
set ANUAL_BAL = 30
where emp_no in (select EMP_NO
from PERSONAL
where (trunc(sysdate) - trunc(HIRE_DATE_BEFORE))/365 > 5)
/***************************************************************************/
--calling report in 10g
DECLARE
repid REPORT_OBJECT;
v_rep VARCHAR2(100);
rep_status VARCHAR2(20);
BEGIN
repid := find_report_object('report4');
v_rep := RUN_REPORT_OBJECT(repid);
END;
/***************************************************************************/
-- Moving multiple tables and indexes between tablespaces at once
ALTER TABLE xxxxxx MOVE TABLESPACE TEST;
ALTER INDEX xxxxxx REBUILD TABLESPACE TEST;
/***************************************************************************/
/***************************************************************************/
select dbms_random.string('a', level)
from dual
connect by level <= 10
/***************************************************************************/
SELECT 'I'||CHR(10)
FROM DUAL
UNION
SELECT 'NEED'||chr(10)
FROM DUAL
UNION
SELECT 'A'||chr(10)
FROM DUAL
UNION
SELECT 'LIST'||chr(10)
FROM DUAL
UNION
SELECT 'WITH'||chr(10)
FROM DUAL
UNION
SELECT 'WORDS'||chr(10)
FROM DUAL
UNION
SELECT 'NOT'||chr(10)
FROM DUAL
UNION
SELECT 'LETTERS'||chr(10)
FROM DUAL
/***************************************************************************/
with t as (select 'I Need a List with Words not Letters' as txt from dual)
-select regexp_substr(txt, '[^ ]+', 1, rownum) as word
from t
connect by rownum <= length(regexp_replace(txt,'[^ ]'))+1
/***************************************************************************/