Вы находитесь на странице: 1из 9

----------------------------- SQL - Basics ---------------------------------------1. how to do a full outer join in Oracle. - TABLE A FULL OUTER JOIN TABLE B 2.

What is the difference between a cartesian product and full outer join. - Cartisian Product - M x N records - Full outer join - M + N records 3. What is merge do? - Does an upsert (update/insert) operation. 4. How to spool output to a file without the having page breaks - SET PAGESIZE 0 ----------------------------- PL/SQL Basics ---------------------------------------5. Difference between a function and procedure - Function can be used in a expression where as procedurs can't. An experienceed developer would tell this as a difference rather than a fun ction returns a value and a procedure doesn't 6. Can we have a commit within a function? - yes 7. What are the types of parameters for a function/procedure - In, In Out, Out 8. Which of the parameters are pass by reference and pass by value - IN - Reference - You can modify the parameter value within the code block a s they are with reference. - In out, out - Pass by value 9. What is the advantages of packages - Function overloading - Performance (provided they are designed correctly). The entire code is load ed to memory. 10. If a variable is declared in the package spec, how does it behave in multipl e sessions. Makarand : If value being assigned to pkg variable..the value set to persist thr ought the session. Other session also use assign values to the variable and do further operarion and maintain thee values till the end of that session. NIhar : A variable declared in package spec keeps its one version and a values a ssigned to it in one session will not be relfected in other sessions. 11. Type of triggers. - Row level and statement level triggers http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/triggers.htm#i201 3 Row Triggers and Statement Triggers BEFORE and AFTER Triggers INSTEAD OF Triggers Triggers on System Events and User Events 12. Can a same table have both statement level and row level before insert trigg er

- Yes 13. order of execution of triggers BEFORE statement trigger Before executing the triggering statement, the trigger action is run. BEFORE row trigger Before modifying each row affected by the triggering statement and before checki ng appropriate integrity constraints, the trigger action is run, if the trigger restriction was not violated. AFTER statement trigger After executing the triggering statement and applying any deferred integrity con straints, the trigger action is run. AFTER row trigger After modifying each row affected by the triggering statement and possibly apply ing appropriate integrity constraints, the trigger action is run for the current row provided the trigger restriction was not violated. Unlike BEFORE row trigge rs, AFTER row triggers lock rows. 14. Can a table have 2 before insert row level triggers - yes 15. What is the order of execution of above question. - Prior to 11g, it can't be predictd/controlled. 16. Can we put a commit inside a trigger - No, but with autonomous transaction you can. 17. What are mutating triggers - When a row level trigger updates the values on the same table. 18. How to avoid MT? - Make the trigger autonomous - Convert to statement level triggers - Use of temporary tables. 19. What are autonomous transactions? Autonomous transactions are independent trasanction which will be initated fromt the parent transaction or session and any COMMIT or ROLLBACKS will not affect t he parent session will only be confined to the autonomous transaction block 20. What are cursors Name for private sql area in which info for processing specific statement is kep t.The cursor is declared on set of rows for sql data manupulation statements. Cursors a PLSQL data sets which when executed on a SQL get all the all the data in PLSQL space and further make it possib le to loop through each of the rowseti n the cursor.

Every SQL statement executed by the RDBMS has a private SQL area that contains i nformation about the SQL statement and the set of data returned. In PL/SQL, a cu rsor is a name assigned to a specific private SQL area for a specific SQL statem ent 21. Steps in using an explicit cursor DECLARE OPEN FETCH CLOSE 22. Which step in the explicit cursor fetches values from the table FETCH. 21. What does open do? Create memory area for the cursor 22. What is the difference between cursor and ref cursor In case of an normal explict cursor, the SQL query has to be defined at the time of declaring the cursor itself. In case of REF Cursor, the cursor declartion i s not associated with any SQL query, it is associated with a query at a later st age this brings in a lot of flexibility as different SQL queries can be associat ed with the cursor (one at a time, offcourse) programatically. REF Cursors also provide the feature of passing parameters. Though there is something dynamic w ith REF Cursor when compared to a normal explicit cursor, it is not a truly perf ect dynamic cursor. Truly perfect dynamic cursors are the one constructed using DBMS_SQL package. 23. What are the types of ref cursor - Strongly type - declare the structure at the time of defining - Weak ref cursor - structure is flexible 24. Difference between VARRAY and Pl/SQL Table PL/SQL tables are temporary array like objects used in a PL/SQL Block. The size of pl/sql table is unconstrained. For varrays we need to specify upperbound. Pl/sql tables can not be stored in database where as varrays can be stored in da tabase. We can use negetive index for pl/sql tables. In varrays negetive index is not al lowed. In pl/sql tables data need not be stored in consecutive rows. Varrays are dense and retain their order while storing in database. You can not perform DML operations on PL/SQL table . DML operations can be perfo rmed on Varrays. pl/sql tables cannot be stored in db whereas varrays can be stored. no dml for pl/sql table but dml can be performed on varrays pl/sql tables are temporary array like objects and size is unconstrained where v array ned to specify upperbound. 25. What does BULK collect do? The BULK COLLECT retrieves the data from the dynamic cursor or REF cursor and st ores it into a PLSQL tables type in one shot. 26. What is the use of NOCOPY hint for a parameter to a procedure/function

The NOCOPY hint always passes the VARIABLE values by reference to the porcedure or function so that the copiler need not cpy the variable value each time callin g the procedure 27. What is the most common exceptions that you have handled. NO_DATA_FOUND, TOO_MANY_VALUES, DUP_VAL_ON_INDEX, INDEX_OUT_OF_BOUNDS when others when no_data_found when too_many_rows zero_divide invalid_number 28. What are the parameters for RAISE_APPLICATION_ERROR 3 Parameters RAISE_APPLICATION_ERROR(-20000,'Organization ' TO_CHAR(p_company_id) ' already exists.'); error number message The user error maessage number and the user defined error message 29. What happens when you hit RAISE_APPLICATION_ERROR - The transaction is rolled back. 30. How to attach a name to a predefined error code PRAGMA EXCEPTION INIT ----------------------------- SQL - DDL ---------------------------------------31. What is use of global temporary table? a GLOBAL temporary table willno t have a memory block assigne dto it until runti me or until when the data is inserted into it and it uses the temporaray tablesp ace. The data in a GT table is persistent until the session and each session can have its own version of the GT table where the data stored by one session will not visible to the other sessions. to improve the speed of queries that perform complex summarization activities. if the results of large number of processing rows are not required when the curr ent session ended then use GTT The data is not persistent in GTT and these tables generate no redo and rollback info. 32. What is index organized tables? it is table that is sorted internaly as an index thus combines a table and index in one, saving you the effort of creating an index IOT tables are oraganized by BTree indexes 33. What are types of indexes? BTree, Bitmap and funtion based indexes

B-Tree Botmap function based partitioned domain 34. Disadvantage of bitmap indexes. Maintanance as these indexes dont get refreshed automatically once a DML is perf ormed hence need to rebuilt again after a mass dml is perfoemd Memory cosnumed by these indexes could potenitally be an issue once the data in the table keeps increasing periodically which is a common scenario in OLTP environment cannot specify bitmap when creating global partitioned index cannot specify both unique and bitmap 35. What is pipelined function? PL/SQL function that will operate like a table and is used for dataware house db to transform large amount of data A pipelined funtion returns the rowsets as soon as they are retrieved from the c ursor or query, in other words these funtions do not wait until all the data is fetched by the query instead these funtions return the data as soon as it is retireved 36. What is deterministic function? A determinsitnc function will not queryt he data everytime the funtion is called if the resultset to be returned by the funtion is always the same. This usually helps when the data retrieved by the funtion is the same the funtion is called eve rytime. function will always return the same output return value for any given input arg uments 37. disadvantages of indexes? Maintaining the indexes ususally when the size of the table is huge and the amou nt of DML operations happening in the table are pretty large. Since indexes need their own tablespaces they do consume a large amount of m emory. If not defined properly then retrieval of data from indexes could be slower than table scan. index consume disk space queries can choose wrong index plan slowing the execution of query and thus perf ormance. 38. How do you choose whether to use function or procedure? Function can use for computation where proc can use for business logic For multiple values to be returened use procedures ese for single value to be re turedn use function,Function is mainly used in the case where it must return a v

alue. A procedure may modify an object where a function can only return a value The RE TURN statement immediately completes the execution of a subprogram and returns c ontrol to the caller.

39. How to delete duplicates without using ROWID? Insert the dulicate columns in temp table usign group by having statement Delete the rows in the original table matching the dat a with temp table cr eated Insert the data from temp table int original table. User a PL/SLQ procedure and cursor to fetch each row and determine wther a duplicate with use of counter variables and delete if the row already exists select * from ( select a.*, row_number() over ( partition by column1 order by column2) r from table a) where r >1; delete from table where (c1,c2,...) in (Select * from table); 40. What is difference between ROWNUM and ROWID A ROWNUM is a column which gets increamented by 1 everytime a row is fetched by the query. A ROWID indicated the actual physical disk location of the row to be found i n the query 41. What are sequences? Sequnces are the objctes which can used as counters genraaly used to get the val ues for priary key. The sequenced ussually start with the number defined int he declaration and can be incremented by a certain amoutn everytime a new valueis required unti l the max limit iis reached 42. how to generate sequence number is reverse order? using "start with". For descending sequences, the default value is the maximum value of the sequence Using INCREAMENT BY statement with a negative digit like INCREMENT BY -2 43. What are synonyms? Synonyms are alias names given to a table, view, stored procedures etc. ----------------------------- SQLLoader ---------------------------------------44. What are external tables? External Tables let you query data in a flat file as though the file were an Ora cle table.

External tables are the tables create on a generic or user created data file lik e a csv file or a delimited files which can used as part of the normal SQL staetments like the regular oracle table. No indexes can be created on t he external table but they can be partitioned 45. Disadvantages of using external table? No indexes can be created on an external table, hence always a full table scan i s required No DML statements are allowed on external tables They always perform a sequqntial read hence are slow to retriev ethe data 46. What are the types of loads possible using SQLLoader? Traditional load and direct access loads Conventional Path, Direct Path, and External Table 47. how do you load alternate rows into the table using SQLLoader? Using INTO TABLE table_name WHERE condition caluse ----------------------------- Unix ----------------------------------------48. Type of shells in unix? What is the advantage of a particular shell over oth ers? Bourne shell (sh) C shell (csh) TC shell (tcsh) Korn shell (ksh) use Unix more extensively, tcsh (Turbo C Shell) is used Korn has a command history feature, a command alias feature, support for shell s cripts A feature of Bourne shell is its way of manipulating environment variables C shells are used for Aliasing and history recording 49. Use of AWK and SED? sed-- to determine which lines of its input that it will operate on from the add ress range passed to it. It receives text input , performs certain operations on specified lines of the input, one line at a time, then outputs the result to a file. awk--Awk breaks each line of input passed to it into fields. 50. How to call SQLPLus from unix script? sqlplus -s $login <<-EOF ----EOF; .sh file contains-sqlplus $1/$2@ORACLE_SID calling .sh file as -- .sh username pwd

51. How many parameters can be passed to a unix function? No defined limit 52. How do you handle more than 10 parameters? Call the function with 10 arguments saperated by space and eclosed within " and start with $ like function_name "$arg1" "$arg2" etc 53. How do you get the return code from the function call? Using $? 54. how to spawn a child process from a script? using fork statement ----------------------------- Unit Testing ---------------------------------------55. What kind of testing do you do for a program 56. Give test cases for the below fnc fnc mysum( a in number, b in number) returns number is begin return a+b ; end; - Should tell about handling small / large numbers (boundary conditions) - should tell about characters (exception handling) - should tell about handling NULL (NULL Handling) ----------------------------- Peformance ---------------------------------------57. What is the output of explain plan Explain plan gives the detailed explanation of query execution path like the typ e of joins used, indexes utilized, full table scans done etc EXPLAIN PLAN output shows how Oracle executes SQL statements and displays the ex ecution plans chosen by the Oracle optimizer. 58. What is the difference between explain plan and autotrace autotrace genrates the query plan or explain plan for each statemnt executed in the session until autotrace is set off. This may result in degradation of query performance The explain is an ad hoc statement for which the user needs to provide a spe cific query to get the explain for the query and its not generated automatically unlike autotrace 59. What is tkprof used for? tkprof is the utility used to parse the trc trace generated by the oracle db for a session when set sql_trace on is executed. The tkprof analyzes the trace and generates

the output in the form of time and memory utilized for parsing, execution an d data fetch which helps the dba's in analysing the db performance You can run the TKPROF program to format the contents of the trace file and plac e the output into a readable output file. TKPROF can also: Create a SQL script that stores the statistics in the database Determine the execution plans of SQL statements 60. What does Cost mean? what does it indicate? The ocst is teh CPU cost and i/o execution cost used by the CBO based onb the mo st recent statistics on the table. The cost is directly proportional to the execution time of the query cost is representing of units of work (disk I/O, CPU usage, and memory usage) or resources. cost represents no if disk i/o , amount of cpu used,memory used for performing a n operation. 61. how do you decide what is the optimal path for execution of a query? how do you change the execution path? Get the explain plan for the query and analyse the joins and indexes being used in the query. Deciding the otimal execution plans depends on lots of factoirs such as User of unique indexes as much as possible Use of nested loop join where the cardinality rate is pretty high Use of hash joins where the cardinality is low Indexes being used in the joins etc by cost,performance of system use hints to change query execution path.

62. What are hints? Hints provide a mechanism to instruct the optimizer to choose a certain query ex ecution plan based on the specific criteria Hints let you make decisions usually made by the optimizer

63. When to use hints? disadvantages of hints. When the Oracle CBO execution plan is resulting in longer execution time of the query it is perferable to use the compiler hints Disadvantages Will override the oracle's standard execution path which needs more time in parsing the query Certain hints like append will result in non-retrival of data wghile a DML is perfomed

Вам также может понравиться