Thursday, June 24, 2010

How oracle works

The following example describes the most basic level of operations that Oracle performs. This illustrates an Oracle configuration where the user and associated server process are on separate machines (connected through a network).

An instance has started on the computer running Oracle (often called the host or database server).
A computer running an application (a local machine or client workstation) runs the application in a user process. The client application attempts to establish a connection to the server using the proper Oracle Net Services driver.
The server is running the proper Oracle Net Services driver. The server detects the connection request from the application and creates a dedicated server process on behalf of the user process.
The user runs a SQL statement and commits the transaction. For example, the user changes a name in a row of a table.
The server process receives the statement and checks the shared pool for any shared SQL area that contains a similar SQL statement. If a shared SQL area is found, then the server process checks the user's access privileges to the requested data, and the previously existing shared SQL area is used to process the statement. If not, then a new shared SQL area is allocated for the statement, so it can be parsed and processed.
The server process retrieves any necessary data values from the actual datafile (table) or those stored in the SGA.
The server process modifies data in the system global area. The DBWn process writes modified blocks permanently to disk when doing so is efficient. Because the transaction is committed, the LGWR process immediately records the transaction in the online redo log file.
If the transaction is successful, then the server process sends a message across the network to the application. If it is not successful, then an error message is transmitted.
Throughout this entire procedure, the other background processes run, watching for conditions that require intervention. In addition, the database server manages other users' transactions and prevents contention between transactions that request the same data.

setting arabic environment for oracle reports and conversion in translation hub

configuration of arabic reports(internal)
------------------------------------------

1.http://www.araboug.org/ib/index.php?showtopic=25004
2.start>run
type:regedit
HKEY_LOCAL_MACHINE>SOFTWARE>ORACLE>KEY_DevSuiteHome2>
search for reports_arabic_numeral
if not found >right click >new>string_value>type:reports_arabic_numeral>(double click on reports_arabic_numeral)>type:hindi.

3.set nls as ARABIC_UNITED ARAB EMIRATES.AR8MSWIN1256

4.run pdf reports which supports arabic arcobat reader.
5.set envrionment as arabic .



configuration in report bulider for arabic conversion
-------------------------------------------------------

1) Open Reports Builder.
2) Go To: Tools/File Conversion (source=\\standard\hre3010.rdf,des=\\arabic\hre3010.rex)
3) Convert reports desired to ".rex"
4) Load .rex reports into Translation Hub import=\\arabic build=\\arabic)
5) Run through Translation Hub
6) Convert files from rex to ".rdf"
7)Go to report bulider Tools/File Conversion rdf to rep.

ORACLE FORMS & REPORTS COMPONENTS

ORACLE FORMS 2 COMPONENTS

1.Form bulider (oracle bulider) =run_report_object
2.Form service web deployment =web.show_document.

running forms with components

x The formsweb.cfg configuration file
x The default.env environment file
x The Forms Servlet (interaction btn forms and web)
x The Forms Listener Servlet(commucation btn forms client and form user runtime process)
x Oracle Containers for J2EE (OC4J)


[reptest]
form=reptest
userid=scott/tiger@orcl
look&feel=oracle
width=700
height=500


formsweb.conf (defines parameter values used by the FormsServlet)
-----------
1.system parameter
->baseHTML=base.htm
->baseHTMLjinitiator=basejini.htm
->baseHTMLjpi=basejpi.htm
->HTMLdelimiter=%
->workingDirectory=\\abc\arabic\fe10g\
->envFile=default.env
2.user parameter
->escapeparams=true(whether to escape certain special characters)
->form=mainmenu3.fmx(which form module to run)
->userid,portid,hostid.
->applet width,height and other parameter details abt forms loaded in html page.

3.custom application parameters
->server url specification
->http://:/forms90/f90ervlet?config=reptest&separateFrame=true
default.env
-----------
->home dir specify(ORACLE_HOME=E:\DevSuiteHome_1)
->Search path for Forms applications(FORMS_PATH=E:\DevSuiteHome_1\forms)
->webutil config file path
->statements when in enter-query mode.(FORMS_RESTRICT_ENTER_QUERY=TRUE)
->pick up the JVM (jvm.dll)
->Settings for Graphics
->Settings for Forms tracing and logging
->System settings
->Java class path
The Forms Servlet
-----------------
->http://:/forms90/f90servlet.
->http://:/forms90/f90servlet?config=reptest
->http://:/forms90/f90servlet?config=reptest&form=reptest
->http://:/forms90/f90servlet?form=reptest&userid=scott/tiger@orcl&lookandfeel=oracle
->It calls formsweb.conf ,HTML parts
->download of the Forms Java applet to the client
->Forms Servlet is released to serve other application requests.
->Its calls the default.env files.

The Forms Listener server
-------------------------
->commucation btn form server and client
->Its placed in formsweb.cfg
->default value "/forms/frmservlet".
oc4j and mod_oc4j
-----------------
->oracle container for j2ee default runtime server for oracle forms and developer.
->mod_oc4j send request from Oracle HTTP Server(servlet) TO Oracle Application Server Containers for J2EE (OC4J),

differents btn tis files
-------------------------
->base.html = its a html file running for generic APPLET tag.\
CODE="oracle.forms.engine.Main"
ARCHIVE="%archive%"
WIDTH="%Width%"
HEIGHT="%Height%">
->basejinit.html =JInitiator-style tags to include the Forms applet
codebase="/forms/jinitiator/%jinit_exename%"
WIDTH="%Width%"
HEIGHT="%Height%"
HSPACE="0"
VSPACE="0">
->basejpi.html = using the JDK Java Plugin
codebase="%jpi_codebase%"
WIDTH="%Width%"
HEIGHT="%Height%"
HSPACE="0"
VSPACE="0">
ORACLE REPORTS 2 COMPONENTS
---------------------------

1.Report bulider (oracle bulider) =run_report_object
2.Reports Services deployment environment. =web.show_document.

main components
----------------
x The Reports Servlet (UZVHUYOHW for paper layouts)
x The Reports Server process
x Rwservlet.properties configuration file
x .conf configuration file
x The cgicmd.dat file


Report Servlet
-------------
->rwservlet default web related report server. (Single Sign-On authentication)
->It dispatch the request from HTTPrequest to Report server Enginee.
Report Server
-------------
->Manage mutiple report at runtime.
->2 types
1.Report 'inprocess' server (rep_) example our product as_server reports.
2.Report 'extra process' server. (rwserver server=aaf00074_rs)own process server.
rwservlet.properties conf file
--------------------------------
->Its shows COOKIEEXPIRE,SINGLESIGNON,REPORTS_NETWORK_CONFIG

.conf file
---------------------------
->.conf configuration file is created the first time a Reports Server is started.
->place here E:\DevSuiteHome_1\reports\conf


cgicmd.dat
-------------
->keyname/ value pairs, where the value defines a number of Reports command-line arguments to be used with one or with many Reports files,
each mapped to a named identifier
->

examples for query optimization

1.Code the query as simply as possible i.e. no unnecessary columns are selected, no unnecessary GROUP BY or ORDER BY.
It is the same or faster to SELECT by actual column name(s). The larger the table the more likely the savings.
Use:
SELECT customer_id, last_name, first_name, street, city FROM customer;
Rather than,

SELECT * FROM customer;

2.

Given Query

Alternative

SELECT ename, hiredate, sal
FROM emp1
WHERE
SUBSTR(ename,1,3) = 'SCO';

SELECT ename, hiredate, sal
FROM emp1
WHERE
ename LIKE 'SCO%';

VARIABLE name VARCHAR2(20)
exec name := 'SCOTT'

SELECT ename, hiredate, sal
FROM emp1
WHERE
ename = NVL (:name, ename);

VARIABLE name VARCHAR2(20)
exec name := 'SCOTT'

SELECT ename, hiredate, sal
FROM emp1
WHERE
ename LIKE NVL (:name, '%');

SELECT ename, hiredate, sal
FROM emp1
WHERE
TRUNC (hiredate) = TRUNC (SYSDATE);

SELECT ename, hiredate, sal
FROM emp1
WHERE hiredate
BETWEEN TRUNC (SYSDATE)
AND TRUNC (SYSDATE) +
.99999;

SELECT ename, hiredate, sal
FROM emp1
WHERE
ename || empno = 'SCOTT7788';

SELECT ename, hiredate, sal
FROM emp1
WHERE
ename = 'SCOTT
AND empno = 7788;

SELECT ename, hiredate, sal
FROM emp1
WHERE
sal + 3000 <>

SELECT ename, hiredate, sal
FROM emp1
WHERE
sal <>

SELECT ename, hiredate, sal
FROM emp1
WHERE sal
!= 0;

SELECT ename, hiredate, sal
FROM emp1
WHERE sal
> 0;


3.

3.

Given Query

Alternative

SELECT d.dname, AVG (e.sal)
FROM emp1 e, dept1 d
WHERE e.deptno = d.deptno
GROUP BY d.dname
HAVING dname != 'RESEAECH'
AND dname != 'SALES';

SELECT d.dname, AVG (e.sal)
FROM emp1 e, dept1 d
WHERE e.deptno = d.deptno
AND dname != 'RESEAECH'
AND dname != 'SALES'
GROUP BY d.dname;

4.

Separate Subqueries

Combined Subqueries

SELECT ename
FROM emp1
WHERE sal = (SELECT MAX (sal)
FROM EMP1)
AND comm = (SELECT MAX (comm)
FROM EMP1);

SELECT ename
FROM emp1
WHERE (sal,comm) = (SELECT MAX (sal), MAX(comm)
FROM EMP1);

5. EXISTS is a faster alternative, because the Oracle optimizer realizes when the subquery has been satisfied once, there is no need to proceed further and the next matching row can be fetched.

Given Query

Alternative

SELECT DISTINCT d.deptno, d.dname
FROM dept1 D,
emp1 E
WHERE D.deptno = E.deptno;

SELECT d.deptno, d.dname
FROM dept1 D
WHERE
EXISTS (SELECT 'X'
FROM emp1 E
WHERE E.deptno = D.deptno);

Select deptno,dname from dept where deptno in (select distinct deptno from emp)

6. The UNION clause forces all rows returned by each portion of the UNION to be sorted and merged and duplicates to be filtered before the first row is returned. A UNION ALL simply returns all rows including duplicates and does not have to perform any sort, merge or filter. If your tables are mutually exclusive (include no duplicate records), or you don't care if duplicates are returned, the UNION ALL is much more efficient.

UNION

UNION ALL

SELECT acct, balance
FROM debit
WHERE trandate = '31-DEC-95'
UNION
SELECT acct, balance
FROM credit
WHERE trandate = '31-DEC-95';

SELECT acct, balance
FROM debit
WHERE trandate = '31-DEC-95'
UNION ALL
SELECT acct, balance
FROM credit
WHERE trandate = '31-DEC-95';

7. An anti-join is used to return rows from a table that that are present in another table. It might be used for example between DEPT and EMP to return only those rows in DEPT that didn't join to anything in EMP;

Basic

SELECT *
FROM dept1
WHERE deptno
NOT IN (SELECT deptno FROM EMP1);

Intermediate

SELECT dept1.*
FROM dept1, emp1
WHERE dept1.deptno = emp1.deptno (+)
AND emp1.ROWID IS NULL;

Optimized quires

SELECT *
FROM dept1
WHERE NOT
EXISTS (SELECT NULL FROM emp1 WHERE emp1.deptno = dept1.deptno);

8. Put reserved words in upper case and application specific identifiers in lower case

IF TO_NUMBER(the_value) > 22
AND Num1 BETWEEN lval AND hval
THEN
Newval := 100;
ELSIF TO_NUMBER(the_value) < 1
THEN
Calc_tots (TO_DATE ('12-JAN-98'));
ELSE
Clear_vals;
END IF;

9. Use whitespace inside a statement

WHILE (total_sales < company_type =" 'NEW')">

10. DECLARE
Min_value NUMBER;
Company_id NUMBER:

Company_name VARCHAR2 (30);
Employee_name VARCHAR2 (60);

Hire_date DATE;
Termination_date DATE;

11. Gen_stats (company_id,
Last_year_date,
Rollup_type,
Total,
Average,
Variance,
Budgeted,
Next_year_plan);

12. Total_sales :=
Product_sales (company_id) +
Service_sales (company_id) admin_cutbacks * .5;

13. SELECT last_name, first_name
FROM employee
WHERE department_id = 15
AND hire_date <>

14. Not like that..

SELECT last_name,
C.name,
MAX (SH.salary) best_salary_ever
FROM employee E,
Company C,
Salary_history SH
WHERE E.company_id = C.company_id
AND E.employee_id = SH.employee_id
AND E.hire_date > ADD_MONTHS (SYSDATE, -60);

15. The readability of code by adding white space

  vFirstName := 'Roger';
  vLastName  := 'Smith';
  vSSN       := 999999999;
 
Not as
  vFirstName := 'Roger';
  vLastName := 'Smith';
  vSSN := 999999999;

**16.use parenthess patterns

IF (nSSN <>
     
  END IF;

Is much better than

IF nSSN <>
     
  END IF;

17. Align the IN and OUT keywords in columns

formatted

PROCEDURE Days_Between   (dStartDate   IN     date,
                          dEndDate     IN     date,
                          nGPA         IN OUT number,
                          nDaysBetween    OUT number)

un formatted

  PROCEDURE Days_Between (dStartDate IN date,
                          dEndDate IN date,
                          nGPA IN OUT number,
                          nDaysBetween OUT number)

18. When calling a procedure or function, align the parameters into a column. This reduces the visual clutter around the call, making it stand out from the rest of the code.

formatted

DaysBetween (dStartDate => dEnrolledDate,

               dEndDate     => dGraduationDate,
               nGPA         => nFinalGPA,
               nDaysBetween => nDuration);


un formatted

  DaysBetween (dStartDate => dEnrolledDate,
               dEndDate => dGraduationDate,
               nGPA => nFinalGPA,
               nDaysBetween => nDuration);

19. use mixed case for user-defined identifiers

vString
nBaseSalary
nGPA
iTardyDays
iClassNumber
lComments
rStudentPhoto

20. Code should always be indented consistently

  IF (some expression) THEN
     IF (some expression) THEN
        IF (some expression) THEN
           
        ELSIF (some expression) THEN
           
        END IF;
     END IF;
  END IF;

21. Statements following the WHEN clause of an exception handler should be indented five spaces, in order to create a column-like effect within the exception handler.

Formatted

  EXCEPTION
     WHEN OTHERS THEN
          DBMS_Output.Put_Line (SQLERRM);

Unformatted

  EXCEPTION
     WHEN OTHERS THEN
        DBMS_Output.Put_Line (SQLERRM);

22. Spaces should precede and follow character (') literals.Because easy to read and understablity.

  SELECT first_name || ' ' || middle_name || ' ' || last_name
         'student_name'
  FROM   STUDENTS
  WHERE  ssn = 999999999;

23. Do not leave any blank spaces preceding or following the ** operator.

  nRaisedNum := nNum**nPower;

24. Do not leave blank spaces before or after the plus (+) and minus (-) signs when used as unary operators.

  nNumber := -nSecondNumber;
  nNumber := +nSecondNumber;
 
25. Identifiers should always use mixed-case and capital letters to indicate separation of elements within an identifier. Thus, a variable of type varchar2 that holds a student’s first name would be    
           vStudentFirstName
            dStartDate
            nEmpnumber
 

26. The identifiers used for explicitly declared cursors should be meaningful; the suffix _cur should be appended to the identifier. For example:

CURSOR Students_cur
IS
SELECT first_name, middle_name, last_name, overall_gpa, most_recent_gpa
FROM   STUDENTS;

Identifiers declared using %TYPE should still include a datatype prefix as part of the identifier name:

nStudentSSN    STUDENTS.ssn%TYPE;
 

27. Do not add redundant bracketing

IF (x = 1) INCORRECT

IF ((x = 1) AND (y = 2)) INCORRECT

IF x = 1 AND y = 2 CORRECT

28. Use meaningful abbreviations for table and column aliases

SELECT cols

FROM employees emp

, companies com

, profiles pro

, sales sal

WHERE com.com_id = emp.emp_com_id

AND pro.pro_com_id = com.com_id

AND sal.sal_com_id (+)= pro.pro_com_id

optimization technique in sql & pl/sql


1

Code the query as simply as possible i.e. no unnecessary columns are selected (NOT USE SELECT * FROM TABLENAME)

2

Try to avoid operations on database objects referenced in the WHERE clause (refer analysis of quries in R&D folder)

3

Using a WHERE clause helps reduce overheads in sorting, summing rather than of HAVING clause

4

Minimize the number of table lookups (subquery blocks) in queries

5

Avoid joins that require the DISTINCT qualifier on the SELECT list in queries use EXISTS

6

use union all instead of union

7

Using Anti-join condition with NOT EXIST

8

Put reserved words in upper case and application specific identifiers in lower case

9

Use whitespace inside a control statements

10

Order your declarations consistently by using datatype defined

11

For Formatting Multiline Statements parameters are align in vertically

12

Align the remainder of the assignment after the assignment operator (using :)

13

Right-align the reserved word for the clauses against the DML statement

14

Don't skimp on the use of line separators

15

The readability of code by adding white space in declaration of variables and assign values.

16

Always use parentheses in expressions containing more than one identifier or literal. .

17

Align the IN and OUT keywords in columns for procedure and functions

18

When calling a procedure or function, align the parameters into a column

19

use mixed case for user-defined identifiers

20

Code should always be indented consistently (mutile if..elseif …endif …end)

21

Statements following the WHEN clause of an exception handler should be indented five spaces

22

Spaces should precede and follow character (') literals

23

Do not leave any blank spaces preceding or following the ** operator

24

Do not leave blank spaces before or after the plus (+) and minus (-) signs when used as unary operators.

25

Identifiers should always use mixed-case and capital letters to indicate separation of elements within an identifier(vEmployee)

26

The identifiers used for explicitly declared cursors should be meaningful and also %TYPE declaration should include the datatype prefix of the identifer name

27

Do not add redundant bracketting (single if condition)

28

Use meaningful abbreviations for table and column aliases

CHARACTER SET NLS

SQL> conn / as sysdba
select * from nls_database_parameters;
SHUTDOWN IMMEDIATE;
STARTUP RESTRICT;
ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
ALTER SYSTEM SET AQ_TM_PROCESSES=0;
ALTER DATABASE CHARACTER SET AR8MSWIN1256;



If the above fails:

SQL>ALTER DATABASE CHARACTER SET INTERNAL_USE WE8MSWIN1252;
SQL>SHUTDOWN IMMEDIATE;
SQL>STARTUP;