36401672-Oracle-DBA

Embed Size (px)

Citation preview

  • 8/14/2019 36401672-Oracle-DBA

    1/67

    Oracle FAQ's1.What is an Oracle instance?

    Overview of an Oracle InstanceEvery running Oracle database is associated with an Oracle instance. When a

    database is started on a database server (regardless of the type of computer),Oracle allocates a memory area called the ystem !lobal "rea (!") and starts

    one or more Oracle processes. #his combination of the !" and the Oracle

    processes is called an Oracle instance. #he memory and processes of an instancemanage the associated database$s data efficiently and serve the one or multipleusers of the database.

    #he Instance and the %atabase"fter starting an instance, Oracle associates the instance with the specified

    database. #his is called mounting the database. #he database is then ready to beopened, which ma&es it accessible to authori'ed users.

    ultiple instances can eecute concurrently on the same computer, each accessingits own physical database. In clustered and massively parallel systems (**),

    the Oracle *arallel erver allows multiple instances to mount a single database.Only the database administrator can start up an instance and open the database.

    If a database is open, the database administrator can shut down the database sothat it is closed. When a database is closed, users cannot access the

    information that it contains.

    ecurity for database startup and shutdown is controlled via connections toOracle with administrator privileges. +ormal users do not have control over the

    current status of an Oracle database.

    Q: What is a view?

    iew" view is a tailored presentation of the data contained in one or more tables

    (or other views). -nli&e a table, a view is not allocated any storage space, nordoes a view actually contain data rather, a view is defined by a /uery that

    etracts or derives data from the tables the view references. #hese tables arecalled base tables.

    iews present a different representation of the data that resides within thebase tables. iews are very powerful because they allow you to tailor the

    presentation of data to different types of users.iews are often used to0

    provide an additional level of table security by restricting access to apredetermined set of rows and2or columns of a table

    hide data compleity simplify commands for the user

    present the data in a different perspective from that of the base table isolate applications from changes in definitions of base tables

    epress a /uery that cannot be epressed without using a view

    What is referential integrity?

    3ules governing the relationships between primary &eys and foreign &eys of

    tables within a relational database that determine data consistency. 3eferential

    integrity re/uires that the value of every foreign &ey in every table be matchedby the value of a primary &ey in another table.

  • 8/14/2019 36401672-Oracle-DBA

    2/67

  • 8/14/2019 36401672-Oracle-DBA

    3/67

    Tech Interviews comment bySasidhar

    K.+ame the data dictionary that stores user5defined tored procedures6

    ans 05 user7obJectsTech Interviews comment byAravind Kumar

    1L.hi ,i would li&e &now more about s/l advanced /ueries .

    Tech Interviews comment by mrs

    11.>uestion0Why -se /lG ?oader in Oracle %atabase6

    "nswer0 #he /l ?oader module of the oracle database anagement ystem loads data into an eistingO3"8?E table from an eternal files.It is available locally only on 8 and *8s with oracle version ;.

    #hroughout this documentation the 8"3 database described in 3eferance " is used for illustration.#here are several methods others than using >? G?oader of inserting data into a table.

    1. #he /l insert command may be used from the >? G *lus module,

    for Eample 0insert into 8"3 values(M)

    where the values to be inserted into a row of the table are listed inside the parentheses. %ates and 8haracters

    data must be urrounded by single /uotes items are seperated by commas.4. /lG=orms allows you to add rows interactively using forms. #he forms may contain default values and

    chec&s for invalid data.

    9. O%? loads the table from a control file and separate fied format data file. O%? is available on allversions of O3"8?E . >? G ?oader is much more fleible than O%? and will eventually supersede it on alsystems.

    Tech Interviews comment byShashi

    14.We can eecute a function in s/l /uery

    select functionname(paramaters) from dualuppose i am created a function add which returns the addition of two numbers then

    select add(9,:) from dualC

    O%N8 stands for open database connectivitytrigger is a stored procedure which auotomatically fired on a table whenever any dml operation is affected in

    the table.we can create ddl trigger,database trigger(logon,logoff,startup,startoff),audit triggers

    pseudo column the column which does not eist in a tableerownum,rowid,level etc

    Tech Interviews comment byDinkocet

    19.#han&s a lot for providing answers for the above /uestionsMi am grateful to all of you

    3egards3avi *ra&ash

    Tech Interviews comment byRavi Prakash

    1:."nswer to some of the /uestions above0O%N8 stands for Open %atabase 8onnectivity. It is used to connect the frontend with the bac&end(database)

    +ormali'ation is the techin/ue of designing the database with the least redundancy and duplicacy of data.#ypes of +ormali'ation01 +=

    4 +=9 +=

    N8+=; +=

    @+= 0 Impossible to achieve this level of normali'ationTech Interviews comment by Vick

    http://oracle/http://www.techinterviews.com/http://oracle/http://www.techinterviews.com/
  • 8/14/2019 36401672-Oracle-DBA

    4/67

    1;.hii have problem with import

    i have eport file on linu os and oracleii want import on windows platform

    what should i do6Tech Interviews comment by rekhalal

    [email protected] Brishna ,#han&s a lot for the "nswers

    Tech Interviews comment by sangeetha1C.Ai "ll,

    #han& you for all posting the > < ".

    Tech Interviews comment byPranesh

    1.what is a synonym 6

    "ns. " synonym is an alternative name for tables,views,procedures and other database obJectsgenerally when we have more than one schema and we wish to access an obJect of a different schema then

    we create synonyms for that obJect in the schema where we wish to access the obJect.

    ynta0create synonym synonym5name for schemaname.obJect5name

    what is an eception 6

    Eception is an event that causes suspension of normal program eecution.In oracle there are serveral types of eceptions1) *re5defined eceptions li&e +O7%"#"7=O-+%,#OO7"+H73OW

    4) -ser5defined eceptions which would validate the business logic9) unnamed system eceptions which are raised due to errors in the application code .. you can name these

    eceptions using *3"!" E8E*#IO+7I+I#:)-nnamed programmer5defined eceptions. Eceptions that are defined and raised in the server by the

    programmer. In this case, the programmer provides both an error number (between 54LLLL and 54LKKK) andan error message, and raises that eception with a call to 3"IE7"**?I8"#IO+7E33O3.

    for all the eceptions raised oracle fills in s/leerm and s/lcode variable which provide the error message anderror code for the eception raised.

    What are pseudo5columns in >?6 *rovide eamples6" pseudocolumn behaves li&e a table column, but is not actually stored in the table. Hou can select from

    pseudocolumns, but you cannot insert, update, or delete their values.Eamples0

    8-33"?,+E#"?,3OWI%,?EE?what is a schema 6

    " schema is a oracle database user account.

    Tech Interviews comment byRajesh B

    1K.What is a schema 6

    " database user account is called a schema.

    Tech Interviews comment by thevampirea@yahoocoin

    4L.What is a schema 6" schema is a logical collection of database obJects li&e tables, views, p&gs, procedures, triggers, etc. Itusually has an associated database user.

    Tech Interviews comment byAnil Kuppa

    41.this is Just to subscribe

    Tech Interviews comment by!atraj

    44.What is a co5related sub5/uery6

    It is very similar to sub5/ueries where the parent /uery is eecuted based on the values returned by sub5/uries. but when come$s to co5related sub/ueries for every instance of parent /uery sub/uery is eecuted and

  • 8/14/2019 36401672-Oracle-DBA

    5/67

    based on the result od sub5/uery the parent /uery will display the record as we will have refernce of parent/uries in su5/ueries we call these as corelated sub/uries.

    so, we can define co5related sub /uery as for every record retrival from the sub /uery is processed and basedon result of process the parent record is displayed.

    Tech Interviews comment by!atraj

    49.wht is the maJor difference b2w oracle i < Ki

    Tech Interviews comment by renjith

    4:.what is trigger6

    #rigger is an event. It is used prevent the invalid entries of the data.#herehas a different types of trigger are available.

    1)rowlevel triggerbefore insert,before delete,before update

    after insert,after delete,after update

    4)statement level triggerbefore insert,before delete,before update

    after insert,after delete,after update

    9)I+#E"% O= trigger:)chema level #riggers

    ;)ystem level #riggers

    Tech Interviews comment byRamananth4;.co5related sub5/uery 5 I assume you mean correlated sub5/uery6

    Tech Interviews comment by"ark

    [email protected] want to get information about coalescing to tablespace6

    end theinformation to me through the mail id i have mentioned above.3egards

    ?uc&yTech Interviews comment by#ucky

    4C.i want to &now how to use rownum and rowid efficiently in s/lGplus /ueriesTech Interviews comment by sudha

    4.hiwill u ple'''' tell me

    can we return cursor in the function if yes than what the process6can we define eceptions twice in same bloc&6

    what is ma. no. of statment that can specified in triggers6in cursor where the cursor variable used in pac&age body6

    Tech Interviews comment by lekha reddy

    4K.is there any solution to delete a particular colum in a database by s/l

    Tech Interviews comment by manraj

    9L.Aow can I assigned two table in a single bloc& (database bloc&) in forms@i6

    Tech Interviews comment bySudipta

    91.>. Is there any solution to delete a particular colum in a database by s/l6". #his is cant be done in versions before Ki.In Ki

    >?P alter table delete column Tech Interviews comment by $aurav Sachan

    94.pseudo columns in s/l are currval and netval.#hese are used with se/uences to retreive the net se/uencevalue and current se/uence value.

    #he usage is as followssuppose abc is the se/uence name if i want to see the currval of the se/uence we issue the s/l statement

    select abc.currval from dual

    http://www.insoft.com/http://www.oracle.com/http://www.insoft.com/http://www.oracle.com/
  • 8/14/2019 36401672-Oracle-DBA

    6/67

    if we want to see the net value of the se/uence we issue the commandselect abc.netval from dual

    Tech Interviews comment by satish

    99.Ai here i would li&e to give simple answer for /uestion Q1

    What is an oracle instance6"n Oracle instance consists of the ystem !lobal "rea (!") memory structure and the bac&ground

    processes used to manage a database. "n instance is identified by using methods specific to each operatingsystem. #he instance can open and use only one database at a time.

    rinivasa 3eddyTech Interviews comment bySrinivasa Reddy

    9:.hi,what is the maJor difference between normal =O3 ?OO* and 8-3O3 ?OO*6

    53egards

    uttappa .#.

    Tech Interviews comment by"uttappa S%

    9;.Ai,

    when we install the new version of Oracle then what happens to our earlier forms6Tech Interviews comment by &jjwala

    [email protected] is overloading of pac&ages in oracle

    Tech Interviews comment byjyothi9C.is it possible to create a cursor which is based on more than one table.

    Tech Interviews comment by vasundhara

    9.#he correct answer for this /uestion is>. Is there any solution to delete a particular colum in a database by s/l6

    ". alter table drop columnor

    first mar& the column unusedalter table set unused column

    then drop italter table drop unused columns.

    #his will drop all the columns mar&ed as unused. If a particular column has to be dropped, mention thecolumn name after columns

    Tech Interviews comment byRam

    9K.the [email protected] RWhat is a schema6S is wrong.

    " schema is a collection of logical obJects owned by a user. " user in that regard is an account registeredwith the Oracle server.

    Once u login into ur account2user, u can access other user$s schema obJects li&e i can write scott.emp, if at ali$ve acces to scott user$s emp table.

    Tech Interviews comment by rahul

    :L.%ata odel0 #he logical data structure developed during the logical database design process is a data modelor entity model. It is also a description of the structural properties that define all entries represented in a

    database and all the relationships that eist among them.F3OW#H*E is used to declare a record with the same types as found in the specified database table, viewor cursor

    F#H*E is used to declare a field with the same type as that of a specified table$s column.Inde for a physical structure (b5tree) to help you /uery run faster.

    #able partition is a method of brea&ing a large table into smaller tables grouped by some logical separators.in your case, having both inde and partition will ma&e things faster.

    %ata 8ontrol statements#hese are used to control the data using %8? (data control language) e0 !rant etc.

    mailto:[email protected]:[email protected]:[email protected]
  • 8/14/2019 36401672-Oracle-DBA

    7/67

    #rigger 0 " program in a database that gets called each time a row in a table is I+E3#E%, -*%"#E%, or%E?E#E%. #riggers allow you to chec& that any changes are correct, or to fill in missing information before

    it is commited. #riggers are normally written in *?2>? or Tava.3elation0 athematical term for a table.

    3edo ?og0 " set of files that record all changes made to an Oracle database. " database -# have at leasttwo redo log files. ?og files can be multipleed on multiple dis&s to ensure that they will not get lost. "lso

    see thread.Oracle "38Aiver *rocess. "38A is an Oracle bac&ground process created when you start an instance in

    "38AIE ?O! O%E. #he "38A process will archive on5line redo log files to some bac&up media.Nuffer 8ache0 #he portion of the !" that holds copies of Oracle data bloc&s. "ll user processes that connec

    to an instance share access to the buffer cache. *erformance of the buffer cache is indicated by the N8A3(Nuffer 8ache Ait 3atio).

    Nac&ground *rocess0 +on5user process that is created when a database instance is started. #hese processes

    are used to manage and monitor database operations. Eample bac&ground processes0 O+, *O+ etc.#wo5*hase 8ommit0 " strategy in which changes to a database are temporarily applied. Once it has been

    determined that all parts of a change can be made successfully, the changes are permanently posted to the

    database. #he steps involved are the RpreparedS and Rcommit re/uestS-nion0 "ll the distinct rows are selected by either /uery.

    Intersect0 "ll distinct rows selected by both /ueries

    inus0 "ll distinct rows that are selected by the first E?E8# statement and that are not selected in thesecond E?E8# statement.Toin0 #he process of combining data from two or more tables using matching columns. #ypes of Join are E/u

    Toin, Outer Toin, elf Toin, +atural Toin, etc.E/ui Toin0 "n E/ui Toin (a&a. Inner Toin or imple Toin) is a Join statement that uses an e/uivalency

    operation (i.e0 col" U colN) to match rows from different tables. #he converse of an e/ui Join is anone/uiJoin operation.

    Outer Toin0 imilar to the E/ui Toin, but Oracle will also return non matched rows from the tale with theouter Join operator (V). issing values are filled with null values.

    elf Toin0 " Join in which a table is Joined with itself.+atural Toin0 " Join statement that compares the common columns of both tables with each other. One shoul

    chec& whether common columns eist in both tables before doing a natural Join.Integer %ata #ypes0 "38A"34 (i'e), +-NE3 (*recision, i'e)

    %enormali'ation0 #he opposite of data normali'ation (almost). In a denormali'ed database, some duplicateddata storage is allowed. #he benefits are /uic&er data retrieval and2or a database structure that is easier for

    end5users.3egards.

    Tech Interviews comment by'enis 'ohn K

    0 commen

    Oracle apps technical document1) What is !"? #rchitect$re of apps?

    " pac&aged business software system that lets a company automate andintegrate the maJority of itbusiness processes share common data and practices across the enterprise andX produce and accesinformation in a real5time environment.2) %ell me some thing a&o$t 'Q((O#*!.

    /l G loader is a bul& loader utility used for moving data from eternal files into the oracle database/l G loader supports various load formats, selective loading, and multi5tables loads.1) conventional

    55#he conventional path loader essentially loads the data by using standard Yinsert$ statement.2) +irect

    https://www.blogger.com/comment.g?blogID=3428468978735661096&postID=5976529464479739549http://oracleiqs.blogspot.com/2008/07/oracle-apps-technical-document.htmlhttps://www.blogger.com/comment.g?blogID=3428468978735661096&postID=5976529464479739549http://oracleiqs.blogspot.com/2008/07/oracle-apps-technical-document.html
  • 8/14/2019 36401672-Oracle-DBA

    8/67

    55 the direct path loader (direct U true) by possess of logic involved with that, and loads directly in tothe oracle data files.E05y data.csv file

    1LL1, Rscott tigerS,1LLL,:L1LL4,SgvreddyS,49:;,;L

    ?oad dataInfile Yc0DdataDmydata.csv$

    Into table emp=ields terminated by R,S optionally enclosed by YS$(empno, empname,sal,deptno)Psqlldr scott/tiger@viscontrol=loader.ctl log= gvlog.log bad=gvbad.baddiscard=gvdis.dsc .,) how +o $ +$mp +ata from pl-sl &loc/ to flat files?

    -sing utl7file pac&age, we can dump data from pl2s/l bloc& to flat file."!!Q!3%'for -#?7=I?E is specify the accessible directories for the -#?7=I?E function in

    the initiali'ation file (I+I#.O3") -sing the -#?7=I?E7%I3 parameters.E0 -#?7=I?E7%I3 U

    : 55remember to update I+I#I%.O3",

    55utl7file7dir U Yc0Doradata$%eclare

    =p utl7file.file7typeNegin

    =p 0U utl7file.fopen(c0Doradata$,tab1.tt$,$w$)-tl7file.putf(fp,$Fs Fs Dn Ytet field$, ;;)

    -tl7file.fclose(fp)End

    4) What is '%O56OO7'?

    8ollection of 8hat of "ccounts and 8urrency and 8alendars is called ON8)What is the interface?

    Interface #able is a table which is used as medium for transfer of data between two systems.9)What is invoice?

    end you a re/uest for payment)What is 36O3* an+ O% 6O3*? ;*ifferent types of interfaces)

    Inbound Interface0=or inbound interfaces, where these products are the destination, interface tables as well assupporting validation, processing, and maintenance programs are provided.Outbound Interface0

    =or outbound interfaces, where these products are the source, database views are provided and thedestination application should provide the validation, processing, and maintenance programs

  • 8/14/2019 36401672-Oracle-DBA

    9/67

    AZ78-#7"88#7I#E7"?? stores information about customer sites.One customer account can have multiple

    sites. #he address is maintained in AZ7?O8"#IO+.

    hz_cust_site_uses_all(site_use_id)AZ78-#7I#E7-E7"?? stores information about site uses or business purposes. " single customer site can have

    multiple site uses, such as bill to or ship to, and each site use is stored as a record in this table.

    hz_party_sites (party_site_id)AZ7*"3#H7I#E stores information about the relationship between *arties and ?ocations. #he same party can have

    multiple party sites.*hysical addresses are stored in AZ7?O8"#IO+.

    hz_locations (location_id)AZ7?O8"#IO+ stores information about physical locations.

    hz_Person_Profiles (person_profile_id)AZ7*E3O+7*3O=I?E stores detail information about people.

    hz_Organization_Profiles (organization_profile_id)AZ7O3!"+IZ"#IO+7*3O=I?E stores credit rating, financial statistics, socioeconomic and corporate lin&age

    information for business sites. #he primary &ey for this table is O3!"+IZ"#IO+7*3O=I?E7I%.

    =)What r the ta&le>s interface ta&les in the c$stomer interface ta&les?

    1)!ac$stomersinterfaceall#his table stores customer, address, and business purpose information. Hou do not have to enter values in thitable if you do not want to import customers, addresses, or business purposes.

    #**!''1 thro$gh 4

    Enter the address for your customer in these four columns. Hou can enter up to four lines of an address.

    ali+ation:

    If you enter a value in O3I!7H#E7"%%3E73E=, you must enter a value in "%%3E1. =or

    multiple rows with the same address reference, insert values in address 1[:.*estination:AZ7?O8"#IO+."%%3E1,

    AZ7?O8"#IO+."%%3E4,AZ7?O8"#IO+."%%3E9,

    AZ7?O8"#IO+."%%3E:

    2) !ac$stomerprofileintall

    " customer level profile must eist in "78-#OE37*3O=I?E7I+#E3="8E for new customers and each bill[tobusiness purpose.

    ,) !acontactphonesintall#his table stores telephone numbers for customers, addresses and contacts as well as contacts for customers

    and addresses.

    4) !ac$stomer&an/sintall#his table stores ban& information for a customer or for a specific Nill[#o address, you must enter a ban&account for this customer,

    8) !ac$stpaymetho+intall#o import payment methods for customers and bill[to business purposes,

    10) What r the staging ta&les in the c$stomer interface?

    3a7customers7stg3a7customers7address7stg3a7customers7point7stg3a7customers7contact points7stg3a7customers7relate7stg3a7customer7error.

    11)%ell me some man+atory col$mns in the c$stomer interface ta&les?

    a) !ac$stomersinterfaceall1) Orig7system7customer7ref4) insert7update7flag

  • 8/14/2019 36401672-Oracle-DBA

    10/67

    9) customer7number:) customer7status;)last7updated7by@) last7updated7dateC)created7by) creation7date.&) !ac$stomerprofileintall

    1) customer7profile7class7namec) !acontactphonesintall

    1)orig7system7telephone7ref4)telephone9) telephone7type+) !ac$stomer&an/sintall

    1) ban&7a2c7name4)ban&7a2c7no9)ban&7a2c7currency7codee) !ac$stpaymetho+intall

    1) payment7method7name

    12)%ell me the 3avigation for c$stomer interface?3eceivablesInterface8ustomers1. What ta&les cannot &e $p+ate+ thro$gh c$stomer interface?

    +o updates will be allowed to be made through customer interface for=ollowing tables3"7I#E7-E7"??3"78-#OE373E?"#IO+AI*7"??3"78-#73E8EI*#7E#AO%"*7N"+B7N3"+8AE"*7N"+B7"88O-+#7"??

    "*7N"+B7"88O-+#7-E7"??2. Aow to sen+ a++itional c$stomer an+ a++ress information thro$gh c$stomer interafce

    Aere is where attribute columns are used.G "dditional 8ustomer data can be populated in3"78-#OE37I+#E3="8E7"??.customer7attribute1 to 1;#his will go into 3"78-#OE3.attribute1 to 1;G "dditional address information can be populated in3"78-#OE37I+#E3="8E7"??.address7attribute1 to 1;#his will go into 3"7"%%3EE7"??.attribute1 to 1;"nd so on.

    8. What sho$l+ &e the &atch siBe ;n$m&er of c$stomer recor+s) general g$i+elines for optimalperformance

    "bout 1L,LLL records per bacth is ideal, it is suggested to &eep the batchsi'e small.9. Why +oes c$stomer interface error o$t if there is mismatch in a++ress information?

    Necause the code validates against these mismatches.arplscin.sl an+ arpl&cin.sl

    It validates the address being inserted or updated with respect to the talocation flefield structure. =or each row being inserted or updated in3"78-#OE37I+#E3="8E, and that has not already been mar&ed in error,

  • 8/14/2019 36401672-Oracle-DBA

    11/67

    the set7location7ccid function is called to return either an eisting ccidfor the address entered or to create a new entry in "37?O8"#IO+7"?-E forthis new address. #he 3"78-#OE37I+#E3="8E record is then updated with thevalue of the ccid returned.. Aow +o yo$ sen+ recor+s at c$stomer level profile an+ a++ress-site level profile?

    =or every customer record in 3"78-#OE37I+#E3="8E7"??, insert two records in table3"78-#OE37*3O=I?E7I+#7"??. (3efer +ote0 1LCLLL.@ )=. *oes C$stomer nterface import salesperson +ata6+o, 3efer Enhancement Nug0 1:C:K;11. C$stomer nterface process can &e $se+ for $p+ating the c$stomer information Aow +oes

    the "*#% wor/?

    8urrent functionality of 8ustomer Interface is to update all the data. Hou cannot run 8ustomerInterface to update only changed data. (3efer Nug0 CK141 for the intended functinality)12. What are some of the important fiel+s that C$stomer nterface +oes not loa+?

    +ot all fields in 3"78-#OE3 are being loaded by the interface.I878O%E!"7I+%I8"#O3=ON7*OI+#

    "?E78A"++E?78O%E=3EI!A#7#E3W"3EAO-E7I%*3I8E ?I#AI*7*"3#I"?*"HE+#7#E37I% in 3"7I#E7-E.*"HE+#7#E37I%(3efer Enhancement 3e/uest Nug0 4:;9LL)1,. 3ew %C#-C$stomer o+elD how to loa+ c$stomer as "!'O3 or O!E#3F#%O3

    thro$gh C$stomer nterface?

    a) *opulate ra7customers7interface7all . person7flag U \H\

    3un 8ustomer Interface process will load this record as *E3O+b) *opulate ra7customers7interface7all . person7flag U \+\ ( or +-?? )3un 8ustomer Interface process will load this record as O3!"+IZ"#IO+

    1,) %ell me what is the proce+$re to +evelop an interface?a.=irst we will get the 3e/uirement document.

    b.We will create control file based on that plot file.c.#hen the control files which loads the data into staging tables.

    d.#hrough pl2s/l programs we will mapping and validate the data and then dump into the interface tables.

    e.#hrough the standard programs we will push the data from interfacetables to Nase tables.14)What vali+ations $ +i+ in the c$stomer interface?

    a.c$stomer name0 the same customer reference can$t have different customer names with in this table

    AZ7*"3#IE.*"3#H7+"Eb.c$stomer n$m&er0 must be null if your r using automatic customer numbering, must eit if you are not using

    automatic customer numbering. #his value much be uni/ue with in AZ7*"3#IE

    c.c$stomer stat$s0 must be Y"$ for active or YI$ for inactiveAZ7*"3#IE7#"#-

    d.&an/ acco$nt n$m or &an/ acco$nt c$rrency co+e0if the ban& a2c already eist do not enter a value

    if the ban& a2c does not eist you must enter a valuee.&an/ a-c name0 it must eist in "*7N"+B7"88O-+# or if it does not eist values must eist for

    N"+B7"2878-33E+8H78O%E

  • 8/14/2019 36401672-Oracle-DBA

    12/67

    N"+B7"287+-N"+B7+"E

    N"+B7N3"+8A7+"E+ote 0 every interface table has two error msg

    1)Error code.4)Error msg.

    18)Aow can $ call a stan+ar+ interface program from sl or pl-sl co+e?

    =+%73E>-E#.-NI#73E>-E# (Y*O$,$EE8-#"N?E +"E$,,,,*"3"E#E3)

    19)#">s 5O! C'%O! 3%!5#C?AZ78-#7"287Z*-N.-*%"#E78-#7"28

    AZ78-#7"287Z*-N.83E"#E78-#7"28

    =+%7*3O=I?E

    =+%7"**?I8"#IO+

    =+%7!?ON"?

    =+%5=I?E

    =+%78O+8-N(can submit conc program in host invironment)

    1) %ell me some #"?

    =+%7=I?E.*-#?I+E(=+%7=I?E.?O!)=+%7=I?E.*-#?I+E(=+%7=I?E.O-#*-#)

    s the "rogram eGitsD +elete conc program an+ its eGec$ta&les.I= =+%7*3O!3".*3O!3"7EI#(YE*$,"**?I8"#IO+7+"E7I+) #AE+

    =+%7*3O!3".%E?E#E7*3O!3"(YE*$,"**?I8"#IO+7+"E7I+)

    =+%7*3O!3".%E?E#E7EE8-#"N?E(YE*$,"**?I8"#IO+7+"E7I+)

    E+%

    1

  • 8/14/2019 36401672-Oracle-DBA

    13/67

    =+% =?E>? these user eits allow you to use fle fields in your reports=+% =O3"#78-33E+8H is used to print currency in various formats by using formula column

    29) "(-'Q( store+ proce+$re parameters?

    or what are the two parameters that are man+atory for pl-sl type conc$rrent program?

    *rocedure2function (E33N-= O-#3E#8O%E O-#MMMMMMM.)E33N-= 05-sed to write the error message to log or re/uest file.

    3E#8O%E 05*opulate log re/uest file with program submission details info.2) What is al$e 'et?

    55#he value set is a collection (or) container of values.55When ever the value set associated with any report parameters. It provides list of values to the enduser to accept one of the values as report parameter value.55 If the list of values needed to be dynamic and ever changing and define a table based values set.2) What r the vali+ation types?

    1) +one 55555555 validation is minimal.4) Independent 555555input must eist on previously defined list of values9) %ependent 555555input is chec&ed against a subset of values based on a

    prior value.9) #able 55555 input is chec&ed against values in an application table:) pecial 555555values set uses a fle field itself.;) *air 555555 two fle fields together specify a range of valid values.@) #ranslatable independent 55555 input must eist on previously defined listof values translated values can be used.C) #ranslatable dependent 5555555 input is chec&ed against a subset of valuesbased on a prior values translated value can be used.

    2) 3egister in the "O?

    #""(C#%O3 5O!

    #""(C#%O3 53C%O3

    #""(C#%O3 3

    2=)Aow +o $ c$stomiBe the !eports?

  • 8/14/2019 36401672-Oracle-DBA

    14/67

    a.Identify the hort name of the standard report in which module we have to customi'e$*+ , i) - want to c-stomie in the ! mod-le 'ath is''l to'0ar011.2.30re'orts04%0 .rd)

    b.Open the .rdf file in 3eport builder and change the name of the module.c.Open the data module and modify the /uery (what is client re/uirements) assign the columns to

    the attrib-tes.d.!o to report wi'ard and select, what r the newly created columns.

    e.#hen 8ompile it. #hen u will get a .rep file in the specified module. If it is not in the specifieddirectory then we have to put in the server directory.

    f.#hen 3egister in the "O? Conc$rrent eGec$ta&le.

    Conc$rrent program.

    g.go to system administrator'ec$rity!esponsi&ilityre$esth) "dd and assign a concurrent program to a re/uest group,0) !egistering parametric report?

    "ny applications will have two parameters,1) from5period 4) to5perioda) !o to obJect navigator and create the parameters.

    ser parameters fromnoD tono ;+ata type char an+ wi+th ,0)b) Open the report layout and write the /uery(we have to reg the table in "O?)%elect em'no5ename5)rom g_em' where em'no between +)rom_no and to_no

    c) 8ompile and put the .3%* file in the server directory.+) 3egistering in "O?.

    Conc$rrent eGec$ta&le

    Conc$rrent programthen go to R"#!#%!'I

    e)!o to #pplication vali+ation set. then go toH*% 3%OI"fter entering the 6#4$ %$T%(1) "nd T"7$N%(4)

    f)!o to "dministrations

    'e$rity responsi&ility !e$esth) "dd and assign a concurrent program to a re/uest group,1) %ell me some report names an+ their ta&le names in E(D #"D #!D an+ "O?1) rac$stomertrGall

    c-stomer_tr*_id

    tr*_n-mber (invoice no5 debit memo no5 credit memo no&

    c-st_tr*_ty'e_id

    4) rac$stomerlinesall ;+etails of invoice)

    c-tomer_tr*_id

    ,) arpaymentsch+$lesall

    chec8_id

    #his table stores all transactions ecept adJustments and miscellaneous cash receipts. Oracle 3eceivables updates thistable when activity occurs against an invoice, debit memo, chargebac&, credit memo, on account credit, or receipt.

    4) rac$sttrGtypesall ;invoice types)

    c-st_tr*_ty'e_id

    8) ra&atchesall

    Natch7id

    #his table stores information about each receipt batch that you create in

    Oracle 3eceivables. Each row includes information about a specific batch such as batch source, status, batch type,

    control count, and control amount

    9) rareceiva&leapplicationall

    ) raa+J$stmentsall

  • 8/14/2019 36401672-Oracle-DBA

    15/67

    #his table stores information about your invoice adJustments. Each row includes general information about the

    adJustment you are ma&ing such as activity name, amount, accounting information, reason, and type of adJustment.

    Hou need one row for each adJustment you are ma&ing to an invoice.

    ) racashreceiotsall8ash7receipt7id

    #his table stores one record for each receipt that you enter. Oracle 3eceivables creates records concurrently in the

    "378"A73E8EI*#7AI#O3H7"??, "37*"HE+#78AE%-?E7"??, and

    "373E8EI"N?E7"**?I8"#IO+ tables for invoice[related receipts.

    1)ap7invoice7allinvoice7amount, base7amount, payment7status7flag(Yy$ [fully paid

    Yn$unpaid

    Yp$ [partially paid)

    4)ap7invoice7payments7all

    invoice7id,

    9)ap7invoice7distibutions7"ll

    amount, base7amount, dist7code7combination7id, line7type7loo&up7code

    :)ap7payment7schdules

    payment7status7flag(R Y$$$$S)

    ;)ap7payment7dustributions7all

    @)ap7chec&s7allchec&7id,

    "*78AE8B7"?? stores information about payments issued to suppliers or refunds received from suppliers. Hou

    need one row for each payment you issue to a supplier or refund received from a supplier. Hour Oracle *ayables

    application uses this information to record payments you ma&e to suppliers or refunds you receive from suppliers.

    C)ap7accounting7events7all

    )ap7ban&7accounts7all

    "*7N"+B7"88O-+#7"?? contains information about your ban& accounts. Hou need one row for each ban&

    account you define. Each ban& account must be affiliated with one ban& branch. When you initiate an automatic

    payment batch, enter a manual chec&, or create a >uic& payment, you can select a ban& account that you define in this

    table.

    K) ap7ban&7accounts7uses7all"*7N"+B7"88O-+#7-E7"?? stores information for the internal and eternal ban& accounts you define in

    Oracle *ayables and Oracle

    3eceivables applications.

    1)po7vendors7all

    4)po7vendors7sites7all

    9)po7headers7all

    po7header7id

    :)po7lines7all

    po7line7id

    ;)po7line7locations7"ll

    @)po7distributions7all

    po7distribution7id,

    1)Elco+ecom&inations

    !?78O%E78ONI+"#IO+ stores valid account combinations for each "ccounting =lefield structure within your

    Oracle !eneral ?edger application. "ssociated with each account are certain codes and flags, including whether the

    account is enabled, whether detail posting or detail budgeting is allowed, and others.

    2)ElJe&atches.

    !?7TE7N"#8AE stores Journal entry batches.

    ,)ElJehea+ers

  • 8/14/2019 36401672-Oracle-DBA

    16/67

    !?7TE7AE"%E3 stores Journal entries. #here is a one[to[many relationship between Journal entry batches and

    Journal entries. Each row in this table includes the associated batch I%, the Journal entry name and description, and

    other information about the Journal entry. #his table corresponds to the Tournals window of the Enter Tournals form.

    #"#- is $-$ for unposted, $*$ for posted. Other statuses indicate that an error condition was found. " complete list

    below.

    4)ElJelines.

    !?7TE7?I+E stores the Journal entry lines that you enter in the Enter Tournals form. #here is a one[to[many

    relationship between Journal entries and Journal entry lines. Each row in this table stores the associated Journal entry

    header I%, the line number, the associated code combination I%, and the debits or credits associated with the Journalline. #"#- is $-$ for unposted or $*$ for posted

    8)Elset of &oo/s

    !?7E#7O=7NOOB stores information about the sets of boo&s you define in your Oracle !eneral ?edger

    application. Each row includes the set of boo&s name, description, functional currency, and other information. #his

    table corresponds to the et of Noo&s form.

    9)Elperio+s

    !?7*E3IO% stores information about the accounting periods you define using the "ccounting 8alendar form. Each

    row includes the start date and end date of the period, the period type, the fiscal year, the period number, and other

    information. #here is a one[to[many relationship between a row in the !?7*E3IO%7E# table and rows in this

    table.

    1)O"3*6% O !"O!%?#his report shows all the open5debit memo transactions, based on customer number and dates.8olumns 05 type, customer7no, tr7no, amt7due, remaining.

    *arameter 05 type, customer, from7date, to7date.2)E3!#%3E "O'% "#K 5( 5O! 6#37 !"O!%?

    Nasically this report generates a flat file of all the payments in order to send in to the ban&.

    ,)"*#% "O'%"#K CAC7' !"O!%?

    #his report which updates the data into the ("*) account payables system from the plot file, the file which issent by ban&

    4)"*#% "O'%"#K O% '%#3*3E CAC7'?

    #his report which shows the out standing chec&s

    8)C'%O! "#K3% *%#(' !"O!%?Which shows each customer original amount, amount pay and due amount based on transaction type (boo&s

    pens)

    %ransaction types in #!

    8redit memo transaction typesInvoice, debit memo, and charge bac& transaction types

    8ommitment transaction types

    Q) AOW *O KO !C%5K %A !!O!' 3 3%!5#C %#6('?

    %epending on the naming convention used, errors appear in either alphabetical order or by error code

    number.

    ,1) Aow +o $ i+entity its name of report?'ystem a+ministrator conc$rrent program +efine

    'ystem a+ministrator conc$rrent program eGec$ta&le

    ,2) Who information>s?

    1) 8reated by4) 8reation date9) ?ast 7updated by:) last7update7date;) last7update7value,,) 5( 5(*'?

  • 8/14/2019 36401672-Oracle-DBA

    17/67

    se+ to capt$re the a++itional &$siness information.

    *55 755

    "dditional -ni/ue Info, andatory

    8aptured in attribute prefied columns egment prefied

    +ot reported on standard reports Is reported on standard reports

    #o provide epansion space on your form Withthe help of X. X 3epresents

    descriptive =le field.=?E =I?E% 0 %E83I*#IE 0 3E!I!#E3

    -sed for entering and displaying &eyinformation

    =or eample Oracle !eneral uses a &ey =lefield called "ccounting =le field touni/uely identifies a general account.=?E =I?E% 0 BEH 0 3E!I!#E3

    Oracle #pplications 7K 5( 5(*'

    1) !? 05 "88O-+#I+!4) "3 05 "?E #" ?O8"#IO+, #E33I#O3H,9) "* 05 N"+B %E#"I?, 8O# "??O8"#IO+, *EO*?E !3O-*Oracle #pplications *'C!"% 5( 5(*' ;"artial)

    1)!? 05 daily rates4)"3 05 credit history, information

    9) *" 05 ban& branch, payment terms, site address,,4) What are the re$ests gro$ps?

    a) ingle re/uest0 5this allows you to submit an individual re/uest.b) 3e/uest set 0 5this allows you to submit a pre5defined set of re/uests.,8) 'ys #+min o+$le?

    a)%efine 8ustom -sers, &)%efine ?ogin -sers, c)3egister oracle %N users,+) %efine 8oncurrent *rograms, e)3egister 8oncurrent Eecutables, f)etting *rofile Optionalues, g)%efine 3e/uest #ypes.

    ,9) #O(?a)3egistering tables. &)3egistering views c)3egistering db se/uences+) 3egistering profile options e)3egistering loo&ups and loo&up codesf)3egistering forms g) 3egistering =orm and +on5=orm functions i)registeringenus and sub5menus. J)3egistering %== and B==. /)?ibraries,) What r the type o+els in the system parametersof the report?

    1) Nit map 4) 8haracter mode,

  • 8/14/2019 36401672-Oracle-DBA

    18/67

    by, having, connect by, start with cause of /ueries.55 bind reference may not be referenced in =3O clause (or) in place ofreserved words or clauses.(C#( !5!3C:

    55 you can use leical reference to replace the clauses appearing "=#E3 select,from, group by, having, connect by, start with.55 you can$t ma&e leical reference in a pl2s/l statmetns.,

  • 8/14/2019 36401672-Oracle-DBA

    19/67

    ultiple statements, is called "8#IE E#."llows the programmer to manually control eplicit cursor in the*l2s/l bloc&

    a)+eclare0 create a named s/l areab)Open0 identify the active set.c)5etch:load the current row in to variables.d)Close0 release the active set.

    8-3O3 "##3IN-#Ea)Lis open0 evaluates to true if the cursor is open.b)Lnot fo$n+0 evaluates to true if the most recent fetch does not return a rowc)Lfo$n+0 evaluates to true if the most recent fetch returns a row.d)Lrow co$nt0 evaluates to the total number of rows returned to far.

    Example for cursor:

    1) Declare

    Vno emp.empno%type;

    Vname emp.ename %type;

    Cursor empcursor is

    !elect empno"ename

    From emp;#e$in

    Open cursor;

    For in 1..1& loop

    Fetch empcursor into no"name;

    D(msoutput.putlinetocharno) ** +**name);

    ,nd i-;

    , nd;

    ) #e$in

    Open empcursor;

    /oop

    Fetch 0hen empcursor % ro0count 1& or,mpcuror % not -ound;

    #dmsoutputputlinetocharno)** +** name);

    ,nd loop;

    Close empcursor;

    ,nd;

    C!'O! 5O! (OO"

    ")cursor for loop is a short cut to process eplicit cursorsN)it has higher performance8)cursor for loop re/uires only the declaration of the cursor, remaining things li&e opening, fetching

    and close are automatically ta&e by the cursor for loopExample:

    1) Declare

    Cursor empcursor is

    !elect empno"ename

    From emp;

    #e$in

    For emprecord in empcursor loop

    D(msoutput.putlineemprecord.empno);

    D(msoutput.putlineemprecord.ename)

    ,nd loop

  • 8/14/2019 36401672-Oracle-DBA

    20/67

    ,nd;

    Can we create a c$rsor witho$t +eclaring it?

    Hes [ by using cursor for loop using sub/ueries.

    NE!I+

    =O3 emp7record I+ ( E?E8# empno, ename

    =3O emp) ?OO*

    55 implicit open and implicit fetch occur

    I= emp7record.empno U C9K #AE+

    ...E+% ?OO* 55 implicit close occurs

    E+%

    a) for $p+ate cla$se:

    1) use eplicit loc&ing to deny access for the duration of a transaction4) loc& the rows before update or deleteE 0 select MM.=romMM.=or update of column refX no7waitX&) where c$rrent of cla$se?

    1) use cursor to update or delete the current rowWhere current of ^P2=) #ttri&$te +ata types?

    1) Ftype 4) Frow type.,0) Gception Aan+ilings?

    Is a mechanism provided by pl2s/l to detect runtime errors and process them with out halting theprogram abnormally

    1)pre5defined4)user5defined.

    "!*53*:

    1)cursor7already7open55555555attempted to open an already open cursor.

    4)%up7val7on7inde 55555555attempted to insert a duplicate values.9)Invalid7cursor 55555555 illegal cursor operation occurred.:)Invalid7number 55555555 conversion of character string to number fails.;)?ogin7denied 555555555loging on to oracle with an invalid user name

    and password.@) program7error 55555555 pl2s/l has an internal problem.C) storage7error 55555555 pl2s/l ran out of memory or memory iscorrupted.) to7many7row 555555555single row select returned more than one row.K) value7error 55555555 arithmetic,conversion,truncation or si'e

    constraint error occurred.1L) 'ero7devided 55555555 attempted to divided by 'ero.'!*53*:

    %eclare 0 name the eception3aise 0 eplicitly raise the eception by using the raise statements3eference0 eception handing section.%he !aise#pplicationrror"roce+$re:

    Hou can use this procedure to issue user5defined error messages from stored sub programs.

    Hou can report errors to your applications and avoid returning unhandled eceptions.Raise(Application()rror*error(num+er,message-,.true/0alse12

  • 8/14/2019 36401672-Oracle-DBA

    21/67

    Error numberbetween 54LLLL to 54LKKKpragma eGceptioninit?

    It tells the compiler to associate an eception with an oracle error. #o get an error message of aspecific oracle error.E0 pragma eception7init(eception name, oracle error number)Gample for Gceptions?

    1) Chec/ the recor+ is eGist or not?

    %eclareE empF rowtypeNegine.empno 0U

  • 8/14/2019 36401672-Oracle-DBA

    22/67

    ,9)What is the maGim$m n$m&er of statements that can &e specifie+ in a trigger statement?

    One.,2) 'tore+ proce+$re?

    tored procedure is a se/uence of statements that perform specific function.8,) What is proce+$re?

    5555 is a named pl2s/l bloc& to perform a specific tas&.5555 " procedure may have %? statements.5555 It may or may not return a value.5555 *rocedure can return more than one value.Gample for proce+$re

    1)#o accept the year as a parameter and list emp belong to the year68reate or replace

    *rocedure empy(y number) is8ursor emp7cursor iselect G from emp where to7char(hiredate,$yyyy$)U$y$Emp7record empFrowtypeNegin=or emp7record in emp7cursor loop

    *rint (emp7record.empno)*rint (emp7record.ename)*rint (emp7record.sal)End loopEndO$tp$t :

    var emp numberNegin0emp 0U Y149:$End

    Eec empy(0emp)*rint empy84) What is f$nction?

    5555 is a named pl2s/l bloc& to perform a specific tas&, is mainly used for calculation purpose.5555 " function is called as part of an eception.5555 Every function should return a valueGample for f$nction

    8reate or replace=unction get7sal(p7id in emp.emp7noF type)3eturn number

    Isv7sal emp.salFtype 0ULNeginelect salary into v7salary=rom empWhere emp7no U p7id3eturn v7salaryEnd get7salEndO$tp$t :

  • 8/14/2019 36401672-Oracle-DBA

    23/67

    var g7sal numberEec 0g7sal 0U get7sal(KK)*rint g7salary=.Can f$nctions &e overloa+e+ ?

    Kes.

    10.Can 2 f$nctions have same name M inp$t parameters &$t +iffer only &y ret$rn +atatype

    3o.

    88) What is the pac/age?

    5555 !roup logically related pl2s/l types, items and subprograms.1)pac&age specification4)pac&age body

    Advantages of a package:

    odularity

    ,asier Application Desi$n

    n-ormation

  • 8/14/2019 36401672-Oracle-DBA

    24/67

    5555 " trigger is eecuted implicitly when ever a particular event tas& places. "nd is nothing but aevent.5555 #he triggering event is a %? (insert, update, delete) operations on a data base table fires whenever a +ata event;s$ch as *() or system event;s$ch as login or sh$t+own)

    occ$rs on a schema or +ata&ase

    %rigger timing :1) before4) after9) instead of ( this is used for views)%riggering events0 1) insert4)update9) delete%rigger type : 1) statement level4) row level.5iring se$ence of +ata&ase triggers

    1)before statement trigger4)before row trigger9)after row trigger:)after statement trigger

    G:1) Create or replace trigger sec$reemp

    NeforeInsert on empNeginIf (to7char(sysdate,$dy$) in(Ysat$,$sun$)) or#o7char(sysdate,$hh4:0mi$)+ot between $L0LL$ and $10LL$)#hen raise7application7error(54L;LL,$u can insert in the office timings$)End if

    EndG : 2) write a program to all transitions with name smith?

    8reate or replace#rigger trigger7nameNefore insert or update or deleteOn emp

    =or each rowWhen (old.ename U$smith$ or+ew.ename U$smith$)Negin

    3aise7application7error(54LLL9,$smith$)End8) *ifference &etween triggers an+ proce+$res?

    %efined with create trigger %efined with create proce+$re

    #he data dictionary contains source codein the user7triggers.

    %ata dictionary contains source code inuser7source

    Implicitly invo&ed Eplicitly invo&ed

  • 8/14/2019 36401672-Oracle-DBA

    25/67

    8ommit, save point and rollbac& are notallowed(#8?)

    #hose are allowed

    8

  • 8/14/2019 36401672-Oracle-DBA

    26/67

    Composite *atatypes0

    = >/?!Q/ @A#/,!

    = >/?!Q/ :,CO:D!

    5ested @A#/,

    5VA::AB

    What is the se$ence of f$nctions N gro$p &yDhavingDor+er&y in a select statements ?

    !elect..

    roup (y

  • 8/14/2019 36401672-Oracle-DBA

    27/67

    you as&ed for the columns called =irst+ame, ?ast+ame, "ddress, 8ity, and tate. +ote that column namesand table names do not have spaces...they must be typed as one word and that the statement ends with a

    semicolon (). #he general form for a E?E8# statement, retrieving all of the rows in the table is0E?E8# 8olumn+ame, 8olumn+ame, ...

    =3O #able+ame

    #o get all columns of a table without typing all column names, use0E?E8# G =3O #able+ame

    Each database management system (%N) and database software has different methods for logging in to

    the database and entering >? commands see the local computer ]guru] to help you get onto the system, sothat you can use >?.

    8onditional election #o further discuss the E?E8# statement, let\s loo& at a new eample table (for

    hypothetical purposes only)0

    Employeetatistics#able

    EmployeeI%+o alary Nenefits *ositionL1L C;LLL 1;LLL anager

    1L; @;LLL 1;LLL anager

    1;4 @LLLL 1;LLL anager41; @LLLL 14;LL anager4:: ;LLLL 14LLL taff

    9LL :;LLL 1LLLL taff99; :LLLL 1LLLL taff

    :LL 94LLL C;LL Entry5?evel::1 4LLL C;LL Entry5?evel

    3elational Operators

    #here are si 3elational Operators in >?, and after introducing them, we\ll see how they\re used0U E/ual

    ^ or _U (seemanual) +ot E/ual

    ^ ?ess #hanP !reater #han

    ^U ?ess #han or E/ual #oPU !reater #han or E/ual

    #o

    #he WAE3E clause is used to specify that only certain rows of the table are displayed, based on the criteria

    described in that WAE3E clause. It is most easily understood by loo&ing at a couple of eamples. If youwanted to see the E*?OHEEI%+O\s of those ma&ing at or over `;L,LLL, use the following0

    E?E8# E*?OHEEI%+O=3O E*?OHEE#"#I#I8#"N?EWAE3E "?"3H PU ;LLLL

    +otice that the PU (greater than or e/ual to) sign is used, as we wanted to see those who made greater than

    `;L,LLL, or e/ual to `;L,LLL, listed together. #his displays0E*?OHEEI%+O

    555555555555L1L

    1L;

  • 8/14/2019 36401672-Oracle-DBA

    28/67

    1;441;

    4::

    #he WAE3E description, "?"3H PU ;LLLL, is &nown as a condition (an operation which evaluates to #ruor =alse). #he same can be done for tet columns0

    E?E8# E*?OHEEI%+O=3O E*?OHEE#"#I#I8#"N?E

    WAE3E *OI#IO+ U \anager\#his displays the I% +umbers of all anagers. !enerally, with tet columns, stic& to e/ual to or not e/ual to

    and ma&e sure that any tet that appears in the statement is surrounded by single /uotes (\). +ote0 *osition isnow an illegal identifier because it is now an unused, but reserved, &eyword in the >?5K4 standard.

    ore 8omple 8onditions0 8ompound 8onditions 2 ?ogical Operators

    #he "+% operator Joins two or more conditions, and displays a row only if that row\s data satisfies "??conditions listed (i.e. all conditions hold true). =or eample, to display all staff ma&ing over `:L,LLL, use0

    E?E8# E*?OHEEI%+O=3O E*?OHEE#"#I#I8#"N?E

    WAE3E "?"3H P :LLLL "+% *OI#IO+ U \taff\

    #he O3 operator Joins two or more conditions, but returns a row if "+H of the conditions listed hold true. #see all those who ma&e less than `:L,LLL or have less than `1L,LLL in benefits, listed together, use thefollowing /uery0

    E?E8# E*?OHEEI%+O

    =3O E*?OHEE#"#I#I8#"N?EWAE3E "?"3H :LLLL O3 NE+E=I# ^ 1LLLL

    "+% < O3 can be combined, for eample0E?E8# E*?OHEEI%+O

    =3O E*?OHEE#"#I#I8#"N?EWAE3E *OI#IO+ U \anager\ "+% "?"3H P @LLLL O3 NE+E=I# P 14LLL

    =irst, >? finds the rows where the salary is greater than `@L,LLL and the position column is e/ual toanager, then ta&ing this new list of rows, >? then sees if any of these rows satisfies the previous "+%

    condition or the condition that the Nenefits column is greater than `14,LLL. ubse/uently, >? only displaysthis second new list of rows, &eeping in mind that anyone with Nenefits over `14,LLL will be included as the

    O3 operator includes a row if either resulting condition is #rue. "lso note that the "+% operation is donefirst.#o generali'e this process, >? performs the "+% operation(s) to determine the rows where the "+%

    operation(s) hold true (remember0 all of the conditions are true), then these results are used to compare withthe O3 conditions, and only display those remaining rows where any of the conditions Joined by the O3

    operator hold true (where a condition or result from an "+% is paired with another condition or "+% result

    to use to evaluate the O3, which evaluates to true if either value is true). athematically, >? evaluates allof the

    conditions, then evaluates the "+% ]pairs], and then evaluates the O3\s (where both operators evaluate leftto right).#o loo& at an eample, for a given row for which the %N is evaluating the >? statement Where clause t

    determine whether to include the row in the /uery result (the whole Where clause evaluates to #rue), the%N has evaluated all of the conditions, and is ready to do the logical comparisons on this result0

    #rue "+% =alse O3 #rue "+% #rue O3 =alse "+% =alse=irst simplify the "+% pairs0

    =alse O3 #rue O3 =alse+ow do the O3\s, left to right0

    #rue O3 =alse

  • 8/14/2019 36401672-Oracle-DBA

    29/67

    #rue#he result is #rue, and the row passes the /uery conditions. Ne sure to see the net section on +O#\s, and the

    order of logical operations. I hope that this section has helped you understand "+%\s or O3\s, as it\s adifficult subJect to eplain briefly. #o perform O3\s before "+%\s, li&e if you wanted to see a list of

    employees ma&ing a large salary (`;L,LLL)or have a large benefit pac&age (`1L,LLL), and that happen to be a manager, use parentheses0

    E?E8# E*?OHEEI%+O

    =3O E*?OHEE#"#I#I8#"N?EWAE3E *OI#IO+ U \anager\ "+% ("?"3H P ;LLLL O3 NE+E=I# P 1LLLL)

    I+ < NE#WEE+

    "n easier method of using compound conditions uses I+ or NE#WEE+. =or eample, if you wanted to list

    all managers and staff0E?E8# E*?OHEEI%+O

    =3O E*?OHEE#"#I#I8#"N?E

    WAE3E *OI#IO+ I+ (\anager\, \taff\)

    or to list those ma&ing greater than or e/ual to `9L,LLL, but less than or e/ual to `;L,LLL, use0

    E?E8# E*?OHEEI%+O=3O E*?OHEE#"#I#I8#"N?EWAE3E "?"3H NE#WEE+ 9LLLL "+% ;LLLL

    #o list everyone not in this range, try0

    @E?E8# E*?OHEEI%+O

    =3O E*?OHEE#"#I#I8#"N?EWAE3E "?"3H +O# NE#WEE+ 9LLLL "+% ;LLLL

    imilarly, +O# I+ lists all rows ecluded from the I+ list."dditionally, +O#\s can be thrown in with "+%\s < O3\s, ecept that +O# is a unary operator (evaluates

    onecondition, reversing its value, whereas, "+%\s < O3\s evaluate two conditions), and that all +O#\s are

    performed before any "+%\s or O3\s.>? Order of ?ogical Operations (each operates from left to right)

    1. +O#4. "+%

    9. O3-sing ?IBE

    ?oo& at the Employeetatistics#able, and say you wanted to see all people whose last names started with

    ]]try0

    E?E8# E*?OHEEI%+O=3O E*?OHEE"%%3E#"N?EWAE3E ?"#+"E ?IBE \F\

    #he percent sign (F) is used to represent any possible character (number, letter, or punctuation) or set ofcharacters that might appear after the ]]. #o find those people with ?ast+ame\s ending in ]], use \F\, or i

    you wanted the ]] in the middle of the word, try \FF\. #he \F\ can be used for any characters in the sameposition relative to the given characters. +O# ?IBE displays rows not fitting the given description. Other

    possibilities of using ?IBE, or any of these discussed conditionals, are available, though it depends on what%N you are using as usual, consult a manual or your system manager or administrator for the available

    features on your system, or Just to ma&e sure that what you are trying to do is available and allowed. #his

  • 8/14/2019 36401672-Oracle-DBA

    30/67

  • 8/14/2019 36401672-Oracle-DBA

    31/67

    each other, because the uni/ue OwnerI% column will be used throughout the database to trac& the owners,rather than the names.

    " foreign &ey is a column in a table where that column is a primary &ey of another table, which means thatany

    data in a foreign &ey column must have corresponding data in the other table where that column is theprimary

    &ey. In %N5spea&, this correspondence is &nown as referential integrity. =or eample, in the "nti/uestable, both the NuyerI% and ellerI% are foreign &eys to the primary &ey of the "nti/ueOwners table

    (OwnerI% for purposes of argument, one has to be an "nti/ue Owner before one can buy or sell any items),as, in both tables, the I% rows are used to identify the owners or buyers and sellers, and that the OwnerI% is

    theprimary &ey of the "nti/ueOwners table. In other words, all of this ]I%] data is used to refer to the owners,

    buyers, or sellers of anti/ues, themselves, without having to use the actual names.

    *erforming a Toin#he purpose of these &eys is so that data can be related across tables, without having to repeat data in every

    table55this is the power of relational databases. =or eample, you can find the names of those who bought a

    chair without having to list the full name of the buyer in the "nti/ues table...you can get the name by relatingthose who bought a chair with the names in the "nti/ueOwners table through the use of the OwnerI%, which

    relates the data in the two tables. #o find the names of those who bought a chair, use the following /uery0

    E?E8# OW+E3?"#+"E, OW+E3=I3#+"E=3O "+#I>-EOW+E3, "+#I>-EWAE3E N-HE3I% U OW+E3I% "+% I#E U \8hair\

    +ote the following about this /uery...notice that both tables involved in the relation are listed in the =3Oclause of the statement. In the WAE3E clause, first notice that the I#E U \8hair\ part restricts the listing to

    those who have bought (and in this eample, thereby own) a chair. econdly, notice how the I% columns arerelated from one table to the net by use of the N-HE3I% U OW+E3I% clause. Only where I%\s match

    acrosstables and the item purchased is a chair (because of the "+%), will the names from the "nti/ueOwners table

    belisted. Necause the Joining condition used an e/ual sign, this Join is called an e/uiJoin. #he result of this

    /uery istwo names0 mith, Nob < =owler, am.

    %ot notation refers to prefiing the table names to column names, to avoid ambiguity, as follows0E?E8# "+#I>-EOW+E3.OW+E3?"#+"E, "+#I>-EOW+E3.OW+E3=I3#+"E

    =3O "+#I>-EOW+E3, "+#I>-EWAE3E "+#I>-E.N-HE3I% U "+#I>-EOW+E3.OW+E3I% "+% "+#I>-E.I#E U \8hair\

    "s the column names are different in each table, however, this wasn\t necessary.%I#I+8# and Eliminating %uplicates

    ?et\s say that you want to list the I% and names of only those people who have sold an anti/ue. Obviously,

    youwant a list where each seller is only listed once55you don\t want to &now how many anti/ues a person sold,

    Justthe fact that this person sold one (for counts, see the "ggregate =unction section below). #his means that youwill need to tell >? to eliminate duplicate sales rows, and Just list each person only once. #o do this, use th

    %I#I+8# &eyword.

    K

    =irst, we will need an e/uiJoin to the "nti/ueOwners table to get the detail data of the person\s ?ast+ame an=irst+ame. Aowever, &eep in mind that since the ellerI% column in the "nti/ues table is a foreign &ey to

    the

  • 8/14/2019 36401672-Oracle-DBA

    32/67

    "nti/ueOwners table, a seller will only be listed if there is a row in the "nti/ueOwners table listing the I%and

    names. We also want to eliminate multiple occurrences of the ellerI% in our listing, so we use %I#I+8#on

    the column where the repeats may occur (however, it is generally not necessary to strictly put the %istinct infront

    of the column name).#o throw in one more twist, we will also want the list alphabeti'ed by ?ast+ame, then by =irst+ame (on a

    ?ast+ame tie). #hus, we will use the O3%E3 NH clause0E?E8# %I#I+8# E??E3I%, OW+E3?"#+"E, OW+E3=I3#+"E

    =3O "+#I>-E, "+#I>-EOW+E3WAE3E E??E3I% U OW+E3I%

    O3%E3 NH OW+E3?"#+"E, OW+E3=I3#+"E

    In this eample, since everyone has sold an item, we will get a listing of all of the owners, in alphabeticalorder

    by last name. =or future reference (and in case anyone as&s), this type of Join is considered to be in the

    categoryof inner Joins.

    "liases < In2ub/ueries

    In this section, we will tal& about "liases, In and the use of sub/ueries, and how these can be used in a 95tableeample. =irst, loo& at this /uery which prints the last name of those owners who have placed an order and

    what the order is, only listing those orders which can be filled (that is, there is a buyer who owns that ordereditem)0

    E?E8# OW+.OW+E3?"#+"E ?ast +ame, O3%.I#E%EI3E% Item Ordered=3O O3%E3 O3%, "+#I>-EOW+E3 OW+

    WAE3E O3%.OW+E3I% U OW+.OW+E3I%"+% O3%.I#E%EI3E% I+

    (E?E8# I#E=3O "+#I>-E)

    #his gives0?ast +ame Item Ordered

    555555555 555555555555mith #able

    mith %es&"&ins 8hair

    ?awson irror#here are several things to note about this /uery0

    1. =irst, the ]?ast +ame] and ]Item Ordered] in the elect lines gives the headers on the report.

    4. #he OW+ < O3% are aliases these are new names for the two tables listed in the =3O clause thatare used as prefies for all dot notations of column names in the /uery (see above). #his eliminates

    ambiguity, especially in the e/uiJoin WAE3E clause where both tables have the column namedOwnerI%, and the dot notation tells >? that we are tal&ing about two different OwnerI%\s from the

    1L

    two different tables.

    9. +ote that the Orders table is listed first in the =3O clause this ma&es sure listing is done off of thattable, and the "nti/ueOwners table is only used for the detail information (?ast +ame).

    :. ost importantly, the "+% in the WAE3E clause forces the In ub/uery to be invo&ed (]U "+H] or

  • 8/14/2019 36401672-Oracle-DBA

    33/67

    ]U OE] are two e/uivalent uses of I+). What this does is, the sub/uery is performed, returning all ofthe Items owned from the "nti/ues table, as there is no WAE3E clause. #hen, for a row from the

    Orders table to be listed, the Item%esired must be in that returned list of Items owned from the "nti/uestable, thus listing an item only if the order can be filled from another owner. Hou can thin& of it this way0

    the sub/uery returns a set of Items from which each Item%esired in the Orders table is compared the Incondition is true only if the Item%esired is in that returned set from the "nti/ues table.

    ;. "lso notice, that in this case, that there happened to be an anti/ue available for each onedesired...obviously, that won\t always be the case. In addition, notice that when the I+, ]U "+H], or ]U

    OE] is used, that these &eywords refer to any possible row matches, not column matches...that is,you cannot put multiple columns in the sub/uery elect clause, in an attempt to match the column in the

    outer Where clause to one of multiple possible column values in the sub/uery only one column can belisted in the sub/uery, and the possible match comes from multiple row values in that one column, not

    vice5versa.

    Whew_ #hat\s enough on the topic of comple E?E8# /ueries for now. +ow on to other >? statements.iscellaneous >? tatements

    "ggregate =unctions

    I will discuss five important aggregate functions0 -, "!, ", I+, and 8O-+#. #hey are calledaggregate functions because they summari'e the results of a /uery, rather than listing all of the rows.

    - () gives the total of all the rows, satisfying any conditions, of the given column, where the given

    column is numeric."! () gives the average of the given column." () gives the largest figure in the given column.

    I+ () gives the smallest figure in the given column.8O-+#(G) gives the number of rows satisfying the conditions.

    ?oo&ing at the tables at the top of the document, let\s loo& at three eamples0E?E8# -("?"3H), "!("?"3H)

    =3O E*?OHEE#"#I#I8#"N?E#his /uery shows the total of all salaries in the table, and the average salary of all of the entries in the table.

    E?E8# I+(NE+E=I#)=3O E*?OHEE#"#I#I8#"N?E

    WAE3E *OI#IO+ U \anager\#his /uery gives the smallest figure of the Nenefits column, of the employees who are anagers, which is

    14;LL.E?E8# 8O-+#(G)

    11

    =3O E*?OHEE#"#I#I8#"N?E

    WAE3E *OI#IO+ U \taff\

    #his /uery tells you how many employees have taff status (9).iews

    In >?, you might (chec& your %N") have access to create views for yourself. What a view does is to allowyou to assign the results of a /uery to a new, personal table, that you can use in other /ueries, where this newtable is given the view name in your =3O clause. When you access a view, the /uery that is defined in you

    view creation statement is performed (generally), and the results of that /uery loo& Just li&e another table inthe

    /uery that you wrote invo&ing the view. =or eample, to create a view083E"#E IEW "+#IEW " E?E8# I#E%EI3E% =3O O3%E3

    +ow, write a /uery using this view as a table, where the table is Just a listing of all Items %esired from theOrders table0

    E?E8# E??E3I%

  • 8/14/2019 36401672-Oracle-DBA

    34/67

    =3O "+#I>-E, "+#IEWWAE3E I#E%EI3E% U I#E

    #his /uery shows all ellerI%\s from the "nti/ues table where the Item in that table happens to appear in the"ntview view, which is Just all of the Items %esired in the Orders table. #he listing is generated by going

    throughthe "nti/ue Items one5by5one until there\s a match with the "ntview view. iews can be used to restrict

    database access, as well as, in this case, simplify a comple /uery.8reating +ew #ables

    "ll tables within a database must be created at some point in time...let\s see how we would create the Orderstable0

    83E"#E #"N?E O3%E3(OW+E3I% I+#E!E3 +O# +-??,

    I#E%EI3E% 8A"3(:L) +O# +-??)

    #his statement gives the table name and tells the %N about each column in the table. *lease note that thisstatement uses generic data types, and that the data types might be different, depending on what %N you

    are

    using. "s usual, chec& local listings. ome common generic data types are08har() 5 " column of characters, where is a number designating the maimum number of characters

    allowed (maimum length) in the column.

    Integer 5 " column of whole numbers, positive or negative.%ecimal(, y) 5 " column of decimal numbers, where is the maimum length in digits of the decimalnumbers in this column, and y is the maimum number of digits allowed after the decimal point. #he

    maimum (:,4) number would be KK.KK.%ate 5 " date column in a %N5specific format.

    ?ogical 5 " column that can hold only two values0 #3-E or ="?E.

    14

    One other note, the +O# +-?? means that the column must have a value in each row. If +-?? was used,that

    column may be left empty in a given row."ltering #ables

    ?et\s add a column to the "nti/ues table to allow the entry of the price of a given Item (*arenthesesoptional)0

    "?#E3 #"N?E "+#I>-E "%% (*3I8E %E8I"?(,4) +-??)#he data for this new column can be updated or inserted as shown later.

    "dding %ata#o insert rows into a table, do the following0

    I+E3# I+#O "+#I>-E "?-E (41, L1, \Ottoman\, 4LL.LL)

    #his inserts the data into the table, as a new row, column5by5column, in the pre5defined order. Instead, let\schange the order and leave *rice blan&0

    I+E3# I+#O "+#I>-E (N-HE3I%, E??E3I%, I#E)"?-E (L1, 41, \Ottoman\)%eleting %ata

    ?et\s delete this new row bac& out of the database0%E?E#E =3O "+#I>-E

    WAE3E I#E U \Ottoman\Nut if there is another row that contains \Ottoman\, that row will be deleted also. ?et\s delete all rows (one, in

    this case) that contain the specific data we added before0%E?E#E =3O "+#I>-E

    WAE3E I#E U \Ottoman\ "+% N-HE3I% U L1 "+% E??E3I% U 41

  • 8/14/2019 36401672-Oracle-DBA

    35/67

    -pdating %ata?et\s update a *rice into a row that doesn\t have a price listed yet0

    -*%"#E "+#I>-E E# *3I8E U ;LL.LL WAE3E I#E U \8hair\#his sets all 8hair\s *rices to ;LL.LL. "s shown above, more WAE3E conditionals, using "+%, must be use

    to limit the updating to more specific rows. "lso, additional columns may be set by separating e/ualstatements

    with commas.iscellaneous #opics

    Indees

    19

    Indees allow a %N to access data /uic&er (please note0 this feature is nonstandard2not available on all

    systems). #he system creates this internal data structure (the inde) which causes selection of rows, when thselection is based on indeed columns, to occur faster. #his inde tells the %N where a certain row is in

    the

    table given an indeed5column value, much li&e a boo& inde tells you what page a given word appears. ?etcreate an inde for the OwnerI% in the "nti/ueOwners table0

    83E"#E I+%E OI%7I% O+ "+#I>-EOW+E3 (OW+E3I%)

    +ow on the names083E"#E I+%E +"E7I% O+ "+#I>-EOW+E3 (OW+E3?"#+"E, OW+E3=I3#+"E)#o get rid of an inde, drop it0

    %3O* I+%E OI%7I%Ny the way, you can also ]drop] a table, as well (careful_55that means that your table is deleted). In the

    secondeample, the inde is &ept on the two columns, aggregated together55strange behavior might occur in this

    situation...chec& the manual before performing such an operation.ome %N\s do not enforce primary &eys in other words, the uni/ueness of a column is not enforced

    automatically. What that means is, if, for eample, I tried to insert another row into the "nti/ueOwners tablewith an OwnerI% of L4, some systems will allow me to do that, even though we do not, as that column is

    supposed to be uni/ue to that table (every row value is supposed to be different). One way to get around thatis

    to create a uni/ue inde on the column that we want to be a primary &ey, to force the system to enforceprohibition of duplicates0

    83E"#E -+I>-E I+%E OI%7I% O+ "+#I>-EOW+E3 (OW+E3I%)!3O-* NH < A"I+!

    One special use of !3O-* NH is to associate an aggregate function (especially 8O-+# counting thenumber

    of rows in each group) with groups of rows. =irst, assume that the "nti/ues table has the *rice column, and

    each row has a value for that column. We want to see the price of the most epensive item bought by eachowner. We have to tell >? to group each owner\s purchases, and tell us the maimum purchase price0

    E?E8# N-HE3I%, "(*3I8E)=3O "+#I>-E!3O-* NH N-HE3I%

    +ow, say we only want to see the maimum purchase price if the purchase is over `1LLL, so we use theA"I+! clause0

    E?E8# N-HE3I%, "(*3I8E)=3O "+#I>-E

    !3O-* NH N-HE3I%A"I+! *3I8E P 1LLL

    ore ub/ueries

  • 8/14/2019 36401672-Oracle-DBA

    36/67

    1:

    "nother common usage of sub/ueries involves the use of operators to allow a Where condition to include th

    elect output of a sub/uery. =irst, list the buyers who purchased an epensive item (the *rice of the item is`1LL

    greater than the average price of all items purchased)0E?E8# N-HE3I%

    =3O "+#I>-EWAE3E *3I8E P

    (E?E8# "!(*3I8E) V 1LL=3O "+#I>-E)

    #he sub/uery calculates the average *rice, plus `1LL, and using that figure, an OwnerI% is printed for every

    item costing over that figure. One could use %I#I+8# N-HE3I%, to eliminate duplicates.?ist the ?ast +ames of those in the "nti/ueOwners table, O+?H if they have bought an item0

    E?E8# OW+E3?"#+"E

    =3O "+#I>-EOW+E3WAE3E OW+E3I% I+

    (E?E8# %I#I+8# N-HE3I%

    =3O "+#I>-E)#he sub/uery returns a list of buyers, and the ?ast +ame is printed for an "nti/ue Owner if and only if theOwner\s I% appears in the sub/uery list (sometimes called a candidate list). +ote0 on some %N\s, e/uals

    can be used instead of I+, but for clarity\s sa&e, since a set is returned from the sub/uery, I+ is the betterchoice.

    =or an -pdate eample, we &now that the gentleman who bought the boo&case has the wrong =irst +ame inthe

    database...it should be Tohn0-*%"#E "+#I>-EOW+E3

    E# OW+E3=I3#+"E U \Tohn\WAE3E OW+E3I% U

    (E?E8# N-HE3I%=3O "+#I>-E

    WAE3E I#E U \Noo&case\)=irst, the sub/uery finds the NuyerI% for the person(s) who bought the Noo&case, then the outer /uery

    updateshis =irst +ame.

    3emember this rule about sub/ueries0 when you have a sub/uery as part of a WAE3E condition, theelect clause in the sub/uery must have columns that match in number and type to those in the Where clause

    of

    the outer /uery. In other words, if you have ] WAE3E 8olumn+ame U (E?E8#...)], the elect must haveonly one column in it, to match the 8olumn+ame in the outer Where clause, and they must match in type

    (bothbeing integers, both being character strings, etc.).EI# < "??

    1;

    EI# uses a sub/uery as a condition, where the condition is #rue if the sub/uery returns any rows, and

    =alseif the sub/uery does not return any rows this is a nonintuitive feature with few uni/ue uses. Aowever, if a

    prospective customer wanted to see the list of Owners only if the shop dealt in 8hairs, try0

  • 8/14/2019 36401672-Oracle-DBA

    37/67

  • 8/14/2019 36401672-Oracle-DBA

    38/67

    WAE3E N-HE3I% +O# I+(E?E8# OW+E3I%

    =3O O3%E3)#he first /uery does a Join to list any owners who are in both tables, and putting a tag line after the I%

    repeatingthe /uote. #he -+IO+ merges this list with the net list. #he second list is generated by first listing those

    I%\s notin the Orders table, thus generating a list of I%\s ecluded from the Join /uery. #hen, each row in the

    "nti/uestable is scanned, and if the NuyerI% is not in this eclusion list, it is listed with its /uoted tag. #here might b

    aneasier way to ma&e this list, but it\s difficult to generate the informational /uoted strings of tet.

    #his concept is useful in situations where a primary &ey is related to a foreign &ey, but the foreign &ey value

    forsome primary &eys is +-??. =or eample, in one table, the primary &ey is a salesperson, and in another tabl

    is

    customers, with their salesperson listed in the same row. Aowever, if a salesperson has no customers, thatperson\s name won\t appear in the customer table. #he outer Join is used if the listing of all salespersons is to

    be

    printed, listed with their customers, whether the salesperson has a customer or not55that is, no customer isprinted (a logical +-?? value) if the salesperson has no customers, but is in the salespersons table.Otherwise,

    the salesperson will be listed with each customer."nother important related point about +ulls having to do with Joins0 the order of tables listed in the =rom

    clauseis very important. #he rule states that >? ]adds] the second table to the first the first table listed has any

    rowswhere there is a null on the Join column displayed if the second table has a row with a null on the Join

    column,that row from the table listed second does not get Joined, and thus included with the first table\s row data.

    #his isanother occasion (should you wish that data included in the result) where an outer Join is commonly used.

    #heconcept of nulls is important, and it may be worth your time to investigate them further.

    E+O-!A >-E3IE___ you say6...now on to something completely different...Embedded >?55an ugly eample (do not write a program li&e this...for purposes of

    argument O+?H)2G 5#o get right to it, here is an eample program that uses Embedded

    >?. Embedded >? allows programmers to connect to a database and

    include >? code right in the program, so that their programs canuse, manipulate, and process data from a database.

    5#his eample 8 *rogram (using Embedded >?) will print a report.5#his program will have to be precompiled for the >? statements,before regular compilation.

    5#he EE8 >? parts are the same (standard), but the surrounding 8code will need to be changed, including the host variable

    declarations, if you are using a different language.5Embedded >? changes from system to system, so, once again, chec&

    local documentation, especially variable declarations and logging

    1C

  • 8/14/2019 36401672-Oracle-DBA

    39/67

    in procedures, in which networ&, %N, and operating system

    considerations are crucial. G22GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG2

    2G #AI *3O!3" I +O# 8O*I?"N?E O3 EE8-#"N?E G22G I# I =O3 E"*?E *-3*OE O+?H G2

    2GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG2Qinclude

    2G #his section declares the host variables these will be thevariables your program uses, but also the variable >? will put

    values in or ta&e values out. G2EE8 >? NE!I+ %E8?"3E E8#IO+

    int NuyerI%

    char =irst+ame1LLX, ?ast+ame1LLX, Item1LLXEE8 >? E+% %E8?"3E E8#IO+

    2G #his includes the >?8" variable, so that some error chec&ing can be done. G2

    EE8 >? I+8?-%E >?8"main()

    2G #his is a possible way to log into the database G2

    EE8 >? 8O++E8# -serI%2*assword2G #his code either says that you are connected or chec&s if an errorcode was generated, meaning log in was incorrect or not possible. G2

    if(s/lca.s/lcode) printf(*rinter, ]Error connecting to database server.Dn])

    eit()

    printf(]8onnected to database server.Dn])2G #his declares a ]8ursor]. #his is used when a /uery returns more

    than one row, and an operation is to be performed on each rowresulting from the /uery. With each row established by this /uery,

    I\m going to use it in the report. ?ater, ]=etch] will be used topic& off each row, one at a time, but for the /uery to actually

    be eecuted, the ]Open] statement is used. #he ]%eclare] Justestablishes the /uery. G2

    EE8 >? %E8?"3E Item8ursor 8-3O3 =O3E?E8# I#E, N-HE3I%

    =3O "+#I>-EO3%E3 NH I#E

    EE8 >? O*E+ Item8ursor

    2G V55 Hou may wish to put a similar error chec&ing bloc& here 55V G22G =etch puts the values of the ]net] row of the /uery in the host

    variables, respectively. Aowever, a ]priming fetch] (programmingtechni/ue) must first be done. When the cursor is out of data, as/lcode will be generated allowing us to leave the loop. +otice

    that, for simplicity\s sa&e, the loop will leave on any s/lcode,

    1

    even if it is an error code. Otherwise, specific code chec&ing mustbe performed. G2

    EE8 >? =E#8A Item8ursor I+#O 0Item, 0NuyerI%

  • 8/14/2019 36401672-Oracle-DBA

    40/67

    while(_s/lca.s/lcode) 2G With each row, we will also do a couple of things. =irst, bump the

    price up by `; (dealer\s fee) and get the buyer\s name to put inthe report. #o do this, I\ll use an -pdate and a elect, before

    printing the line on the screen. #he update assumes however, thata given buyer has only bought one of any given item, or else the

    price will be increased too many times. Otherwise, a ]3owI%] logicwould have to be used (see documentation). "lso notice the colon

    before host variable names when used inside of >? statements. G2EE8 >? -*%"#E "+#I>-E

    E# *3I8E U *3I8E V ;WAE3E I#E U 0Item "+% N-HE3I% U 0NuyerI%

    EE8 >? E?E8# OW+E3=I3#+"E, OW+E3?"#+"E

    I+#O 0=irst+ame, 0?ast+ame=3O "+#I>-EOW+E3

    WAE3E N-HE3I% U 0NuyerI%

    printf(]F4;s F4;s F4;s], =irst+ame, ?ast+ame, Item)2G -gly report55for eample purposes only_ !et the net row. G2

    EE8 >? =E#8A Item8ursor I+#O 0Item, 0NuyerI%

    2G 8lose the cursor, commit the changes (see below), and eit theprogram. G2

    EE8 >? 8?OE Item8ursorEE8 >? 8OI# 3E?E"E

    eit()

    8ommon >? >uestions < "dvanced #opics1. Why can\t I Just as& for the first three rows in a table6 55Necause in relational databases, rows are

    inserted in no particular order, that is, the system inserts them in an arbitrary order so, you can onlyre/uest rows using valid >? features, li&e O3%E3 NH, etc.

    4. What is this %%? and %? I hear about6 55%%? (%ata %efinition ?anguage) refers to (in >?) the8reate #able statement...%? (%ata anipulation ?anguage) refers to the elect, -pdate, Insert, and

    %elete statements. "lso, >?, referring to elect statements, stands for >uery anipulation?anguage.

    9. "ren\t database tables Just files6 55Well, %N\s store data in files declared by system managersbefore new tables are created (on large systems), but the system stores the data in a special format, and

    may spread data from one table over several files. In the database world, a set of files created for adatabase is called a tablespace. In general, on small systems, everything about a database (definitions

    and all table data) is &ept in one file.

    :. (3elated /uestion) "ren\t database tables Just li&e spreadsheets6 55+o, for two reasons. =irst,

    1K

    spreadsheets can have data in a cell, but a cell is more than Just a row5column5intersection. %epending

    on your spreadsheet software, a cell might also contain formulas and formatting, which database tablescannot have (currently). econdly, spreadsheet cells are often dependent on the data in other cells. In

    databases, ]cells] are independent, ecept that columns are logically related (hopefully together a rowof columns describe an entity), and, other than primary &ey and foreign &ey constraints, each row in a

    table is independent from one another.;. Aow do I import a tet file of data into a database6 55Well, you can\t do it directly...you must use a

    utility, such as Oracle\s >?G?oader, or write a program to load the data into the database. " program

  • 8/14/2019 36401672-Oracle-DBA

    41/67

    to do this would simply go through each record of a tet file, brea& it up into columns, and do an Insertinto the database.

    @. What web sites and computer boo&s would you recommend for more information about >? anddatabases6 55=irst, loo& at the sites at the bottom of this page. I would especially suggest the following0

    %N Ingredients (more theorical topics), %N ?ab2?in&s (comprehensive academic %N lin& listing),#utorial *age (listing of other tutorials), and mini>? (more information about the best &nown free

    %N)."lso, if you wish to practice >? on an interactive site (using Tava technologies), I highly recommend

    =ran& #orres\ (torresfuswest.net) site at http022s/lcourse.com and its new se/uel (so to spea&) site athttp022s/lcourse4.com. =ran& did an outstanding Job with his site, and if you have a recent release

    browser, it\s definitely worth a visit. In addition, point your browser to www.topica.com, and subscribeto their >? e5mail #ips of the %ay...they are outstanding #im >uinlan goes into topics that I can\t

    even begin to go into here, such inde data structures (N5trees and NV5trees) and Join algorithms, so

    advanced I# 3%N pros will get a daily insight into these data management tools.-nfortunately, there is not a great deal of information on the web about >? the list I have below is

    fairly comprehensive (definitely representative). "s far as boo&s are concerned, I would suggest (for

    beginners to intermediate5level) ]Oracle0 #he 8omplete 3eference] (multiple versions) from Oracle and]-nderstanding >?] from ybe for general >? information. "lso, I would recommend O\3eilly

    *ublishing\s boo&s, and Toe 8el&o\s writings for advanced users. =or specific %N info (especially in

    the "ccess area), I recommend >ue\s ]-sing] series, and the boo&s of "lison Nalter.C. What is a schema6 55" schema is a logical set of tables, such as the "nti/ues database above...usually,it is thought of as simply ]the database], but a database can hold more than one schema. =or eample, a

    star schema is a set of tables where one large, central table holds all of the important information, and islin&ed, via foreign &eys, to dimension tables which hold detail information, and can be used in a Join to

    create detailed reports.. I understand that Oracle offers a special &eyword, %ecode, that allows for some ]if5then] logic. Aow

    does that wor&6 55 #echnically, %ecode allows for conditional output based on the value of a column orfunction. #he synta loo&s li&e this (from the Oracle0 8omplete 3eference series)0

    elect ...%E8O%E (alue, If1, #hen1, If 4, #hen 4, ...,X Else) ...=rom ...#he alue is the name of a column, or a function (conceivably based on a column or columns), and for

    each If included in the statement, the corresponding #hen clause is the output if the condition is true. Ifnone of the conditions are true, then the Else value is output. ?et\s loo& at an eample0

    elect %istinct 8ity,%E8O%E (8ity, \8incinnati\, \>ueen 8ity\, \+ew Hor&\, \Nig "pple\, \8hicago\,

    4L

    \8ity of Nroad houlders\, 8ity) " +ic&name

    =rom 8ities

    #he output might loo& li&e this08ity +ic&name

    555555555555 555555555555555555555555555555Noston Noston8incinnati >ueen 8ity

    8leveland 8leveland+ew Hor& Nig "pple

    \8ity\ in the first argument denotes the column name used for the test. #he second, fourth, etc. argumentsare the individual e/uality tests (ta&en in the order given) against each value in the 8ity column. #he

    third, fifth, etc. arguments are the corresponding outputs if the corresponding test is true. #he finalparameter is the default output if none of the tests are true in this case, Just print out the column value.

    #I*0 If you want nothing to be output for a given condition, such as the default ]Else] value, enter the

  • 8/14/2019 36401672-Oracle-DBA

    42/67

    value +ull for that value, such as0elect %istinct 8ity,

    %E8O%E (8ity, \8incinnati\, \>ueen 8ity\, \+ew Hor&\, \Nig "pple\, \8hicago\,\8ity of Nroad houlders\, +ull) " +ic&name

    =rom 8itiesIf the 8ity column value is not one of the ones mentioned, nothing is outputted, rather than the city name

    itself.8ity +ic&name

    555555555555 5555555555Noston

    8incinnati >ueen 8ity8leveland

    +ew Hor& Nig "pple

    K. Hou mentioned 3eferential Integrity before, but what does that have to do with this concept I\ve heardabout, 8ascading -pdates and %eletes6 55#his is a difficult topic to tal& about, because it\s covered

    differently in different %N\s.

    =or eample, icrosoft >? erver (C.L < below) re/uires that you write ]triggers] (see the Hahoo>? 8lub lin& to find lin&s that discuss this topic55I may include that topic in a future version of this

    page) to implement this. (" /uic& definition, though a #rigger is a >? statement stored in the database

    that allows you to perform a given /uery usually an ]"ction] >uery55%elete, Insert, -pdateXautomatically, when a specified event occurs in the database, such as a column update, but anyway...)icrosoft "ccess (believe it or not) will perform this if you define it in the 3elationships screen, but it will

    still burden you with a prompt. Oracle does this automatically, if you specify a special ]8onstraint] (seereference at bottom for definition, not synta) on the &eyed column.

    o, I\ll Just discuss the concept. =irst, see the discussion above on *rimary and =oreign &eys.

    41

    8oncept0 If a row from the primary &ey column is deleted2updated, if ]8ascading] is activated, the valueof the foreign &ey in those other tables will be deleted (the whole row)2updated.

    #he reverse, a foreign &ey deletion2update causing a primary &ey value to be deleted2changed, may ormay not occur0 the constraint or trigger may not be defined, a ]one5to5many] relationship may eist, the