11
INTRODUCTIONSQL is divided into the following Data Definition Language (DDL) Data Manipulation Language (DML) Data Retrieval Language (DRL) Transaction Control Language (TCL) Data Control Language (DCL)DDL -- create, alter, drop, truncate, renameDML -- insert, update, deleteDRL -- selectTCL -- commit, rollback, savepointDCL -- grant, revoke CREATE TABLE SYNTAX Create table < table_name > ( col1 datatype1, col2 datatype2 …coln datatypen );Ex: SQL> create table student (no number (2), name varchar (10), marks number (3)); INSERT This will be used to insert the records into table.We have two methods to insert. By value method

INTRODUCTIONSQL is Divided Into the Following

Embed Size (px)

DESCRIPTION

JJ

Citation preview

INTRODUCTIONSQL is divided into the followingData Definition Language (DDL)Data Manipulation Language (DML)Data Retrieval Language (DRL)Transaction Control Language (TCL)Data Control Language (DCL)DDL -- create, alter, drop,truncate, renameDML -- insert, update, deleteDRL -- selectTCL -- commit, rollback, savepointDCL -- grant, revokeCREATE TABLE SYNTAXCreate table (col1 datatype1, col2 datatype2 coln datatypen);Ex:SQL>create table student (no number (2), name varchar (10), marks number (3));INSERTThis will be used to insertthe records into table.We have two methods to insert.By value methodBy address methoda) USING VALUE METHODSyntax:insert into select * from bookswhere contains(info, propertyANDharvestsANDworkers) > 0;SQL>select * from bookswhere catsearch(info, property harvests workers, null) >0;The following queries will search for either of the two words.SQL>select * from bookswhere contains(info, propertyORharvests) > 0;Instead ofORyou can use a vertical line (|).SQL>select * from bookswhere contains(info, property|harvests) > 0;SQL>select * from bookswhere catsearch(info, property|harvests, null) > 0;In the following queries theACCUM(accumulate) operator adds together the scores of theindividual searches and compares the accumulated score to the threshold value.SQL>select * from bookswhere contains(info, propertyACCUMharvests) > 0;SQL>select * from bookswhere catsearch(info, propertyACCUMharvests, null) > 0;Instead ofORyou can use a comma(,).SQL>select * from books where contains(info, property , harvests) > 0;SQL>select * from books where catsearch(info, property ,harvests, null) > 0;In the following queries theMINUSoperator subtracts the score of the second terms searchfrom the score of the firstterms search.SQL>select * from bookswhere contains(info, propertyMINUSharvests) > 0;SQL>select * from bookswhere catsearch(info, propertyNOTharvests, null) > 0;Instead ofMINUSyou can use and instead ofNOTyou can use ~.SQL>select * from bookswhere contains(info, property-harvests) > 0;SQL>select * from bookswhere catsearch(info, property~harvests, null) > 0;SEARCHING FOR AN EXACT MATCH OF A PHRASE133The following queries will search for the phrase. If the search phrase includes a reservedword within oracle text, the you must use curly braces ({}) to enclose text.SQL>select * from bookswhere contains(info, transactions {and} finances) >0;SQL>select * from bookswhere catsearch(info, transactions {and} finances, null) >0;You can enclose the entire phrase within curly braces, in which case any reserved wordswithin the phrase will be treated as part of the search criteria.SQL>select * from bookswhere contains(info, {transactions and finances}) >0;SQL>select * from bookswhere catsearch(info, {transactions and finances}, null) >0;SEARCHING FOR WORDS THAT ARE NEAR EACH OTHERThe following queries will search for the words that are in between the search terms.SQL>select * from bookswhere contains(info, workersNEARharvests) > 0;Instead ofNEARyou can use ;.SQL>select * from books where contains(info, workers ; harvests) > 0;InCONTEXTindex queries, you can specify the maximum number of words between thesearch terms.SQL>select * from bookswhere contains(info, NEAR((workers, harvests),10) >0;USING WILDCARDS DURING SEARCHESYou can use wildcards to expand the list of valid search terms used during your query. Justas in regulartext-string wildcard processing, two wildcards are available.%-percentsign;multiple-characterwildcard_-underscore; single-character wildcardSQL>select * from books where contains(info, worker%) > 0;134SQL>select * from bookswhere contains(info, work___) >0;SEARCHING FOR WORDS THAT SHARE THE SAME STEMRather than using wildcards, you can use stem-expansion capabilities to expand the list oftext strings. Given the stem of a word, oracle will expand the list of words to search for toinclude all words having the same stem. Sample expansions are show here.Play-playsplayingplayedplayfulSQL>select * from books where contains(info, $manage) > 0;SEARCHING FOR FUZZY MATCHESA fuzzy match expands the specified search term to include words thatare spelled similarlybut that do not necessarily have the same word stem. Fuzzy matches are most helpful whenthe text contains misspellings. The misspellings can be either in the searched text or in thesearch string specified by the user during the query.The following queries will not return anything because its search does notcontain the wordhardest.SQL>select * from bookswhere contains(info, hardest) >0;Itdoes,however,containsthewordharvest.Afuzzymatchwillreturnthebookscontaining the word harvest even though harvest has a different word stem thant theword used as the search term.Touse afuzzymatch,precedethe searchtermwithaquestionmark,withnospacebetween the question mark and the beginning of the search term.SQL>select * from bookswhere contains(info, ?hardest) >0;SEARCHING FOR WORDS THAT SOUND LIKE OTHER WORDSSOUNDEX, expands search terms based on how the word sounds. The SOUNDEX expansionmethod uses the same text-matching logic available via the SOUNDEX function in SQL.135Tousethe SOUNDEXoption,youmustprecedethesearchtermwithanexclamationmark(!).SQL>select * from books where contains(info, !grate) > 0;INDEX SYNCHRONIZATIONWhen usingCONTEXTindexes, you need to manage the text index contents; the text indexesare not updated when the base table is updated. When the table was updated, its text indexis out of sync with the base table. To sync of the index, execute theSYNC_INDEXprocedure oftheCTX_DDLpackage.SQL>execCTX_DDL.SYNC_INDEX(book_index);INDEX SETSHistorically, problems with queries of text indexes have occurred when other criteria areused alongside text searches as part of the where clause. To improve the mixed querycapability, oracle features index sets. The indexes within the index set may be structuredrelational columns or on textcolumns.To create an index set, use theCTX_DDLpackage to create the index set and add indexes toit. When you create a text index, you can thenspecify the index set it belongs to.SQL>execCTX_DDL.CREATE_INDEX_SET(books_index_set);The add non-text indexes.SQL>execCTX_DDL.ADD_INDEX(books_index_set,title_index);Now create aCTXCATtext index. Specify ctxsys.ctxcat as the index type, and list the indexset in the parameters clause.SQL>create index book_index onbooks(info) indextype is ctxsys.ctxcatparameters(index set books_index_set);136INDEX-ORGANIZED TABLEAn index-organized table keeps its data sorted according to the primary key column valuesfor the table. Index-organized tables store their data as if the entire table was stored in anindex.An index-organized table allows you to storethe entire tables data in an index.Ex:SQL>create table student (sno number(2),sname varchar(10),smarks number(3)constraint pk primary key(sno) organization index;PARTITION INDEXSimilartopartitioningtables,oracleallowsyoutopartitionindexestoo.Liketablepartitions,index partitions could be in different tablespaces.LOCAL INDEXESLocal keyword tells oracle to create a separte index for each partition.In the local prefixed index the partition key is specified on the left prefix. When theunderlyingtableispartitionedbaeson,say twocolumnsthenthe index canbeprefixed on the firstcolumn specified.Local prefixed indexes can be unique or non unique.Local indexes may be easier to manage than global indexes.Ex:SQL>create index stud_index on student(sno) local;GLOBAL INDEXESA global index may contain values from multiple partitions.An index is global prefixed if itis partitioned on the left prefix of theindex columns.The global clause allows you to create a non-partitioned index.Globalindexesmayperformuniquenesschecksfasterthanlocal(partitioned)indexes.You cannot create global indexes forhash partitions or subpartitions.137