Showing posts with label main-page. Show all posts
Showing posts with label main-page. Show all posts

23 August, 2015

Oracle | Keywords | GROUP BY, ROLLUP and CUBE

This article is for knowing how some of the keywords in Oracle work:

1. GROUP BY - Group by clause allows us to group the data based on a column or a combination of columns. The main benefit of using this keyword is when we have to get the aggregated data.
Ex - We have to find the total number of employees working in different departments. The following query can be used for this.
SELECT dept_id, COUNT(emp_id) 
FROM department d, employee e 
WHERE e.dept_id = d.dept_id 
GROUP BY dept_id 
The same way we can use group by to get the sum or average of the salaries of different departments.
 

25 July, 2015

Oracle PL SQL | Pending Questions

1. The validity of a package depends upon the validity of the other database objects it references to; So if we try to create 2 packages which have dependency on each other, then how will that contention be resolved?

08 July, 2015

Oracle Collections : Introduction

A collection is an ordered group of elements which have the same data type and we use subscripts to actually access those elements.

There are three types of collections provided by Oracle:

  1. Index-by Tables / Associative Arrays
  2. Nested Table
  3. Variable size array / Varray

Index by Table / Associative Array
Each stored data unit is in the form of KEY-VALUE pair. The keys are unique and it can be either a string or an integer.

TYPE type_name IS TABLE OF element_type [NOT NULL] INDEX BY sucscript_type;

table_name type_name;

Below is an example showing how to use associatibe array:

TYPE salary IS TABLE OF NUMBER INDEX BY varchar2(20);
salary_list salary;

--Adding elements to this ass. array

salary_list('ram') = 15000;
salary_list('lakshman') = 7050;
salary_list('bharat') = 35000;
salary_list('shatrugan') = 5000;

--Now using the collection elements

name := salary_list.FIRST;
WHILE name IS NOT NULL LOOP
DBMS_OUTPUT.PUT_LINE ('Salary of '||name||' is '||TO_CHAR(salary_list(name));

name := salary_list.NEXT(name);


END LOOP;

END;
/

Elements of a index-by table can be %ROWTYPE data of a database table; or it could be %TYPE of a single column of the table.


NESTED TABLES

Its like a one-dimensional array where the elements are stored with their subscript. 
But its not conventional type of array as the no. of elements in the nested table is unbound compared to normal array. And its also not as dense as arrays are because the elements keep on changing making it sparse.

The syntax of nested tables is similar to that of the index-by collection except the fact that nested tables do not use INDEX BY clause.

Nested tables can be stored in the database tables where as index-by doesn't.

01 July, 2015

PLSQL Interview Questions | Second Set

1. Is it possible to Auto-Refresh the Materialize View?

Yes it is possible. During declaration, you can specify the auto refresh interval of the mview.

Sol:The DBMS_MVIEW package contains three APIs for performing refresh operations: 
•DBMS_MVIEW.REFRESH 
Refresh one or more materialized views. 
•DBMS_MVIEW.REFRESH_ALL_MVIEWS 
Refresh all materialized views. 
•DBMS_MVIEW.REFRESH_DEPENDENT 
Refresh all materialized views that depend on a specified master table or materialized view or list of master tables or materialized views. 
 CREATE materialized VIEW yarpno_mv 2 refresh fast 3 NEXT trunc(sysdate+1) 4 AS SELECT * FROM yarpno; 

2. Explain diff. types of Indexes? Which one is fasted?
(IBM) 

3. How to send mails multiple customers in a single select query?(Bahwan Cyber Tech) sol : UTL_SMTP , UTL_MAIL 

4. Explain about Nonralization.(Polaris) 

6. What is passed by value & passed by reference? explain with example.(Bahwan Cyber Tech) 

7. What is Direct Path Loader?(IBM) 

8. Diff. between Direct Path Loader vs Conventional Path Loader?(IBM) 

9. Sql loader is for upload or download or both?(LNT) 

10. How to load other than csv file? (iGATE) 

11. How to skip a column in sql loader?(IBM) 

12. DML operations inside the exception handling path ( when others then) is possible? Explain.(Polaris) 

13. What i & g mean by in Oracle versions? (DNB-Dun & Broadstreet) 

14. what are diff. in 10g & 11g? (RAMCO) 

15. what is diff. between cursor & ref cursor? (LNT) 

16. what is diff. between nested table & varray?(iGATE) Greens Technology’s Contact :-9840496320 

17. what is diff. between ref cursor & bulk collect?(Bahwan Cyber Tech) 

18. What is global cursor? (CTS) 

19. what will happen when we use COMMIT in Trigger? (Polaris) 

20. How many number of triggers possible? (LNT) 

21. HOW TO SEE INVALID INDEXES?HOW TO REBUILD INVALID INDEXES USING PL/SQL BLOCK?(Polaris) 

22. TELL ME ABOUT BULK_COLLECT & BULK_BIND.(Bahwan Cyber Tech) 

23. WHAT IS DIFF B/W NOT EXITS & MINUS?(IBM) 

24. What is the physical and logical structure of oracle?(Polaris) 

25. how can u open multiple files in Unix is it possible? 

26. Created procedure has 5 parameters if the same procedure is called with 3 parameters will it work? What is the error will it give? (hexaware) 

27. What is pragma EXCEPTIO_INIT_?(Polaris) 

28. HOW TO COUNT NO OF RECORDS IN TABLE WITHOUT COUNT?(Bahwan Cyber Tech) 

29. HOW TO RETRIVE TOP 3 SALARIES FROM EACH DEPARTMENTS?(IBM) 

30. WHAT IS CONTEXT SWITHCING?(TCS) 

31. WHAT IS BULKCOLLECT? AND ANY RESTRICTIONS IN BULKCOLLECT?(iGATE) 

32. WHAT IS FUNCTIONAL BASED INDEX? WRITE SYNTAX? 

33. CAN YOU ALTER PROCEDURE WITH IN PACKAGE?(iGATE) 

34. IS IT POSSIBLE TO OPEN CURSOR WHICH IS IN PACKAGE IN ANOTHER PROCRDURE?(Polaris) 

35. DIFFERENCE BETWEEN CASE AND DECODE?(iGATE) 

36. CAN YOU USE SYSDATE IN CHECK CONSTRAINTS? IF NO, WHY?(hexaware) 

37. TELL ME SOME IMPORTANT ORACLE 11G FEATURES?(Bahwan Cyber Tech) 

38. IF TABLE DROPPED, THEN WHAT HAPPEN VIEW?(hexaware) 

39. WHICH FUNCTIONS ARE NOT SUPPORTED TO INDEX?(hexaware) 

40. WHAT ARE THE DATATYPES AVILABLE IN PL/SQL, NOT IN SQL? 

41. DIFF B/W EXPLICT CURSOR & FOR LOOP CURSOR?(Polaris) 

42. WHAT IS RAISE_APPLICATION_ERROR?EXPLAIN(IBM) 

43. HOW CAN YOU CALL PROCEDURE IN SELECT STATEMENT?(hexaware) 

44. HOW TO DROP PACKAGE BODY ONLY? 

45. What is the disadvantage of package?(Bahwan Cyber Tech) 

46. CAN USE PRAGMA_AUTONAMOUS_TRANCTIONS IN PACKAGES? 

47. HOW TO DEBUGG YOUR CODE? 

48. How will you move the cursor with out using arrow keys in vi editor in UNIX? 

49. What is grep in UNIX? (Polaris) 

50. How you get latest processed record in unix?(Polaris) 

51. Write a script for check a file if it is available or no If available rename it(unix). 

52. What is inode and explain it (unix)(Polaris) 

53. Write a correlated sub query and explain how it works.(hexaware) 

54. What are different type of triggers? 

55. Write a pl/sql block for trigger at the time of insertion for inserting old and new values in auditing table?(Bahwan Cyber Tech) 

56. If we have both user exception and system exception, which will be handled first? 

57. How to access table from another database? 

58. If I gave a select statement, it contains null data; I gave NO_DATA_FOUND AND OTHERS in exception block? What exception will handles and that procedure compiled or not? It will not compiled why because no choice appear with choice others in exception handler. 

59. How u know whether a table is locked or not?(unix)(Polaris) 

60. How you know what are the preveliges you have? 

61.Is it possible for "two objects have the same name"? 

62. Can you see dba tables? 

63. What is cluster? 

64. What is dual ? can we truncate it ? 

65. What is the difference between truncate and delete? 

66. What is the difference between drop and delete?w 

67. what is explain plan? explain?(IBM) 

68. what is dbms_profiler? what are the uses.explin? 

69. explain the steps you worked with the performance tunning. 

70. what are the stepls for table partioning? explain? 

71. is it composite primary key possilbe? if yes how give example. 

72. what is the diff. between plsql table & record? 

73. Is it possilbe to create index automatically?if yes explain what and how? 

74. how you create views without base table? 

75. what is .bad file? 

76. what is the result for the query - SELECT 'A' FROM DUAL INTERSECT SELECT NULL FROM DUAL; 

77. HOW you pass parameters into package? 

78. To where you use execute immediate? what is the use of it? 

79. is it possible to use Continue statement is in PL/SQL loops? 

80. How many primary key you can use in a table? 

81. What are Difference between WHERE & HAVING? 

83. What is the difference between the cursor declared in the procedure and cursor declared in the package?

PL/SQL Interview Questions | First Set

PL/SQL is an advance version of SQL. There are given top list of PL/SQL interview questions with answer.

1) What is PL/SQL?
PL/SQL stands for procedural language extension to SQL. It supports procedural features of programming language and SQL both. It was developed by Oracle Corporation in early of 90's to enhance the capabilities of SQL.

2) What is PL/SQL table? Why it is used?
Objects of type tables are called PL/SQL tables that are modeled as database table. They are a type of COLLECTION. They were initially introduced in pl/sql. Nested tables are Varrays were introduced only after Oracle 8i.
We can also say that PL/SQL tables are a way to provide arrays. Arrays are like temporary tables in memory that are processed very quickly. PL/SQL tables are used to move bulk data. They simplifies moving collections of data.

3) What are the datatypes available in PL/SQL?
There are two types of datatypes in PL/SQL:
1.    Scalar datatypes Example are NUMBER, VARCHAR2, DATE, CHAR, LONG, BOOLEAN etc.
2.    Composite datatypes Example are RECORD, TABLE etc.

4) What is the basic structure of PL/SQL?
PL/SQL uses BLOCK structure as its basic structure. Each PL/SQL program consists of SQL and PL/SQL statement which form a PL/SQL block.
PL/SQL block contains 3 sections.
1.    The Declaration Section (optional)
2.    The Execution Section (mandatory)
3.    The Exception handling Section (optional)

5) What is the difference between FUNCTION, PROCEDURE AND PACKAGE in PL/SQL?
Function: The main purpose of a PL/SQL function is generally to compute and return a single value. A function has a return type in its specification and must return a value specified in that type.
Procedure: A procedure does not have a return type and should not return any value but it can have a return statement that simply stops its execution and returns to the caller. A procedure is used to return multiple values otherwise it is generally similar to a function.
Package: A package is schema object which groups logically related PL/SQL types , items and subprograms. You can also say that it is a group of functions, procedure, variables and record type statement. It provides modularity, due to this facility it aids application development. It is used to hide information from unauthorized users.

6) What is exception? What are the types of exceptions?
Exception is an error handling part of PL/SQL. There are two type of exceptions: pre_defined exception and user_defined exception.

7) How exception is different from error?
Whenever an Error occurs Exception arises. Error is a bug whereas exception is a warning or error condition.

8) What is the main reason behind using an index?
Faster access of data blocks in the table.

9) What are PL/SQL exceptions? Tell me any three.
1.    Too_many_rows
2.    No_Data_Found
3.    Value_error
4.    Zero_error etc.

10) What is the maximum number of triggers, you can apply on a single table?
12 triggers.

11) How many types of triggers exist in PL/SQL?
There are 12 types of triggers in PL/SQL that contains the combination of BEFORE, AFTER, ROW, TABLE, INSERT, UPDATE, DELETE and ALL keywords.
·         BEFORE ALL ROW INSERT
·         AFTER ALL ROW INSERT
·         BEFORE INSERT
·         AFTER INSERT etc.

12) What is stored Procedure?
A stored procedure is a sequence of statement or a named PL/SQL block which performs one or more specific functions. It is similar to a procedure in other programming languages. It is stored in the database and can be repeatedly executed. It is stored as schema object. It can be nested, invoked and parameterized.

13) How to execute a stored procedure?
There are two way to execute a stored procedure.
From the SQL prompt, write EXECUTE or EXEC followed by procedure_name.

1.    EXECUTE or [EXEC] procedure_name;

Simply use the procedure name

1.    procedure_name;


14) What are the advantages of stored procedure?
Modularity, extensibility, reusability, Maintainability and one time compilation.

15) What are the cursor attributes used in PL/SQL?
%ISOPEN: it checks whether the cursor is open or not.
%ROWCOUNT: returns the number of rows affected by DML operations: INSERT,DELETE,UPDATE,SELECT.
%FOUND: it checks whether cursor has fetched any row. If yes - TRUE.
%NOTFOUND: it checks whether cursor has fetched any row. If no - TRUE.

16) What is consistency?
Consistency simply means that each user sees the consistent view of the data.
Consider an example: there are two users A and B. A transfers money to B's account. Here the changes are updated in A's account (debit) but until it will be updated to B's account (credit), till then other users can't see the debit of A's account. After the debit of A and credit of B, one can see the updates. That?s consistency.

17) What is cursor and why it is required?
A cursor is a temporary work area created in a system memory when an SQL statement is executed.
A cursor contains information on a select statement and the row of data accessed by it. This temporary work area stores the data retrieved from the database and manipulate this data. A cursor can hold more than one row, but can process only one row at a time. Cursor are required to process rows individually for queries.

18) How many types of cursors are available in PL/SQL?
There are two types of cursors in PL/SQL.
1.    Implicit cursor, and

2.    explicit cursor

27 June, 2015

PLSQL NOTES : INTRODUCTION

This is my personal blog for notes taking around the area of Oracle. The content present here is data from my personal viewpoint and might not be valid for any other person.

Please use this information wisely!!!


-By Author and Creator.