Oracle 面试宝典 - 6

1. How can variables be passed to a SQL routine

By use of the & symbol. For passing in variables the numbers 1-8 can be used (&1, &2,...,&8) to pass the values after the command into the SQLPLUS session. To be prompted for a specific variable, place the ampersanded variable in the code itself: "select * from dba_tables where owner=&owner_name;" . Use of double ampersands tells SQLPLUS to resubstitute the value for each subsequent use of the variable, a single ampersand will cause a reprompt for the value unless an ACCEPT statement is used to get the value from the user.

2. You want to include a carriage return/linefeed in your output from a SQL script, how can you do this

The best method is to use the CHR() function (CHR(10) is a return/linefeed) and the concatenation function "||". Another method, although it is hard to document and isn?t always portable is to use the return/linefeed as a part of a quoted string.

3. How can you call a PL/SQL procedure from SQL

By use of the EXECUTE (short form EXEC) command.

4. How do you execute a host operating system command from within SQL

By use of the exclamation ball "!" (in UNIX and some other OS) or the HOST (HO) command.

5. You want to use SQL to build SQL, what is this called and give an example

This is called dynamic SQL. An example would be: set lines 90 pages 0 termout off feedback off verify off spool drop_all.sql select ?drop user ?||username||? cascade;? from dba_users where username not in ("SYS?,?SYSTEM?); spool off Essentially you are looking to see that they know to include a command (in this case DROP USER...CASCADE;) and that you need to concatenate using the ?||? the values selected from the database.

6. What SQLPlus command is used to format output from a select

This is best done with the COLUMN command.

7. You want to group the following set of select returns, what can you group on

Max(sum_of_cost), min(sum_of_cost), count(item_no), item_no The only column that can be grouped on is the "item_no" column, the rest have aggregate functions associated with them.

8. What special Oracle feature allows you to specify how the cost based system treats a SQL statement

The COST based system allows the use of HINTs to control the optimizer path selection. If they can give some example hints such as FIRST ROWS, ALL ROWS, USING INDEX, STAR, even better.

9. You want to determine the location of identical rows in a table before attempting to place a unique index on the table, how can this be done

Oracle tables always have one guaranteed unique column, the rowid column. If you use a min/max function against your rowid and then select against the proposed primary key you can squeeze out the rowids of the duplicate rows pretty quick. For example: select rowid from emp e where e.rowid > (select min(x.rowid) from emp x where x.emp_no = e.emp_no); In the situation where multiple columns make up the proposed key, they must all be used in the where clause.

10. What is a Cartesian product

A Cartesian product is the result of an unrestricted join of two or more tables. The result set of a three table Cartesian product will have x * y * z number of rows where x, y, z correspond to the number of rows in each table involved in the join.

11. You are joining a local and a remote table, the network manager complains about the traffic involved, how can you reduce the network traffic Push the processing of the remote data to the remote instance by using a view to pre-select the information for the join. This will result in only the data required for the join being sent across.

11. What is the default ordering of an ORDER BY clause in a SELECT statement

Ascending

12. What is tkprof and how is it used

The tkprof tool is a tuning tool used to determine cpu and execution times for SQL statements. You use it by first setting timed_statistics to true in the initialization file and then turning on tracing for either the entire database via the sql_trace parameter or for the session using the ALTER SESSION command. Once the trace file is generated you run the tkprof tool against the trace file and then look at the output from the tkprof tool. This can also be used to generate explain plan output.

13. What is explain plan and how is it used

The EXPLAIN PLAN command is a tool to tune SQL statements. To use it you must have an explain_table generated in the user you are running the explain plan for. This is created using the utlxplan.sql script. Once the explain plan table exists you run the explain plan command giving as its argument the SQL statement to be explained. The explain_plan table is then queried to see the execution plan of the statement. Explain plans can also be run using tkprof.

14. How do you set the number of lines on a page of output? The width

The SET command in SQLPLUS is used to control the number of lines generated per page and the width of those lines, for example SET PAGESIZE 60 LINESIZE 80 will generate reports that are 60 lines long with a line width of 80 characters. The PAGESIZE and LINESIZE options can be shortened to PAGES and LINES.

15. How do you prevent output from coming to the screen

The SET option TERMOUT controls output to the screen. Setting TERMOUT OFF turns off screen output. This option can be shortened to TERM.

16. How do you prevent Oracle from giving you informational messages during and after a SQL statement execution

The SET options FEEDBACK and VERIFY can be set to OFF.

17. How do you generate file output from SQL

By use of the SPOOL comm

From:http://www.orafaq.com/wiki/Interview_Questions

时间: 2024-11-09 16:30:41

Oracle 面试宝典 - 6的相关文章

Oracle 面试宝典 - 3

1. Describe the difference between a procedure, function and anonymous pl/sql block.  Candidate should mention use of DECLARE statement, a function must return a value while a procedure doesn't have to. 2. What is a mutating table error and how can y

Oracle 面试宝典 - 1

1. Explain the difference between a hot backup and a cold backup and the benefits associated with each. A hot backup is basically taking a backup of the database while it is still up and running and it must be in archive log mode. A cold backup is ta

Oracle 面试宝典 - 5

1. Give one method for transferring a table from one schema to another: There are several possible methods, export-import, CREATE TABLE... AS SELECT, or COPY. 2. What is the purpose of the IMPORT option IGNORE? What is it?s default setting The IMPORT

Oracle 面试宝典 - 2

1. How would you determine the time zone under which a database was operating? SELECT dbtimezone FROM DUAL; 2. Explain the use of setting GLOBAL_NAMES equal to TRUE. It ensure the use of consistent naming conventions for databases and links in a netw

Oracle 面试宝典 - 4

1. A tablespace has a table with 30 extents in it. Is this bad? Why or why not. Multiple extents in and of themselves aren?t bad. However if you also have chained rows this can hurt performance. 2. How do you set up tablespaces during an Oracle insta

Oracle 面试宝典 - 7

1. What is a CO-RELATED SUBQUERY A CO-RELATED SUBQUERY is one that has a correlation name as table or view designator in the FROM clause of the outer query and the same correlation name as a qualifier of a search condition in the WHERE clause of the

Oracle 面试宝典 - 8

1. What is a pseudo column. Give some examples It is a column that is not an actual column in the table. eg USER, UID, SYSDATE, ROWNUM, ROWID, NULL, AND LEVEL. Suppose customer table is there having different columns like customer no, payments.What w

Oracle 面试宝典 - General Questions

转自 http://www.orafaq.com/wiki/Interview_Questions Tell us about yourself/ your background. What are the three major characteristics that you bring to the job market? What motivates you to do a good job? What two or three things are most important to

Java面试宝典2013版(超长版)

一. Java基础部分......................................................................................................2 1.一个".java"源文件里能否够包含多个类(不是内部类)?有什么限制?.....2 2.Java有没有goto?........................................................................