Jiangtang's profile技止于此BlogListsNetwork Tools Help

Blog


    11/22/2007

    SQL——在Oracle SQL*Plus里工作(1):基础篇

    自己整理出来的东西,做备忘最好。他人的东西,无论多详整,都不会像下面的东西让我记起更多。

    1.使用演示帐号scott进入SQL*Plus,密码是tiger,这里帐号和密码不区分大小写。或者,你用其他任何一个账户登录SQL*Plus,再敲入连接scott的命令 connect scott/tigerscott账户下有一些简单的练习数据,在oracle的安装路径里,你找到一个叫adminscott.sql的脚本,可以查看端倪。这里面有三张常用的表:员工表emp、部门表dept和工资表salgrade。

    2.一个最简洁的sql语句由select*  from  表的名字  组成,即,sql至少要包括select和from两个字句。有时你要在sql下演示,比如说只是把大写字母A转化成小写a(函数lower('A')),你看上去不需要数据库提供的任何表,但语法还需要一个from字句。此时可以用Oracle提供的一张虚表dual,如select  lower('A')  from dual。

    3.改变系统默认格式——日期:alter session set nls_date_language='american' 。

    4.显示变量标签:select empno as "emp number",ename name from emp。两种方式,用空格隔开方便些,加as好读些。

    5.连接运算符||和distinct关键字。

    6.限制性查询where:比较运算符between and 、in、 like。

    7.like运算符的通配符:%代表零个或多个字符,_代表一个(只是一个)字符(_不是-)。

    8.定义转义符(escape):where ename like 'IT\_%' escape '\'。'\'是c语言中的转义符。_本是通配符。

    9.如果使用order by排序语句,要把它放在sql的最后。默认是按升序。

    10.desc[ribe],描述表的结构。

    11.set line[size]调整显示屏的显示宽度,默认是80。同样有set pagee[size]。

    12.行编辑命令: 

      A[PPEND] text : 在缓冲区行的末尾加上text的文本。
      C[HANGE]/old/new:将当前行中old替换为new
      C[HANGE]/text: 从行中删除text文本
      CL[EAR] BUFF[ER]:清除缓冲区里所有的行
      DEL : 删除当前行
      DEL *:删除当前行
      DEL n * : 删除从n行到当前行。
      DEL LAST:删除最后一行。
      DEL m n:删除范围为:m到n行。
      DEL * N:从当前行向后删除到n行。
      I[NPUT]:在当前行后插入任意数量的命令行;添加一或者多行到缓冲区
      INPUT text :添加包含的文本。
      L[IST]:列出缓冲区里所有的行。
      LIST n :列出第n行。
      LIST * :列出当前行。
      LIST LAST :列出最后一行。
      LIST m n LIST * n:

          n:指定第n行为当前行

          n text:用text的文本的内容替代第n行

          o text:在第一行之前插入text指定的文本

    13.保存脚本:save d:\…,保存结果spool d:\… spool off,载入:get d:\…,编辑:ed d:\…,运行:@ d:\…。

    Technorati Tags: , ,

    Comments (3)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    No namewrote:
    您需要二手液晶显示屏废旧液晶屏么?我们是不折不扣的二手液晶屏、旧液晶屏大批发商,长期大量供应可再利用的旧液晶屏。我公司提供的各种尺寸的二手液晶屏, 不同厚薄如笔记本屏,均已经过我们严格的分类,检验,测试流程。请访问协力液晶屏www.sceondhandlcd.com[ghfcbghibfifgia]
    Nov. 21
    Nov. 9
    Nov. 3

    Trackbacks

    The trackback URL for this entry is:
    http://johnthu.spaces.live.com/blog/cns!2053CD511E6D5B1E!338.trak
    Weblogs that reference this entry
    • None