Best PL/SQL and SQL Tips To Read Before Interview
Before you go for your interview for the post of a Database Programmer, Please read these Useful PL/SQL and SQL Tips. Best PL/SQL and SQL Tips To Use When Working With Oracle Database.
1. Zero is a number and a Space is a character.
2. Character strings and date values are enclosed in single quotation marks.
3. Character values are case sensitive and date values are format sensitive.
4. The default date format is DD-MON-RR. Oracle database stores date in a format: Century, year, month, day, hours, minutes and seconds.
5. An Alias cannot be used in the WHERE clause.
6. The symbol ! = and ^= also represents to not equal to condition.
7. Values specified with the BETWEEN condition are inclusive.
8. The IN condition is also called membership condition.
9. The IN condition can be used with any data type.
10. A NULL value cannot be equal (=) or unequal to any value.
11. NULL values are displayed last for ascending sequences and first for descending
12. Column Alias can be used in the ORDER BY clause.
13. Sysdate is a function that does not contain any argument but return current database server date and time.
14. Database stores dates as Numbers, so arithmetic operators such as addition and subtraction can be performed on dates.
15. All Group Functions ignores null values. To substitutes a value for null values, use the NVL, NVL2, or COALESCE functions.
16. The oracle server implicitly sorts the result set in ascending order when using a “Group By” clause. To override this default ordering, DESC can be used in an “Order By” clause.
17. MIN and MAX functions can be used for any data type.
18. AVG, SUM, VARIANCE, and STDDEV functions can be used only with Numeric data types.
19. You cannot use a column alias in the GROUP BY clause.
20. All columns in the SELECT list that are not in group functions must be in the GROUP BY clause.
21. The GROUP BY column does not have to be in the SELECT list.
22. To restrict groups use HAVING clause not WHERE clause.
23. Don’t use Group functions in the Where clause.
24. Using the Table prefixes (alias) with the column names improves Performance, because it tells the oracle server exactly where to find the columns.It also helps to keep SQL code smaller, therefore using less memory.
25. A condition involving an Outer Join cannot use IN and OR operator.
26. The statement with the values clause adds only one row at a time to a table.
27. You can use a subquery in place of the table name in to INTO clause of the INSERT statement.
28. When creating a table by using a subquery, the integrity rules are not passed on to the new table, only the column data type definitions are passed.
29. When you add a new column in a table using ALTER command, than the new column become the last column in that table.
30. During modifying a column you can increase the width of a numeric or character column.
31. During modifying a column you can decrease the width of a column only if the column contains only null values or if the table has no rows.
32. During modifying a column you can change the data type only if the column contains null values
33. You can convert a CHAR column to the VARCHAR2 data type or convert a VARCHAR2 column to the CHAR data type only if the column contains null values or if you do not change the size.
34. A change to the default value of a column affects only subsequent insertions to the table.
35. Using the ALTER TABLE statement, only one column can be dropped at time and the table must have at least one column remaining in it after it is altered.
36. You can add a comment of up to 2000 bytes about a column, table, view or snapshot by using the COMMENT statement.
37. You can define any constraint at the Table level except NOT NULL which is defined only at column level.
38. Without the ON DELETE CASCADE or the ON DELETE SET NULL options, the Row in the parent table cannot be deleted if it is referenced in the child table.
39. You can add a NOT NULL constraint to an existing column by using the MODIFY clause of the ALTER TABLE statement.
40. You can define a NOT NULL column only if the table is empty or if the column has a value for every row
41. A View can be modifying by using the CREATE or REPLACE option.
42. When you drop a table, corresponding indexes are also dropped.
43. More Indexes on a table does not mean faster queries. Each DML operations that are committed on a table with indexes must be updated. The more indexes you have associated with a table, the more effort the oracle server must make to update all the indexes after a DML operation.
44. You cannot modify indexes. To change an Index, you must drop it and the recreates it.
45. If you drop a table, Indexes and Constraints are automatically dropped but Views and Sequences remains.
46. A user can have access to several Roles and several users can be assigned the same Role. Roles are typically created for database application.
47. An owner of a table can grant access to all users by using the PUBLIC keyword.
48. Privileges cannot be granted on remote objects.
49. PL/SQL Engine processes the entire PL/SQL block and filters out the SQL and procedural Statements separately, this reduces the amount of work that is sent to the oracle server and the number of memory cursors that are required.
50. PL/SQL code can be stored in oracle server as subprograms and can be referenced by any number of applications that are connected to the database.
51. In PL/SQL, an error is called an Exception.
52. If using NOT NULL or CONSTANT with variable declaration, you must assign a value to it.
53. To assign a value into a variable from a database, use SELECT or FETCH statements.
54.A slash (/) runs the PL/SQL block in a script file or in some tools such as iSQL*Plus.
55. DECODE and Group Functions (Avg, Sum, Min, Max, Count, Stddev, and Variance) are not available in procedural statements. They can be used in an SQL statement in a PL/SQL block.
56. An exception section can contain nested blocks.
57. The Scope of the identifier is that region of a program unit (block, subprogram, or package) from which you can reference the identifier.
58. PL/SQL does not directly support DDL statements such as Create, Alter, and Drop table.
59. PL/SQL does not directly support DCL statements such as GRANT and REVOKE.
60. PL/SQL supports DML (Insert, Update, and Delete) and Transaction control commands of SQL (Commit, Rollback, Savepoint)
61. Select statements within PL/SQL block must return one and only one row. A query that returns more than one row (TOO_MANY_ROWS) or no row (NO_DATA_FOUND) generates an error.
62. PL/SQL does not return an error if a DML statement does not affect any rows in the underlying table, however if a SELECT statement does not retrieve any rows PL/SQL returns an exception.
63. SQL%ISOPEN always evaluates to FALSE because PL/SQL closes the implicit cursors immediately after they are executed.
64. The PL/SQL program opens a cursor, processes rows returned by a query and then closes the cursor. The cursor makes the current position in the Active set.
65. Declare variables before the cursor declaration.
66. If the query returns no rows, no exception is raised.
67. You cannot reference cursor attributes directly in a SQL statement.
68. Before the first fetch %NOTFOUND evaluates to Null. So if Fetch never executes successfully, the Loop is never exited, that is because the EXIT WHEN statement. Executes only if it’s WHEN condition is true. To be safe, use the following EXIT statement: EXIT WHEN emp_cursor%NOTFOUND or emp_cursor%NOTFOUND is Null.
69. When the same cursor is referenced repeatedly we can pass parameters to the cursor. We can also use cursor for loop with parameters.
70. A block always terminates when PL/SQL raises an exception.
71. Exception cannot appear in assignment statements or SQL statements.
72. You cannot use SQLCODE and SQLERRM directly in a SQL statement. Instead, you must assign their values to local variables, and then use the variables in the SQL statement.
73. The keyword DECLARE that is used to indicate the starting of the declaration section in anonymous blocks is not used with the subprograms (Procedures or functions).
74. There must be at least one statement existing in the executable section, there must be atleast A NULL statement that is considered an executable statement.
75. You cannot reference host or bind variables in the PL/SQL block of a stored Procedure. 76. You cannot restrict the size of the data type in the parameters of the subprograms.
77. You must declare the subprogram in the declaration section of the block and must be the last item after all the other program items. For example: A variable declared after the end of the subprogram, before the begin of the procedure, will cause the compilation error.
78. A Function must have a Return Clause in the Header and at least one Return Statement in the executable section.
79. Return data type in function declaration must not include a size specification.
80. You cannot reference host or bind variables in the PL/SQL block of a stored Function.
81. Although multiple Return statements are allowed in a function (usually within an IF statement) only one Return statement is executed.
82. It is a good programming practice to assign a return value to a variable and use a single return Statement in the executable section of the code. There can be a return statement in the exception Section of the program also.
83. A Function may accept one or many parameter, but must return a single value.
84. Although the three parameters modes (IN, OUT, INOUT) can be used with any subprogram, avoid Using the OUT and INOUT modes with Functions.
85. Anywhere a built-in function can be placed, a user-defined function can be placed as well.
86. Only stored functions are callable from SQL statements. Stored Procedures cannot be called.
87. Functions that are callable from SQL expressions cannot contain OUT and INOUT parameters, other functions can contain parameters wit these modes but it is not recommended.
88. A Procedure containing one OUT Parameter can rewritten as a function containing a RETURN Statement.
89. Package cannot be invoked, parameterized or nested.
90. Package Specification and Body are stored separately in the database but must have the same name.
91. Define the Package Specification before the Body.
92. A Package Specification can exist without a package Body, but a package Body cannot exist without a package Specification.
93. It is quite common in the package body to see all private variables and subprograms defined first and the public subprograms defined last.
94. If a Specification declares only types, constants, variables, exceptions and call specifications, the package body is unnecessary. However, the body can still be used to initialize items declared in the package specification.
95. Changes to the package specification require recompilation of each referencing subprogram. So place few construct as possible in a package specification.
96. Only local or packaged subprograms can be overloaded. You cannot overload stand-alone.
97. Most built-in functions are overloaded. For ex: TO_CHAR function of standard package.
98. PL/SQL does not allow forward references; you must declare an identifier before using it. Therefore, a program must be declared before calling it.
99. The excessive use of Triggers can result in complex inter-dependencies, which may be difficult to maintain in large applications. Only use Triggers when necessary and beware of recursive and cascading effects.
100. If the logic for the Trigger is very lengthy, create stored procedures with the logic and invoke them in the Trigger body using CALL statement. There is no semicolon at the end of call statement.
101. Note that database triggers fire for every user each time the event occurs for which the Trigger is created.
102. The size of a Trigger cannot be more than 32K.
103. Using column names along with the Update clause in the Trigger improves performance, because the Trigger fires only when the particular column is updated and thus avoids unintended firing when any other column is updated.
104. You can combine several Triggering events into one by taking advantage of a special conditional predicates INSERTING, UPDATING, DELETING with the Trigger body.
105. The OLD and NEW qualifiers are available only in ROW Triggers and prefix these qualifiers with a colon (:) in every SQL and PL/SQL statement.
106. There is no colon (:) prefix if the qualifiers are referenced in the WHEN restricting ROW Trigger can decrease the performance if you do a lot of updates on larger tables.
107. When you specify ON SCHEMA, the Trigger fires for the specific user, if you specify ON DATABASE, the Trigger fires for all users. 108. A Table is not considered Mutating for statement Triggers.
109. Statements in the Trigger Body operate under the privilege of the Trigger owner, not the Trigger user.
110. If the Package body changes and the Package specification does not changes, the stand-alone Procedure referencing a package construct remains valid.
111. If the package specification changes, the outside procedure referencing a package construct is invalidated, as is the package body.
112. If a Stand-alone procedure referenced within the package changes, the entire package body is invalidated, but the package specification remains valid. Therefore, it is recommended that you bring the procedure into the package.
113. Dynamic SQL supports all the SQL data types but does not supports PL/SQL specific types except PL/SQL record.
114. You can use the INTO clause for a single-row query, but you must use OPEN-FOR, FETCH and CLOSE for a multi row query.
115. The oracle 9i server performs implicit conversion between CLOB and VARCHAR2 data types. The other implicit conversions between LOB’s are not possible. Foe ex: if the user creates a table T with a CLOB column and a table S with a BLOB column, the data is not directly transferable between these two columns.
ALSO READhttp://techhowdy.com/best-plsql-sql-tips-read-interview/http://techhowdy.com/wp-content/uploads/2017/11/Oracle-11g-PLSQL.pnghttp://techhowdy.com/wp-content/uploads/2017/11/Oracle-11g-PLSQL-150x150.pngDatabase Programmingadvanced pl sql tips,best pl sql tips,oracle pl sql performance tips,oracle pl sql tips and techniques,oracle pl sql tips and tricks pdf,oracle pl/sql tips and techniques pdf,pl sql coding tips,pl sql decode tips,pl sql developer tips,pl sql developer tips and tricks,pl sql developer tips tricks,pl sql developer tool tips,pl sql optimization tips,pl sql performance tips,pl sql programming tips,pl sql query tuning tips,pl sql tips and tricks,pl sql tips for performance,pl sql tuning tips,pl sql tuning tips for oracle,pl/sql performance tuning tips in oracle,tips for pl sql developers,tips in pl/sql,tips pl sql oracle,top twenty pl/sql tips and techniquesBefore you go for your interview for the post of a Database Programmer, Please read these Useful PL/SQL and SQL Tips. Best PL/SQL and SQL Tips To Use When Working With Oracle Database. 1. Zero is a number and a Space is a character. 2. Character strings and date values are enclosed in...DemonLyoid Lopeslyoid_lopes@yahoo.comAdministratorHi there, I am Lyoid Lopes. Internet Marketer and Blog writer. I am Software Engineering Technology graduate from Centennial College Canada. In Techhowdy I publish new technology news every day. You can reach me Facebook, Twitter and Google +TechHowdy