培训: 001 Lesson 1-15 -- 2001/11/20最新补充: Lesson 14-15

[复制链接]
查看11 | 回复9 | 2005-2-28 12:57:00 | 显示全部楼层 |阅读模式
原来的帖子好象丢失了,重新传送,希望对001组的同志们有用,下面将陆续补充
[php]
Lession1
Selecting Rows
* RELATIONSHIPS

Solid Line = Must Be

Dashed Line = May Be

Single Line = One and Only One

Crow's foot = One or More

UID = #

Secondary UID = ( # )

Mandatory attribute = ( * )

Optional Attribute = ( o )
* An SQL command is entered at the SQL prompt, and subsequent lines are numbered. This is called the SQL buffer. -可有多个buffer存贮plus语句
* Only one statement can be current at any time within the buffer, and the statement can be executed in a number of ways:(重点)

Place a semicolon (

at the end of last clause.

Place a semicolon or slash on the last line in the buffer.

Place a slash at the SQL prompt.

Issue a SQL*Plus RUN command at the SQL prompt.
* Character and date column headings and data are left-justified within a column and numbers are right-justified. Character and date column headings may be truncated, but number headings may not be truncated. The column labels appear in uppercase by default. You can override the column label display with an alias.(重点,注意:仅数字是右对齐的,而且保留完整的heading)
* SQL*Plus ignores blank spaces before and after the arithmetic operator.
* By default, alias headings will be forced to uppercase and cannot contain blank spaces and special characters (such as # or $), unless the alias is enclosed in double quotation marks (“ ”).
* You can include the AS keyword before the alias name to comply with ANSI SQL 92 standards.
* 关于别名的使用(重点):

1. 一旦在WHERE中定义了表别名,则在整个SELECT语句中不能再使用表原名

2. where,group by子句中可以使用表别名,但不能使用列别名

2. order by子句中可以使用列别名,但不能有表名前缀,不能使用:表原名.列别名,但可以使用:表别名.列原名

3. 表别名可以与列别名相同
* A literal is any character, expression, or number included in the SELECT list that is not a column name or a column alias.
--可以理解为除了字段名(包括别名)以外的常量(字符、数字、表达式)
* Currently, Oracle treats a character value with length of zero as null. However, this may not continue to be true in future versions of Oracle.-- 8i中还没有改变,''仍然视为null处理
* You can use the NVL function to convert any datatype, but the return value is always the same as the datatype of expr1. -- 除非可以隐含自动转换的类型,比如数字-字符
* In SQL*Plus, you can display the structure of a table using the DESCRIBE command. The result of the command is to see the column names, datatypes, and whether a column must contain data(null or not null). (重点)
* You terminate the SQL buffer by either entering one of the terminator characters (semicolon or slash), or pressing [RETURN] twice. You will now see the SQL prompt. (重点)
* SQLPLUS Command :0 text Inserts a line before line 1.
* SPO[OL] [filename[.ext]|OFF|OUT] Stores query results in a file, OFF closes the spool file. OUT closes the spool file and sends the file results to the system printer. (重点)
* COLUMN 命令:

JUS[TIFY] {align}
Justifies the column heading (not the data) to be left, center, or right.

NOPRI[NT]
Hides the column.

NUL[L] text
Specifies text to be displayed for null values.

PRI[NT]
Shows the column.

TRU[NCATED]
Truncates the string at the end of the first line of display. -与wrap对应,根据列宽截断

WRA[PPED]
Wraps the end of the string to the next line.

WOR[D_WRAPPED]
Same as WRAPPED, but ensures that words do not split.-在中文字符集下的处理,也是以空格区分

L
Represents local currency.
L9999
-与nls_currency的设定相关
*

COL[UMN] column
Displays the current settings for the specified column.

COL[UMN]
Displays the current settings for all columns.

COL[UMN] column CLE[AR] Clears the settings for the specified column.

CLE[AR] COL[UMN]
Clears the settings for all columns.
* The selection capability in SQL allows you to choose rows in a table to be returned by a query.You can restrict the rows returned by selection using various criteria.The projection capability in SQL allows you to choose columns in a table to be returned by a query.You can control the number of columns returned by a query.Selection is often considered horizontal partitioning, and projection is often considered vertical partitioning.
? SQL commands are not case sensitive, unless indicated.(Lession1 Page7 Writing SQL Commands)
[/php]
回复

使用道具 举报

千问 | 2005-2-28 12:57:00 | 显示全部楼层
[php]
Lession2
Limiting Selected Rows
* ORDER BY clause is last in SELECT command.
-(重点)
* If no ORDER BY clause, the Oracle7 Server may not fetch rows in the same order for the same query twice.
--与数据存贮的变化有关
* ASC orders the rows in ascending order. This is the default order.
* In Oracle7, null values are displayed last for ascending sequences and first for descending sequences. -- 8i依然是这个原则(重点)
* You can order by position to save time.-- 没有测试过按位置order by是否可以节省运行时间?
* Sort by position is especially useful when sorting by a long expression. Rather than typing the expression again.
-别名也可以解决问题
* You can order by columns that are not in the SELECT list. --注意例外情况是:在SELECT中使用了DISTINCT和组函数 (重点)
* Conditions consist of the following:

- Column name,expression,constant

- Comparison operator

- Literal
* ...WHERE expr operator value : the expr cannot be an alias.
-参见Lession1的关于别名的限制说明
* SQL Operator Precedence 优先次序
-(重点)

1. 正负+ -

2. 乘除* /

3. 加减+ - ||

4. All comparison operators 比较运算符:=>=BETWEEN ...AND.../IN(list)/LIKE/is (not) null

5. NOT

6. AND
逻辑运算符

7. OR
* = NULL that an error is not raised, the result is simply always FALSE.
* It may be faster and easier to eliminate rather than include.-?排除比包括速度快?需要测试
* Search conditions can contain either literal characters or numbers.
* The % and _ symbols may be used in any combination with literal characters.
* When you need to have an exact match for the actual “%” and “_” characters, use the ESCAPE option. This option specifies what the ESCAPE character is.
? 无ORDER BY时ORACLE缺省用什么样的顺序显示数据?ROWID?
---
[/php]
回复

使用道具 举报

千问 | 2005-2-28 12:57:00 | 显示全部楼层
[php]
Lession3
Single Row Functions
* Functions are a very powerful feature of SQL and can be used to

Perform calculations on data.

Modify individual data items.

Manipulate output for groups of rows.

Alter date formats for display.

Convert column datatypes.
* An argument may be one of the following:

A user-supplied constant

A variable value

A column name

An expression
* Features of Single Row Functions

They may expect one or more user arguments.

You can nest them.

You can use them in SELECT, WHERE, and ORDER BY clauses.-- 为什么不写:group by?
* Lower(),Upper(): Converts alpha character
INITCAP(): Converts alpha character values to uppercase for the first letter of each word, all other letters in lowercase.
CONCAT(): 同 ||
SUBSTR(column|expression,m[,n]): m 不能缺省,n缺省为到end, n=0返回null
NVL(column|expression1,column|expression2):exp1和exp2必须同类型,或者可以隐含转换
ROUND(column|expression,n):n=0或n不指定,则round到整数位;n为负数,则从小数点起向左边round;Round the date at midnight.
TRUNC(column|expression,n):n=0或n不指定,则round到整数位;n为负数,则从小数点起向左边n位trunc为0
NEXT_DAY(date,‘char’):Finds the date of the next specified day of the week (‘char’) following date. char may be a number representing a
day or a character string. (char在英文字符集下,用三位表示即可,如:mon, char是和字符集相关的?在中文字符集下具体的char格式如何寻找?)
* Oracle stores dates in an internal numberic format. - Century,year,month,day,hours,minutes,seconds.
* Default date display is DD-MON-YY.-- 于CharacterSet设置有关,nls_data_format, nls_date_language
* Valid Oracle dates are between January 1, 4712 B.C. and December 31, 4712 A.D.
--Oracle8i中不知是否更改了?
* The DUAL table is owned by the user SYS and may be accessed by all users. It contains one column, DUMMY, and one row with the value “X”
* Add hours to a date by dividing the number of hours by 24.-按天的方式增减
* 日期值可以直接按字符形式比较,比如:WHERE start_date LIKE ’%1991’; 当然于nls_date_format有关
* to_char(date): The names of days and months in the output are automatically padded with blanks. To remove padded blanks or to suppress leading zeros, use the fill mode fm element. The resultant column width is 80 characters by default. (注意:8i中已经改变了不是80列)
* TO_CHAR() format:
MONTH
Name of month padded with blanks to length of 9 characters.
RM
Roman numeral month.
DAY
Name of day padded with blanks to length of 9 characters.
DY
Name of day; 3-letter abbreviation.
Years in dates YYYY or SYYYY Year;
S prefixes BC date with -.
SCC or CC
Century;
S prefixes BC date with -.
Q
Quarter of year.
SSSSS
Seconds past midnight (0-86399).
/ . ,
Punctuation is reproduced in the result.
“ of the ”Quoted string is reproduced in the result.
TH
Ordinal number (for example, DDTH for 4TH).
SP
Spelled-out number (for example, DDSP for FOUR).
SPTH or THSP
Spelled-out ordinal numbers (for example, DDSPTH for FOURTH).
L
uses the floating local currency symbol
set the NLS_CURRENCY parameter
MI
Minus signs to right (negative values).
999999MI 1234-
PR
Parenthesize negative numbers.
999999PR
EEEE
Scientific notation (format must specify four Es).
99.999EEEE 1.234E+03
V
Multiply by 10 n times (n= no of 9s after V).
9999V99 123400
B
Display zero values as blank, not 0.
B9999.99 1234.00
FM/fm
Fill Mode 删除前导0和右边的空格
FX
Format Exact 精确匹配
-参见ORACLE文档
* RR available in Oracle7, not Oracle Version 6.
* NLS parameters may be added to init.ora file to set default date formats and language names and abbreviations. And you can use the dcl command: "Alter Session" to change it in a session and can change it in register table in Windows system.
* The Oracle Server displays a string of pound signs (#) in place of a whole number whose digits exceed the number of digits provided in the format model.
* Single row functions can be nested to any depth. Nested functions are evaluated from the innermost level to the outermost level. 可以嵌套任意层次,执行次序从内到外;

?在中文字符集下具体的char格式如何寻找?
-- --
[/php]
回复

使用道具 举报

千问 | 2005-2-28 12:57:00 | 显示全部楼层
真是太及时了
回复

使用道具 举报

千问 | 2005-2-28 12:57:00 | 显示全部楼层
真是雪中送炭!
回复

使用道具 举报

千问 | 2005-2-28 12:57:00 | 显示全部楼层
众人拾柴财火焰高,感谢easyfree的这种乐于助人的精神。
回复

使用道具 举报

千问 | 2005-2-28 12:57:00 | 显示全部楼层
[php]
Lession4
Displaying Data from Multiple Tables
* Cartesian Product 笛卡儿乘积
* To join tables together, you need a minimum of the number of join conditions summarized as the number of tables minus one. 最少的连接条件是连接表的个数-1(重点考试题)This rule may not apply if your table has a concatenated primary key, in which case more than one column is equired to uniquely identify each row. 当有组合的主键时,刚才的原则不适用;
* Table aliases help to keep SQL code smaller, therefore using less memory.
* Once you use the table alias, you must continue to qualify every column reference with the table alias. 表名和表别名不能同时使用;If a table alias is used for a particular table name in the FROM clause, then that table alias must be substituted for the table name hroughout the SELECT statement.
* Table aliases can be up to 30 characters in length.
-8i中规定?
* The table alias is only valid for the current SELECT statement.
* A NON-EQUIJOIN's relationship is obtained using an operator other than equal (=).
- 不是使用=连接的就是非等值连接
* Table aliases have been specified for performance reasons, not because of possible ambiguity.
* (+) is placed on the “side” of the join that is deficient in information. (the side where there is no value to join to, or which have no direct match in the other side , But not on both sides. Place the outer join symbol following the name of the table without the matching rows.)
* A condition involving an outer join may not use the IN operator or be linked to another condition by the OR operator.
* Speed up database access with table ailiases.
? Additional join methods include the following:

Outer joins

Self joins

Set operators? update ?
? When writing a SELECT statement that joins tables, precede the column name with the table name for clarity and to enhance database access. 能够提高优化器的使用么?
? How to code with an outer join on both sides? This is possible with the UNION operator, which is not addressed in this course.
-----------------------------------------------
Lession5
Group Functions
* ORACLE7中有7个组函数;
-8i中?????
* STDDEV()
标准方差;
VARIANCE()
?
* COUNT(*)=COUNT(ROWID)=COUNT(1)
统计NULL和重复的值;但COUNT(字段)统计非空值
* MAX(),MIN()
忽略NULL
* 组函数中可以使用DISTINCT和ALL,ALL是缺省值;如:COUNT(DISTINCT A),COUNT(ALL A);
* The datatypes for the arguments may be CHAR, VARCHAR2, NUMBER, or DATE where expr is listed.-????? 8i中是否有变化?????
* You can use AVG and SUM functions against columns that store numeric data. You can use MAX and MIN functions for any datatype.
* GROUP BY Clause Gidelines

Cannot select individual results as well unless the individual column appears in the GROUP BY clause.

You cannot use the positional notation or column alias in the GROUP BY clause.

By default, rows are sorted by ascending order of the GROUP BY list. You can override this by using the ORDER BY clause.
* The ORDER BY clause is always the last clause in a SELECT statement.
-- end ---
[/php]
回复

使用道具 举报

千问 | 2005-2-28 12:57:00 | 显示全部楼层
在lesson 2 中,有一个问题我想问一下
order by position中的postiton是什么意思
原文在lesson 2 9页
Another method for sorting query results is to sort by position. This is especially useful when sorting by a long expression. Rather than typing the expression again,
you can specify its position in the SELECT list.
SQL> SELECT last_name, salary*12
2 FROM s_emp
3 ORDER BY 2;
2指的是salary*2这个位置吗?
谢谢
:)



回复

使用道具 举报

千问 | 2005-2-28 12:57:00 | 显示全部楼层
是的
回复

使用道具 举报

千问 | 2005-2-28 12:57:00 | 显示全部楼层
當你用
SELECT *FROM s_emp
ORDER BY 2
也可以
它指的是 按照所選的 column第2個 column 來 sort
( default ASC )
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行