Monday, July 15, 2013

SQL Query

Displaying the sum total salaries of employees per department for a particular year

SQL> select *
2 from (select department_id, to_char(trunc(hire_date, 'YYYY'), 'YYYY')
hire_date, salary
3 from employee)
4 PIVOT (SUM(salary)
5 FOR (department_id, hire_date) IN
6 ((10, '2007') AS Accounting_2007,
7 (20, '2008') AS Payroll_2008,
8 (30, '2010') AS IT_2010
9 )
10 );
ACCOUNTING_2007                  PAYROLL_2008             IT_2010
—————————           ————————      ——————————————
190000                                                     90000                        370000
1 row selected.

Pivoting on and displaying multiple aggregate columns

SQL> select *
2 from (select department_id, hire_date, salary
3 from employee)
4 PIVOT (SUM(salary) AS sals,
5 MAX(hire_date) AS latest_hire
6 FOR department_id IN (10, 20, 30, NULL));
10_SALS  10_LATEST  20_SALS 20_LATEST 30_SALS 30_LATEST NULL_SALS NULL_LATE

370000 07-JUL-11 155000 06-MAR-09 370000 27-FEB-10 75000 14-SEP-05


Creating a table with pivoted data


SQL> CREATE TABLE pivoted_emp_data AS
2 select *
3 from (select department_id, hire_date, salary
4 from employee)
5 PIVOT (SUM(salary) sum_sals,
6 MAX(hire_date) latest_hire
7 FOR department_id IN (10 AS Acc, 20 AS Pay, 30 AS IT, NULL));

Using the UNPIVOT operator to turn rows into columns
SQL> select hire_date, salary
2 from pivoted_emp_data
3 UNPIVOT INCLUDE NULLS
4 ((hire_date, salary)
5 FOR department_id IN (
6 (acc_latest_hire, acc_sum_sals) AS 'Accounting',
7 (pay_latest_hire, pay_sum_sals) AS 'Payroll',
8 (it_latest_hire, it_sum_sals) AS 'IT',
9 (null_latest_hire, null_sum_sals) AS 'Unassigned'
10 ))
11 order by hire_date, salary;
HIRE_DATE SALARY
———————————————— ———————————
14-SEP-05 75000
06-MAR-09 155000
27-FEB-10 370000
07-JUL-11 370000
4 rows selected.

Log information for external table creation

CREATE TABLE statement
CREATE TABLE "SYS_SQLLDR_X_EXT_T"
(
"PATIENT_NAME" VARCHAR2(30),
"V_YYYY" VARCHAR2(255), "V_MM" VARCHAR2(255),
"V_DD" VARCHAR2(255), "V_HH" VARCHAR2(255),
"V_MI" VARCHAR2(255), "V_SS" VARCHAR2(255),
"SERVICE_DATE" VARCHAR(4000)
)
ORGANIZATION external
(
TYPE oracle_loader
DEFAULT DIRECTORY MY_DIR
ACCESS PARAMETERS
( RECORDS DELIMITED BY NEWLINE CHARACTERSET US7ASCII
BADFILE 'MY_DIR':'t.bad'
LOGFILE 't.log_xt' READSIZE 1048576
FIELDS TERMINATED BY "," LDRTRIM
MISSING FIELD VALUES ARE NULL
REJECT ROWS WITH ALL NULL FIELDS
( "PATIENT_NAME" CHAR(255) TERMINATED BY ",",
"V_YYYY" CHAR(255) TERMINATED BY ",",
"V_MM" CHAR(255) TERMINATED BY ",",
"V_DD" CHAR(255) TERMINATED BY ",",
"V_HH" CHAR(255) TERMINATED BY ",",
"V_MI" CHAR(255) TERMINATED BY ",",
"V_SS" CHAR(255) TERMINATED BY ",",
"SERVICE_DATE" CHAR(255) TERMINATED BY ","
)
) location('t.dat')
)REJECT LIMIT UNLIMITED
INSERT AS SELECT statement
INSERT /*+ append */ INTO T
(
PATIENT_NAME,
SERVICE_DATE
)
SELECT
"PATIENT_NAME",
to_date("V_YYYY" || "V_MM" || "V_DD" || "V_HH" || "V_MI" || "V_SS" ,
'YYYYMMDDHH24MISS')
FROM "SYS_SQLLDR_X_EXT_T"

Using the PIVOT function to obtain cross-tabular results

 Using the PIVOT function to obtain cross-tabular results
SQL> select *
2 from (select department_id, salary
3 from employee) total_department_sals
4 PIVOT (SUM(salary)
5 FOR department_id IN (10 AS Accounting, 20 AS Payroll, 30 AS IT,
6 NULL AS Unassigned_Department));
ACCOUNTING        PAYROLL                IT                       UNASSIGNED_DEPARTMENT

370000                          155000               370000                                 75000
1 row selected.

Oracle Reports interviews ques. & answer



Oracle Reports interviews ques. & answer

1.
What are the different file extensions that are created by oracle reports?

Rep file and Rdf file.

2.
From which designation is it preferred to send the output to the printed?

Previewer.

3.
Is it possible to disable the parameter from while running the report?

Yes

4.
What is lexical reference?How can it be created?

Lexical reference is place_holder for text that can be embedded in a sql statements.A lexical reference can be created using & before the column or parameter name.

5.
What is bind reference and how can it carate?

Bind reference are used to replace the single value in sql,pl/sql statements a bind reference can be careated using a (:) before a column or a parameter name.

6.
What use of command line parameter cmd file?

It is a command line argument that allows you to specify a file that contain a set of arguments for r20run.

7.
Where is a procedure return in an external pl/sql library executed at the client or at the server?

At the client.

8.
Where is the external query executed at the client or the server?

At the server.

9.
What are the default parameter that appear at run time in the parameter screen?

Destype and Desname.

10.
Which parameter can be used to set read level consistency across multiple queries?

Read only.

11.
What is term?

The term is terminal definition file that describes the terminal form which you are using r20run.

12.
What is use of term?

The term file which key is correspond to which oracle report functions.

13.
Is it possible to insert comments into sql statements return in the data model editor?

Yes.

14.
If the maximum record retrieved property of the query is set to 10 then a summary value will be calculated?

Only for 10 records.

15.
What are the sql clauses supported in the link property sheet?

Where startwith having.

16.
To execute row from being displayed that still use column in the row which property can be used?

Format trigger.

17.
Is it possible to set a filter condition in a cross product group in matrix reports?

No.

18.
If a break order is set on a column would it effect columns which are under the column?

No.

19.
With which function of summary item is the compute at options required?

percentage of total functions.

20.
What is the purpose of the product order option in the column property sheet?

To specify the order of individual group evaluation in a cross products.

21.
Can a formula column be obtained through a select statement?

Yes.

22.
Can a formula column refered to columns in higher group?

Yes.

23.
How can a break order be created on a column in an existing group?

By dragging the column outside the group.

24.
What are the types of calculated columns available?

Summary, Formula, Placeholder column.

25.
What is the use of place holder column?

A placeholder column is used to hold a calculated values at a specified place rather than allowing is to appear in the actual row where it has to appeared.

26.
What is the use of hidden column?

A hidden column is used to when a column has to embedded into boilerplate text.

27.
What is the use of break group?

A break group is used to display one record for one group ones.While multiple related records in other group can be displayed.

28..
If two groups are not linked in the data model editor, what is the hierarchy between them?

Two group that is above are the left most rank higher than the group that is to right or below it.

29.
The join defined by the default data link is an outer join yes or no?

Yes.

30.
How can a text file be attached to a report while creating in the report writer?

By using the link file property in the layout boiler plate property sheet.

31.
Can a repeating frame be careated without a data group as a base?

No.

32.
Can a field be used in a report wihtout it appearing in any data group?

Yes.

33.
For a field in a repeating frame, can the source come from the column which does not exist in the data group which forms the base for the frame?

Yes.

34.
Is it possible to center an object horizontally in a repeating frame that has a variable horizontal size?

Yes.

35.
If yes,how?

By the use anchors.
36.
What are the two repeating frame always associated with matrix object?

One down repeating frame below one across repeating frame.

37.
Is it possible to split the printpreviewer into more than one region?

Yes.

38.
Does a grouping done for objects in the layout editor affect the grouping done in the datamodel editor?

No.

39.
How can a square be drawn in the layout editor of the report writer?

By using the rectangle tool while pressing the (Constraint) key.

40.
To display the page no. for each page on a report what would be the source & logical page no. or & of physical page no.?

& physical page no.

41.
What does the term panel refer to with regard to pages?

A panel is the no. of physical pages needed to print one logical page.

42.
What is an anchoring object & what is its use?

An anchoring object is a print condition object which used to explicitly or implicitly anchor other objects to itself.

43.
What is a physical page? & what is a logical page?

A physical page is a size of a page. That is output by the printer. The logical page is the size of one page of the actual report as seen in the Previewer.

44.
What is the frame & repeating frame?

A frame is a holder for a group of fields. A repeating frame is used to display a set of records when the no. of records that are to displayed is not known before.