16 Aug 2017

Generating Calendar

--GENERATING DATES FOR ONE YEAR
SELECT TRUNC(SYSDATE,'YEAR') + LEVEL-1 AS GEN_DATE
FROM DUAL
CONNECT BY TRUNC(SYSDATE,'YEAR') +LEVEL-1 < ADD_MONTHS(TRUNC(SYSDATE,'YEAR'),12)

OUTPUT
    GEN_DATE
1 1/1/2017
2 1/2/2017
3 1/3/2017
4 1/4/2017
5 1/5/2017
...
361 12/27/2017
362 12/28/2017
363 12/29/2017
364 12/30/2017
365 12/31/2017

Generating The Transaction Dates

--GENERATE_DATES
WITH
START_AND_END(START_DATE,END_DATE)
AS (SELECT TRUNC(SYSDATE,'MONTH'), LAST_DAY(SYSDATE) FROM DUAL)
SELECT START_DATE + LEVEL-1 AS TRANS_DATE
FROM START_AND_END
CONNECT BY LEVEL <=END_DATE - START_DATE +1;

Output
    TRANS_DATE
1 8/1/2017
2 8/2/2017
3 8/3/2017
4 8/4/2017
5 8/5/2017
6 8/6/2017
7 8/7/2017
8 8/8/2017
9 8/9/2017
10 8/10/2017
11 8/11/2017
12 8/12/2017
13 8/13/2017
14 8/14/2017
15 8/15/2017
16 8/16/2017
17 8/17/2017
18 8/18/2017
19 8/19/2017
20 8/20/2017
21 8/21/2017
22 8/22/2017
23 8/23/2017
24 8/24/2017
25 8/25/2017
26 8/26/2017
27 8/27/2017
28 8/28/2017
29 8/29/2017
30 8/30/2017
31 8/31/2017

2 Mar 2017

Calling Reports in 11g

How to call reports using oracle forms 11g developer (Oracle Fusion) or 10g Developer with paramform=yes

Well I am sure this example will also help you to create your production level forms and reports.
This is the simple example using the demo user of oracle “HR” having table“employee”.
*************
Coding for report calling using paramform=yes or paramform=no is different.
So given below example will help you to call the report using paramform=yes.
It will create a new web page with the parameters defined on the report.
*************
Create a simple report based on table EMPLOYEE with a user parameter:
SELECT ALL EMPLOYEES.EMPLOYEE_ID, EMPLOYEES.FIRST_NAME, EMPLOYEES.LAST_NAME, 
EMPLOYEES.HIRE_DATE, EMPLOYEES.SALARY, EMPLOYEES.DEPARTMENT_ID
FROM EMPLOYEES 
WHERE DEPARTMENT_ID=:DEPARTMENT;

Now Compile and save the report C:\TEST\FORMS11G\EMP.RDF. Please check your report is working fine and also taking the report input from your parameter. You can view the output in run preview.
Then create a simple form and drag a button to call report using the procedure or create a menu or Htree based menu to call that procedure.

Now add a new object for "Reports" in the object navigator of Forms.

A dialog box will appear and select the option "Use Existing Report File" and browse the file. An object with the default name will appear under Reports Object.

Now Open Property Palette for Reports objects in the Forms Object Navigator and see the following values:

Name: EMPLOYEE
Filename: C:\TEST\FORMS11G\EMP.RDF 
Now Check your Weblogic server is in running mode or 
Start Your Weblogic Server (Whatever configuration you had set)
Now check your 11g report server is running or 
Note: Please note that for 10g you must specify full path to your RDF file or add this path into REPORTS_PATH environment variable. 
Report Destination Type: CACHE 
Report Destination Format: HTML 
Report Server: rep_adminserver_my-pc_asinst_2
(This is the same server name as defined in the file D:\Oracle\Middleware\asinst_2\reports\reports_install.properties)
On button create a WHEN-BUTTON-PRESSED trigger with the following code: 
Test_report;
Now create a procedure.
Name = test_report
Now write the code in the area of code: 
***********************
PROCEDURE TEST_REPORT_PARAMFORMYES IS

vc_urlvarchar2(1000);
            vc_user_nameVARCHAR2(100);
            vc_user_passwordVARCHAR2(100);
            vc_user_connectVARCHAR2(100);
            vc_connectVARCHAR2(300);      
            vc_reportvarchar2(100) := 'C:\TEST\FORMS11G\emp.rdf';
            vc_servervarchar2(50):= 'rep_adminserver_my-pc_asinst_2';
BEGIN
            vc_user_name:=get_application_property(username);
            vc_user_password:=get_application_property(password);
            vc_user_connect:=get_application_property(connect_string);
            vc_connect:=vc_user_name||'/'||vc_user_password||'@'||vc_user_connect;
           
            vc_url:='http://my-pc:7001/reports/rwservlet?server='||vc_server
            || '&report='||vc_report||'&desformat=pdf&destype=cache'
            || '&userid='||vc_connect
            || '&P_REP_NM='||vc_report
            || '&P_ACTION='||'http://my-pc:7001/reports/rwservlet?'
            || '&P_SERVERNAME='||vc_server
            || '&P_USER_CONNECT='||vc_connect
            || '&paramform=yes';

WEB.SHOW_DOCUMENT(vc_url,'_blank');
END;
***********************
Now simply compile the form. 
And Run the form then click the button. A new web page will appear with the parameters of department. Now pass the parameters on the web based parameters and Report will be displayed in a new browser window if you have mention the html format or else an acrobat reader will run and will show the report. 
If Report is not working smoothly

Open the report_install file
Located at D:\Oracle\Middleware\asinst_1\reports
Locate the Parameter 
REPORTS_APP_CONFIGURATION_DIR=D\:\\Oracle\\Middleware\\user_projects\\domains\\FormsClassicDomain\\config\\fmwconfig\\servers\\WLS_REPORTS\\applications\\reports_11.1.2\\configuration

Edit the file rwservlet.properties located on
 <DomainHome>\config\fmwconfig\servers\WLS_REPORTS\applications\reports_11.1.2.1.0\configuration

 Add the following parameter below the <inprocess> parameter:
 <webcommandaccess>L2</webcommandaccess>

 Re-start the WLS_REPORTS Server.

17 Feb 2017

Timer Example On Web Server Form.
CREATE ONE CONTROL BLOCK HAVING ONE DISPLAY ITEM AND FIVE PUSH BUTTONS.
PROPERTIES OF DISPLAY ITEM
NAME : MY_SCROLL_BAR
DATA TYPE          : CHARACTER
MAX LENGTH     :30
XPOSITION         : 259
YPOSITION          :157
WIDTH                  : 5
HEIGHT                 :12

PUSH BUTTONS  PROPERTIES
NAME                                   : CREATE              STOP     RESET    DELETE  DEFAULT
WIDTH                                 : 113                       113         113         113         0
HEIGHT                               : 20                         20           20           20           0
XPOS                                   : 25                         86           421         464         0
YPOS                                   : 52                         153         153         52           0
Keyboard Navigation           : No                        No          No          No          Yes
Mouse Navigation                : No                        No          No          No          Yes

Trigger on Create Button
DECLARE
                V_TIMER TIMER;
BEGIN
                -- FIND TIMER FIRST IF ALREADY EXISTS.
                V_TIMER := FIND_TIMER('PRGBARTMR');
                IF ID_NULL(V_TIMER) THEN
                -- CREATING TIMER FOR ONE SECOND... ONE SECOND = 1000 MILLISECOND
                V_TIMER := CREATE_TIMER('PRGBARTMR', 1000, REPEAT);
                ELSE
                                MESSAGE('ALREADY EXISTS.');
                END IF;
                -- WILL HANDLE THIS TIMER IN FORM LEVEL WHEN-TIMER-EXPIRED TRIGGER
END;

Trigger On Stop Button
DECLARE
                V_TIMER TIMER;
BEGIN
                -- FIND THE TIMER FIRST
                V_TIMER := FIND_TIMER('PRGBARTMR');
                IF NOT ID_NULL(V_TIMER) THEN
                                -- THIS WILL STOP THE TIMER AFTER ONE MILLISECOND
                                SET_TIMER(V_TIMER, 1, NO_REPEAT);
                END IF;
                -- WILL HANDLE THIS TIMER IN FORM LEVEL WHEN-TIMER-EXPIRED TRIGGER
END;




Trigger On Delete Button
DECLARE
                V_TIMER TIMER;
BEGIN
                -- FIND THE TIMER FIRST
                V_TIMER := FIND_TIMER('PRGBARTMR');
                IF NOT ID_NULL(V_TIMER) THEN
                                -- THIS WILL DELETE THE TIMER
                                DELETE_TIMER(V_TIMER);
                END IF;
END;

Trigger On Reset Button
DECLARE
                V_TIMER TIMER;
BEGIN
                -- FIND THE TIMER FIRST
                V_TIMER := FIND_TIMER('PRGBARTMR');
                IF NOT ID_NULL(V_TIMER) THEN
                                -- THIS WILL RE-START THE TIMER AFTER ONE SECOND
                                SET_TIMER(V_TIMER, 1000, REPEAT);
                ELSE
                                V_TIMER := CREATE_TIMER('PRGBARTMR',1000, REPEAT);
                END IF;
                -- WILL HANDLE THIS TIMER IN FORM LEVEL WHEN-TIMER-EXPIRED TRIGGER
END;

Coding on When Timer Expired
DECLARE
                V_TIMER_NAME VARCHAR2(30);
                V_WIDTH NUMBER;
BEGIN
                -- GET THE TIMER NAME FIRST.. TO KNOW WHICH TIMER HAS EXPIRED.. IF MULTIPLE TIMER ARE RUNNING
  V_TIMER_NAME := GET_APPLICATION_PROPERTY(TIMER_NAME);
  -- CHECK IF THE SAME TIMER WITH CAPITAL LETTERS
  IF V_TIMER_NAME = 'PRGBARTMR' THEN
                 V_WIDTH := GET_ITEM_PROPERTY('BLKTMR.PRGBAR', WIDTH);
                 IF V_WIDTH < 100 THEN
                                  V_WIDTH := V_WIDTH + 5;
                 ELSE
                                  V_WIDTH := 0;
                 END IF;
                 SET_ITEM_PROPERTY('BLKTMR.PRGBAR', WIDTH, V_WIDTH);
                END IF;
END;


13 Feb 2017

UTL_MATCH : String Matching by Testing Levels of Similarity/Difference

The UTL_MATCH package was introduced in Oracle 10g Release 2, but first documented (and therefore supported) in Oracle 11g Release 2.
To See The Details Follow the following Link
My Query Example
SELECT 'MUHAMMAD' COL1,
       'MOHAMMAD' COL2,
       UTL_MATCH.JARO_WINKLER_SIMILARITY('MUHAMMAD', 'MOHAMMAD') AS JWS
  FROM DUAL
UNION
SELECT 'MOHAMMAD',
       'MEHMOOD',
       UTL_MATCH.JARO_WINKLER_SIMILARITY('MEHMOOD', 'MOHAMMAD') AS JWS
  FROM DUAL

UNION

SELECT 'MARRY',
       'MARRIE',
       UTL_MATCH.JARO_WINKLER_SIMILARITY('MARRY', 'MARRIE') AS JWS
  FROM DUAL;

OUTPUT
    COL1 COL2 JWS
1 MARRY MARRIE 89
2 MOHAMMAD MEHMOOD 74
3 MUHAMMAD MOHAMMAD 92

6 Feb 2017

CREATE OR REPLACE TYPE HR.a_email_address as object (email_add VARCHAR2(100))
/

CREATE OR REPLACE TYPE HR.a_email_add as table of a_email_address
/

CREATE OR REPLACE FUNCTION HR.get_email_add (rcplist IN VARCHAR2)
  RETURN a_email_add
  IS
-- rcplist as parameter should contain comma separated data ( if more than 1 recipient )
  l_email_add a_email_add := a_email_add();
  xx number:=1;
  --
Begin
  for rec in (
              select substr(rcplist,
                     instr(','||rcplist||',', ',', 1, rn),
                     instr(','||rcplist||',', ',', 1, rn+1)
                     - instr(','||rcplist||',', ',', 1, rn) - 1) mvalue
                from ( select level rn from dual
             connect by level <= length(rcplist)-length(replace(rcplist,',',''))+1)
             )
  loop
   --DBMS_OUTPUT.PUT_LINE (rec.mvalue);
     l_email_add.extend;
     l_email_add(l_email_add.last) := a_email_address(NULL);
     --
     l_email_add(xx).email_add := rec.mvalue;
     xx:=xx+1;
   end loop;
  --
  Return l_email_add;
End;
/

To test above code

SELECT * FROM TABLE(get_email_add(‘afzaal@mcbah.com,shabbir@mcbah.com,Kashif@mcbah.com’)

/
Websites

SQL / PL-SQL on Oracle Community - various related documents and articles to understand various features / functionalities



SQL Full Outer Koin



this is a PDF file which is online and on page # 11, 12 there is mentioned Forms 6i, Character Set and related Patch, please check.

Official site download link for latest version, if want to:

Working Key
ver 9.0.6
Product Code:  46q6ntekz7kx5ctygpjeeh6f5wavambtly 
Serial Number: 580356
Password:      xs374ca 


ver 11.0
Registration Code: 
Product Code: 4t46t6vydkvsxekkvf3fjnpzy5wbuhphqz 
Serial Number: 601769 
Password: xs374ca

Learn Oracle SQL also find readymade Scripts
attached is a PDF document from Intel Corporation for their new PC's ( new not for all but most of us ) or visit below link:

A must visit site for all of us, here is real Treasure, almost every famous Qaari
Oracle Forms & Reports 12c Installation guide  ( it includes installation guide of Web Logic Server )

Link 1 ( on Linux )

Link 2  ( on Win 7 )

Link 3  ( on Win 7 )
If someone wants to, here is a link contain complete step-by-step guide to install Oracle Forms & Reports 12c on Windows 7. Also contain links to install Weblogic Server and Database 12c.


Oracle Official Community Forum

Comprehensive Oracle related information for various versions.

Forum for approx. all Oracle technologies.
Please read it, we have to be much more thankful to ALLAH Sub’hanahu Wa-Ta’ala.
Very important topic for DBAs and Developers, but this much DEPENDS on how we have designed our DB Structures.
Oracle Regular Expression Enhancement in 11g
SQL

Storing and Retrieving XML Data in Oracle 11g
Site for various Samples, used PJC’s in Forms 10g


A Forum to discuss, understand and knowledge on Oracle Forms, Plug able Java Components (PJC) - Share knowledge and experience

 Webutil Configuration file for Forms 10g to run locally from our PC, here are some Forms 10g Tips & Techniques for us ( may be you will find something new for you… )


ADF


Here is a sample and results of INTERPRETED and NATIVE compilation feature of Oracle PL/SQL, kindly have a look.

-- ==========================================================================================
-- test of INTERPRETED (default) and NATIVE compiled objects (Packages/Procedures/Functions)
-- NOTE: noticeable performance / difference will be seen on where much / heavy calculations
-- (of any kind) involved
-- ==========================================================================================

CREATE PACKAGE ncomp_test AS
     PROCEDURE simple(p_comp IN VARCHAR2);
     PROCEDURE pls(p_comp IN VARCHAR2);
END ncomp_test;
/

CREATE OR REPLACE PACKAGE BODY ncomp_test AS
     -- define variables here to use in all Procedures/Functions of Package Body
     l_start NUMBER:=0;
     --
     --
     PROCEDURE simple(p_comp IN VARCHAR2) IS
        s SIMPLE_INTEGER := 0;
     BEGIN
       l_start := DBMS_UTILITY.get_time;
       FOR i IN 1 .. 10 ** 8 LOOP
           s := s + 1;
       END LOOP;
       DBMS_OUTPUT.put_line('Simple Integer took : ' ||
                       Round(((DBMS_UTILITY.get_time - l_start)/60),2)||' Seconds');
     END simple;
     --
     --
     PROCEDURE pls(p_comp IN VARCHAR2) IS
        p PLS_INTEGER := 0;
     BEGIN
        l_start := DBMS_UTILITY.get_time;
        FOR i IN 1 .. 10 ** 8 LOOP
           p := p + 1;
        END LOOP;
       DBMS_OUTPUT.put_line('PLS Integer took : ' ||
                       Round(((DBMS_UTILITY.get_time - l_start)/60),2)||' Seconds');
     END pls;

END ncomp_test;
/

-- this will run in default INTERPRETED mode
-- =========================================
BEGIN
  ncomp_test.simple('INTERPRETED');
  ncomp_test.pls('INTERPRETED');
END;
/

Simple Integer took : 4.7 Seconds
PLS Integer took : 4.55 Seconds

PL/SQL procedure successfully completed.


-- this will set mode to NATIVE
ALTER PACKAGE ncomp_test COMPILE PLSQL_CODE_TYPE = NATIVE;

-- this will run in NATIVE mode
-- ============================
BEGIN
  ncomp_test.simple('NATIVE');
  ncomp_test.pls('NATIVE');
END;
/

Simple Integer took : .65 Seconds
PLS Integer took : 1.68 Seconds

PL/SQL procedure successfully completed.


Test again in default mode

-- this will set mode to INTERPRETED – default mode
ALTER PACKAGE ncomp_test COMPILE PLSQL_CODE_TYPE = INTERPRETED;

BEGIN
  ncomp_test.simple('INTERPRETED');
  ncomp_test.pls('INTERPRETED');
END;
/

Simple Integer took : 4.7 Seconds
PLS Integer took : 4.55 Seconds


PL/SQL procedure successfully completed.
Here are findings regarding Oracle 11g, here are with complete examples. 

1)      Seudo Column in Tables - apply any complex formula here

in this example: update Sale_category column based on value of sales_amt directly
without user interaction, its like a DEFAULT value on column
---------------------------------------------------------------------------------

create table hr.sales
(
   sales_id      number,
   cust_id       number,
   sales_amt     number,
   sale_category varchar2(6)
   generated always as
   (
      case
         when sales_amt <= 10000
            then 'LOW'
         when sales_amt > 10000
            and sales_amt <= 100000
            then case
               when cust_id < 101 then 'LOW'
               when cust_id between 101 and 200 then 'MEDIUM'
               else 'MEDIUM'
            end
         when sales_amt > 100000
            and sales_amt <= 1000000
            then case
               when cust_id < 101 then 'MEDIUM'
               when cust_id between 101 and 200 then 'HIGH'
               else 'ULTRA'
            end
         else 'ULTRA'
      end
    ) virtual
);

insert into hr.sales (sales_id, cust_id, sales_amt) values (1,1,100);
insert into hr.sales (sales_id, cust_id, sales_amt) values (2,101,100001);
insert into hr.sales (sales_id, cust_id, sales_amt) values (3,102,1500);
insert into hr.sales (sales_id, cust_id, sales_amt) values (4,102,10000);
insert into hr.sales (sales_id, cust_id, sales_amt) values (5,101,100000);
insert into hr.sales (sales_id, cust_id, sales_amt) values (5,101,1000000);
insert into hr.sales (sales_id, cust_id, sales_amt) values (6,102,10000000);

select * from hr.sales;

  SALES_ID    CUST_ID  SALES_AMT SALE_C
---------- ---------- ---------- ------
         1          1        100 LOW
         2        101     100001 HIGH
         3        102       1500 LOW
         4        102      10000 LOW
         5        101     100000 MEDIUM
         5        101    1000000 HIGH
         6        102   10000000 ULTRA

7 rows selected.

drop table hr.sales;

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


2)      Using a Constraint to Enforce a Phone Number Format with Regular Expression

Regular expressions are useful for enforcing constraints—for example, to ensure that phone numbers are entered into the

database in a standard format. Example 3-1 creates a contacts table and adds a CHECK constraint to the p_number column to

enforce the below format model:

(XXX) XXX-XXXXXXX
(092) 333-1234567


CREATE TABLE hr.contacts (
  cust_name    VARCHAR2(30),
  cust_mobile  VARCHAR2(30)
  CONSTRAINT c_contacts_pnf
  CHECK (REGEXP_LIKE (cust_mobile, '^\(\d{3}\) \d{3}-\d{7}$'))
);

test entering wrong format in cust_mobile column
------------------------------------------------
HR.@.xe > insert into hr.contacts values ('My Customer 1','123456789');
insert into hr.contacts values ('My Customer 1','123456789')
*
ERROR at line 1:
ORA-02290: check constraint (HR.C_CONTACTS_PNF) violated


HR.@.xe > insert into hr.contacts values ('My Customer 1','(092) 333-123456');
insert into hr.contacts values ('My Customer 1','(092) 333-123456')
*
ERROR at line 1:
ORA-02290: check constraint (HR.C_CONTACTS_PNF) violated


now make a correct entry ...
----------------------------
  1* insert into hr.contacts values ('My Customer 1','(092) 333-1234567')
HR.@.xe > /

1 row created.


commit;