* DISTINCT Only one instance of the duplicated data is shown eg. select DISTINCT amount from checks; * WHERE - WHERE simply causes your queries to be more selective eg. SELECT * FROM BIKES WHERE NAME = 'BURLEY'; * LIKE You can see the use of the percent sign (%) in the statement after LIKE. When used inside a LIKE expression, % is a wildcard. _ The underscore is the single-character wildcard. eg. SELECT * FROM PARTS WHERE LOCATION LIKE '%BACK%'; * UNION UNION returns the results of two queries minus the duplicate rows. eg. SELECT NAME FROM SOFTBALL UNION SELECT NAME FROM FOOTBALL; * UNION ALL UNION ALL works just like UNION except it does not eliminate duplicates. eg. SELECT NAME FROM SOFTBALL UNION ALL SELECT NAME FROM FOOTBALL; * INTERSECT INTERSECT returns only the rows found by both queries. eg. SELECT * FROM FOOTBALL INTERSECT SELECT * FROM SOFTBALL; * MINUS Minus returns the rows from the first query that were not present in the second. eg. SELECT * FROM FOOTBALL MINUS SELECT * FROM SOFTBALL; * IN Shorthand to OR eg. SELECT * FROM FRIENDS WHERE STATE= 'CA' OR STATE ='CO' OR STATE = 'LA'; is the same as: SELECT * FROM FRIENDS WHERE STATE IN('CA','CO','LA'); * BETWEEN Returns something between something eg. SELECT * FROM PRICE WHERE WHOLESALE BETWEEN 0.25 AND 0.75; * COUNT The function COUNT returns the number of rows that satisfy the condition in the WHERE clause. eg. SELECT COUNT(*) FROM TEAMSTATS WHERE HITS/AB < .35; * SUM SUM does just that. It returns the sum of all values in a column. eg. SELECT SUM(SINGLES) TOTAL_SINGLES FROM TEAMSTATS; * AVG The AVG function computes the average (keskiarvo) of a column. eg. SELECT AVG(SO) AVE_STRIKE_OUTS FROM TEAMSTATS; * MAX If you want to find the largest value in a column, use MAX. eg. SELECT MAX(HITS) FROM TEAMSTATS; * MIN MIN does the expected thing and works like MAX except it returns the lowest member of a column. eg. SELECT MIN(AB) FROM TEAMSTATS; * VARIANCE VARIANCE (varianssi) produces the square of the standard deviation. eg. SELECT VARIANCE(HITS) FROM TEAMSTATS; * STDDEV Finds the standard deviation of a column of numbers. eg. SELECT STDDEV(HITS) FROM TEAMSTATS; * ADD_MONTHS This function adds a number of months to a specified date. eg. SELECT TASK, STARTDATE, ENDDATE ORIGINAL_END, ADD_MONTHS(ENDDATE,2) FROM PROJECT; * LAST_DAY LAST_DAY returns the last day of a specified month. eg. SELECT ENDDATE, LAST_DAY(ENDDATE) FROM PROJECT; * MONTHS_BETWEEN If you need to know how many months fall between month x and month y, use MONTHS_BETWEEN like this. eg. SELECT TASK, STARTDATE, ENDDATE,MONTHS_BETWEEN(STARTDATE,ENDDATE) DURATION FROM PROJECT; * NEW_TIME If you need to adjust the time according to the time zone you are in, the New_TIME function is for you. Abbreviation Time Zone AST or ADT Atlantic standard or daylight time BST or BDT Bering standard or daylight time CST or CDT Central standard or daylight time EST or EDT Eastern standard or daylight time GMT Greenwich mean time HST or HDT Alaska-Hawaii standard or daylight time MST or MDT Mountain standard or daylight time NST Newfoundland standard time PST or PDT Pacific standard or daylight time YST or YDT Yukon standard or daylight time eg. SELECT ENDDATE EDT, NEW_TIME(ENDDATE, 'EDT','PDT') FROM PROJECT; * NEXT_DAY NEXT_DAY finds the name of the first day of the week that is equal to or later than another specified date. eg. SELECT STARTDATE, NEXT_DAY(STARTDATE, 'FRIDAY') FROM PROJECT; * SYSDATE SYSDATE returns the system time and date: eg. SELECT DISTINCT SYSDATE FROM PROJECT; * ABS The ABS function returns the absolute value of the number you point to. eg. SELECT ABS(A) ABSOLUTE_VALUE FROM NUMBERS; * CEIL CEIL returns the smallest integer greater than or equal to its argument. eg. SELECT B, CEIL(B) CEILING FROM NUMBERS; * FLOOR Returns the largest integer equal to or less than its argument. eg. SELECT A, FLOOR(A) FLOOR FROM NUMBERS; * COS, COSH, SIN, SINH, TAN, and TANH The COS, SIN, and TAN functions provide support for various trigonometric concepts. They all work on the assumption that n is in radians. eg. SELECT A, COS(A) FROM NUMBERS; * EXP EXP enables you to raise e to a power. eg. SELECT A, EXP(A) FROM NUMBERS; * LN LOG These two functions center on logarithms. LN returns the natural logarithm of its argument. LOG, takes two arguments, returning the logarithm of the first argument in the base of the second. eg. SELECT A, LN(A) FROM NUMBERS; SELECT B, LOG(B, 10) FROM NUMBERS; * POWER To raise one number to the power of another, use POWER. In this function the first argument is raised to the power of the second. eg. SELECT A, B, POWER(A,B) FROM NUMBERS; * SIGN SIGN returns -1 if its argument is less than 0, 0 if its argument is equal to 0, and 1 if its argument is greater than 0. eg. SELECT A, SIGN(A) FROM NUMBERS; SELECT A FROM NUMBERS WHERE SIGN(A) = 1; * SQRT The function SQRT returns the square root of an argument. eg. SELECT A, SQRT(A) FROM NUMBERS; * CHR CHR returns the character equivalent of the number it uses as an argument. The character it returns depends on the character set of the database. Usually ASCII. eg. SELECT CODE, CHR(CODE) FROM CHARACTERS; * CONCAT The || symbol splices two strings together, as does CONCAT. eg. SELECT CONCAT(FIRSTNAME, LASTNAME) "FIRST AND LAST NAMES" FROM CHARACTERS; * INITCAP INITCAP capitalizes the first letter of a word and makes all other characters lowercase. eg. SELECT FIRSTNAME BEFORE, INITCAP(FIRSTNAME) AFTER FROM CHARACTERS; * LOWER LOWER changes all the characters to lowercase. eg. SELECT LOWER(FIRSTNAME) FROM CHARACTERS; * UPPER UPPER changes all the characters to uppercase. eg. SELECT UPPER(FIRSTNAME) FROM CHARACTERS; * LPAD RPAD LPAD and RPAD take a minimum of two and a maximum of three arguments. The first argument is the character string to be operated on. The second is the number of characters to pad it with, and the optional third argument is the character to pad it with. The third argument defaults to a blank, or it can be a single character or a character string. The following statement adds five pad characters, assuming that the field LASTNAME is defined as a 15-character field. L and R stands for Left Rigth side eg. SELECT LASTNAME, LPAD(LASTNAME,20,'*') FROM CHARACTERS; * LTRIM RTRIM LTRIM and RTRIM take at least one and at most two arguments. The first argument, like LPAD and RPAD, is a character string. The optional second element is either a character or character string or defaults to a blank. If you use a second argument that is not a blank, these trim functions will trim that character the same way they trim the blanks in the following examples. eg. SELECT LASTNAME, RTRIM(LASTNAME) FROM CHARACTERS; * REPLACE REPLACE does just that. Of its three arguments, the first is the string to be searched. The second is the search key. The last is the optional replacement string. If the third argument is left out or NULL, each occurrence of the search key on the string to be searched is removed and is not replaced with anything. eg. SELECT LASTNAME, REPLACE(LASTNAME, 'ST') REPLACEMENT FROM CHARACTERS; * SUBSTR This three-argument function enables you to take a piece out of a target string. The first argument is the target string. The second argument is the position of the first character to be output. The third argument is the number of characters to show. If you use a negative number as the second argument, the starting point is determined by counting backwards from the end. eg. SELECT FIRSTNAME, SUBSTR(FIRSTNAME,2,3) FROM CHARACTERS; * TRANSLATE The function TRANSLATE takes three arguments: the target string, the FROM string, and the TO string. Elements of the target string that occur in the FROM string are translated to the corresponding element in the TO string. eg. SELECT FIRSTNAME, TRANSLATE(FIRSTNAME '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ 'NNNNNNNNNNAAAAAAAAAAAAAAAAAAAAAAAAAA); * INSTR To find out where in a string a particular pattern occurs, use INSTR. Its first argument is the target string. The second argument is the pattern to match. The third and forth are numbers representing where to start looking and which match to report. eg. SELECT LASTNAME, INSTR(LASTNAME, 'O', 2, 1) FROM CHARACTERS; * LENGTH LENGTH returns the length of its lone character argument. eg. SELECT FIRSTNAME, LENGTH(RTRIM(FIRSTNAME)) FROM CHARACTERS; * TO_CHAR The primary use of TO_CHAR is to convert a number into a character. eg. SELECT TESTNUM, TO_CHAR(TESTNUM) FROM CONVERT; * TO_NUMBER Is the companion function to TO_CHAR, and of course, it converts a string into a number. eg. SELECT NAME, TESTNUM, TESTNUM*TO_NUMBER(NAME) FROM CONVERT; * GREATEST LEAST These functions find the GREATEST or the LEAST member from a series of expressions. eg. SELECT GREATEST('ALPHA', 'BRAVO','FOXTROT', 'DELTA') FROM CONVERT; * USER USER returns the character name of the current user of the database. eg. SELECT USER FROM CONVERT; * STARTING WITH is an addition to the WHERE clause that works exactly like LIKE(%) eg. SELECT PAYEE, AMOUNT, REMARKS FROM CHECKS WHERE PAYEE STARTING WITH('Ca'); * ORDER BY The ORDER BY clause gives you a way of ordering your results. eg. SELECT * FROM CHECKS ORDER BY CHECK#; * DESC The DESC at the end of the ORDER BY clause orders the list in descending order instead of the default (ascending) order. eg. SELECT * FROM CHECKS ORDER BY PAYEE DESC; * GROUP BY GROUP BY runs the aggregate function described in the SELECT statement for each grouping of the column that follows the GROUP BY clause. eg. SELECT PAYEE, SUM(AMOUNT) FROM CHECKS GROUP BY PAYEE; * HAVING Enables you to use aggregate functions in a comparison statement, providing for aggregate functions what WHERE provides for individual rows. eg. SELECT TEAM, AVG(SALARY) FROM ORGCHART GROUP BY TEAM HAVING AVG(SALARY) < 38000; * EXISTS takes a subquery as an argument and returns TRUE if the subquery returns anything and FALSE if the result set is empty. eg. SELECT NAME, ORDEREDON FROM ORDERS WHERE EXISTS (SELECT * FROM ORDERS WHERE NAME ='TRUE WHEEL') * ANY Compared the output of the following subquery to each row in the query, returning TRUE for each row of the query that has a result from the subquery. eg. SELECT NAME, ORDEREDON FROM ORDERS WHERE NAME = ANY (SELECT NAME FROM ORDERS WHERE NAME ='TRUE WHEEL') * SOME Similarity to IN. IN works like multiple equals. ANY and SOME can be used with other relational operators such as greater than or less than. eg. SELECT NAME, ORDEREDON FROM ORDERS WHERE NAME = SOME (SELECT NAME FROM ORDERS WHERE NAME ='TRUE WHEEL') * ALL Returns TRUE only if all the results of a subquery meet the condition.Oddly enough, ALL is used most commonly as a double negative eg. SELECT NAME, ORDEREDON FROM ORDERS WHERE NAME <> ALL (SELECT NAME FROM ORDERS WHERE NAME ='JACKS BIKE') * INSERT VALUES The INSERT...VALUES statement enters data into a table one record at a time. eg. INSERT INTO table_name (col1, col2...) VALUES(value1, value2...) * INSERT SELECT Essentially, the output of a standard SELECT query is then input into a database table. The same rules that applied to the INSERT...VALUES statement apply to the INSERT...SELECT statement. eg. INSERT INTO table_name (col1, col2...) SELECT col1, col2... FROM tablename WHERE search_condition * UPDATE The purpose of the UPDATE statement is to change the values of existing records. eg. UPDATE table_name SET columnname1 = value1 [, columname2 = value2]... WHERE search_condition * DELETE Delete data from a database. eg. DELETE FROM tablename WHERE condition * CREATE DATABASE The CREATE DATABASE Statement eg. CREATE DATABASE database_name * CREATE TABLE The CREATE TABLE Statement eg. CREATE TABLE table_name (field1 datatype [ NOT NULL ], field2 datatype [ NOT NULL ],field3 datatype [ NOT NULL ]...) ie2. CREATE TABLE BILLS (NAME CHAR(30),AMOUNT NUMBER,ACCOUNT_ID NUMBER); Data types supported by Personal Oracle7. Data Type Comments CHAR Alphanumeric data with a length between 1 and 255 characters. Spaces are padded to the right of the value to supplement the total allocated length of the column. DATE Included as part of the date are century, year, month, day, hour, minute, and second. LONG Variable-length alphanumeric strings up to 2 gigabytes. (See the following note.) LONG RAW Binary data up to 2 gigabytes. (See the following note.) NUMBER Numeric 0, positive or negative fixed or floating-point data. RAW Binary data up to 255 bytes. ROWID Hexadecimal string representing the unique address of a row in a table. (See the following note.) VARCHAR2 Alphanumeric data that is variable length; this field must be between 1 and 2,000 characters long. * ALTER TABLE The ALTER TABLE command enables you to do two things: Add a column to an existing table Modify a column that already exists eg. ALTER TABLE table_name ie2. ALTER TABLE BILLS MODIFY NAME CHAR(40); ie3. ALTER TABLE NEW_BILLS ADD COMMENTS CHAR(80); * DROP TABLE The DROP TABLE command deletes a table along with all its associated views and indexes. eg. DROP TABLE table_name; * DROP DATABASE eg. DROP DATABASE database_name