Академический Документы
Профессиональный Документы
Культура Документы
sqlplus bob/bob
SQL> select 40 from dual; [40]
SQL> select 'polly want a cracker' from dual; [polly want a
cracker]
SQL> select user from dual; [BOB]
SQL> select SYSDATE from dual; [15-APR-98]
SQL> exit
3 What is an object in ORACLE? An object in ORACLE can be a table, view, package, package
body, index, constraint, sequence, etc . . .
4 a)How do you see what tables a)select * from user_tables;
are owned by the user_id you b)select * from cat;
logged onto ORACLE with? select * from user_objects;
b) How can I see other things? select * from user_sequences;
c) Can I see other user's select * from all_tables where user = 'BOB'
objects? select * from user_views;
c) In most cases you can see other peoples items. Sometimes if
information is not being shared you will not be able to tell what
is in another person's account.
select * from all_tables;
select * from all_objects;
5 What is a VIEW? A view is a query which when called looks like a table. It is not
a table. To see what views exists you can issue the following
SQL statement:
select * from user_views;. Or
select * from all_views where owner = 'BOB'; user_views,
all_tables, user_tables, all_sequences, user_sequences,
user_tab_columns, all_tab_columns etc. . . are all VIEWS.
6 How do I tell what the columns desc view_or_table_name;
in a view or a table are?
7 What is a schema? The set of objects owned by a user account is called the user's
schema.
8 What is an index? An index is used on one or more columns on a table to decrease
the time it takes to find certain value(s).
9 Why might an index increase An index may increase the time it takes to do an insert, update,
the amount of time it takes to do or delete if the index itself needs to be updated because of the
an insert, update, or delete. DML (data manipulation language) issued.
10 What is a constraint? When a constraint is applied to a table, every row in the table
must satisfy the conditions specified in the constraint
definition. Examples of types of constraints are NOT NULL,
UNIQUE, DEFAULT, and CHECK.
11 How do you see what table select index_owner, index_name, column_name,
fields are used in indexes or column_position from all_ind_columns where table_name =
constraints? 'MLOAN'; select owner, table_name, constraint_name,
column_name, position from all_cons_columns; The position
indicates what order the column_name appears in the index or
constraint. The position is important because the order of the
columns determines how SQL statements should be written. It
is important to note that the positions of columns in an index
can change (the DBA may decide to do this).
12 What is all_tab_columns or All_tab_columns is a view that has an entry for every column
user_tab_columns? of every table of every users schema. User_tab_columns is a
view that has an entry for every column of every table in a
certain user's schema. When you use desc on a table to show
the columns of that table the order of the columns shown is
determined by the position that you can see when you look at
the column_id in all_tab_columns and/or user_tab_columns.
The DBA may change the order of these columns. It is very
important not to assume that the columns are in a certain order
and will stay that way.
13 Why do indexes and constraints select * from all_constraints c, all_indexes i where i.owner
have the same names? = c.owner and i.table_owner = c.owner and index_name =
constraint_name and i.table_name = c.table_name; A
UNIQUE CONSTRAINT, or NOT NULL CONSTRAINT by
definition is an index; even though it is enforcing referential
integrity, it also provides a fast method of looking up certain
values in certain columns in a table.
14 What does it mean if an It means that this index or constraint is on one or more columns
index_name or constraint_name of a table and it represents the primary key(s).
has a "_PK_" in it?
15 What is a primary key? The primary key of a table is the column or set of columns that
makes every row in that table unique.
16 What is a foreign key? A foreign key from one table references a primary key in
another table.
17 a) What is a sequence? a)A sequence is like a ticket dispenser in a bakery. It usually
b) How do you obtain the next dispense tickets starting with 1 and progressing with 2 , 3 , 4
value from a sequence? and so on. This progression can either be ascending or
c) How do you create a descending. In the above example the increment is 1. Like the
sequence? dispenser, a sequence will not give the same number to one or
d) Can you modify a sequence more people. (okay, Dispensers get new tapes and start over
once you have created it? again with 1).
e) How do I get rid of a b) So, you want the next value from a sequence? The SQL
sequence. command is
SELECT sequence_name.nextval from dual; Once you have
called for the next value from a sequence, you can use get the
current value;
SELECT sequence_name.currval from dual; CURRVAL can
not be used before NEXTVAL in any session.
c)create sequence ticket_giver; Go ahead try it!!! If you want
to see where your sequence information is kept you can query
the VIEW user_sequences or all_sequences:
select * from user_sequences;
d) In most cases the answer to this question is No. You would
have to drop the sequence and recreate it with the new
attributes. ; In ORACLE versions greater than 7.3.3 you may
use the alter sequence sql statement to change some attributes
of a sequence.
e) In most cases your Database Administrator would not want
you dropping sequences that he or she has created. However, if
you create a sequence you may drop it. Drop sequence
ticket_giver; or Drop sequence sequence_name;.
18 What is a trigger? A trigger is like a bomb. It is specified to go off when certain
events happen. A trigger may be set to check values for an
insert into a row of data and alter them or cause an error. A
trigger may be specified to log changes to tables or user logons,
just about anything.
19 Is there an ORACLE command Yes, on UNIX you can use the command: oerr ora #. Although
available through the operating ORACLE errors sometimes appear to be negative numbers,
system can tell you the meaning they are positive numbers!
of an error number. What is it?
20 What can you tell me about You can call exp and imp respectively from the AIX command
EXP and IMP commands? line to export and import data from the database. For more
information about these commands type either
exp help=y or imp help=y. These commands are extremely
useful for saving data sets for testing certain conditions (like
proving that an error in a program has been fixed.) Exports
include sequences, privledges, views, tables, packages,
indexes, constraints, grants, database links, and table_data. You
can choose to export a table definition and not the table data or
to export all the tables or just one. Imports can be used to
transfer tables, etc. from one user to another.
21 What are some basic Data INSERT UPDATE TRUNCATE DELETE CREATE DROP,
Manipulation Commands etc . . .
(DML)?
22 What does DROP do? It removes an object from the database such as a table,
sequence, view, package, etc. . . Syntax: drop table
table_name; drop sequence sequence_name;
23 What does ALTER do? Alter allows you to add to or modify a database object.
24 Is ORACLE SQL case sensitive Trick question. When you access views you have to give field
or not? values in uppercase like
select * from all_tables where table_name =
'TICKET_TAKER';. When you are issuing a data modification
language command you can reference a table in any case that
you want. Data is case sensitive.
25 What is the difference between select variables are retrieved and bind variables are certain
a select and a bind variable? values you specifiy in the where clause.
26 How do you tell what date and select sysdate from dual;
time an ORACLE system thinks
it is?
27 If you have a large number of select distinct (some_column) from some_table;
rows in a table and you just
need to know the unique values
of a column what SQL
statement would you use?
28 What query would you execute select some_column, count(*) from some_table group by
if you wanted to know some_column;
how many times each value
appears in the database?
29 What if you just wanted to select some_column, count(*) from some_table group by
know what value appeared count(*) desc where rownum < 2;
the most times in a specific field
in the database?
30 What if you wanted to know select some_column, count(*) from some_table group by
what values appear count(*) having count(*) > 15;
more than 15 times in a table?
31 What is something very Your group by items must be in the exact order of the select
important to remember about items.
using GROUP BY?
32 What query would you use if select min(some_column) from some_table;
you wanted the minimum data
value in a select field in a table?
33 What is wrong with the The value in the some_other_column field may not come from
following query: the same row as the minimum value.
select min(some_column),
some_other_column from
some_table where something =
:something;
34 What about There is nothing wrong with this query.
select min(some_column),
max(some_other_column)
from some table where
something = something;
35 If you wanted to convert the to_date('23-JAN-98','DD-MON-YY')
character string '23-JAN-98'
into an ORACLE variable of
type DATE what command
would you use?
36 If you wanted a get a date from To_char(date,'YYYYMMDD:HH.MI.SS A.M.')
the database in a character array
format what command would
you use? Specifically the format