日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

笔记(数据库)

發(fā)布時(shí)間:2023/12/14 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 笔记(数据库) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
  • 2008-10-11?Saturday
  • 1.?導(dǎo)入數(shù)據(jù)時(shí)間分析
  • 用amsConn->ExecSql(str);方式?插入5543行記錄用時(shí)13.391秒
  • 用???CRecords?cRecord(*amsConn,?1);
  • ????????cRecord.Query(str);
  • 方式,插入5543行記錄用時(shí)26.61秒
  • 用表類的Insert命令時(shí)
  • 用有線時(shí)
  • OK
  • 5543
  • 4.953
  • 用時(shí)4.953秒
  • 體現(xiàn)出表類操作的優(yōu)勢(shì),一次提交,節(jié)省時(shí)間
  • 2.?ORACLE基礎(chǔ)
  • 在命令行中操作
  • C:/Documents?and?Settings/sun>sqlplus/nolog
  • SQL>?conn?/as?sysdba
  • 已連接。
  • SQL>?startup
  • ORACLE?例程已經(jīng)啟動(dòng)。
  • SQL>?select?*?from?student;
  • SNO??????????????SNAME???????????????????????????????????????????AGE
  • ----------------?----------------------------------------?----------
  • 001??????????????Mary?????????????????????????????????????????????19
  • ?????????????????Tom??????????????????????????????????????????????21
  • SQL>?shutdown
  • 數(shù)據(jù)庫(kù)已經(jīng)關(guān)閉。
  • 已經(jīng)卸載數(shù)據(jù)庫(kù)。
  • ORACLE?例程已經(jīng)關(guān)閉。
  • 3.?sqlloader使用
  • 創(chuàng)建用戶
  • 創(chuàng)建表空間
  • 查找的資料
  • 1、在Oracle中按照導(dǎo)入數(shù)據(jù)的格式建立一個(gè)空表
  • 2、編寫一個(gè)loader.ctl文件,內(nèi)容如下
  • load?data??
  • infile?'/backup/incoming/SDSS.csv'?
  • into?table?SDSS??????
  • fields?terminated?by?","
  • (?RA,?DEC,?MAG?)????
  • 操作分類:?
  • ????????a、insert,為缺省方式,在數(shù)據(jù)裝載開始時(shí)要求表為空
  • ????????b、append,在表中追加新記錄
  • ????????c、replace,刪除舊記錄,替換成新裝載的記錄
  • ????????d、truncate,同上
  • 3、在CMD中執(zhí)行以下語句:
  • ????????sqlldr?sss/oracle?control=loader.ctl?
  • 4、自動(dòng)在當(dāng)前目錄下生成兩個(gè)文件
  • ????????默認(rèn)日志文件名為:loader.log?
  • ????????默認(rèn)壞記錄文件為:SDSS.bad?
  • 注意事項(xiàng):
  • 1、必須在服務(wù)器本機(jī)上操作,不能在只安裝Oracle客戶端的機(jī)器上使用。
  • 2、CSV文件的內(nèi)容是以“,“分隔的,如果數(shù)據(jù)在結(jié)尾沒有逗號(hào)導(dǎo)入時(shí)就會(huì)出錯(cuò)。
  • 可以利用UltraEdit等文本編輯器處理一下,將?^p?替換為?,^p?就可以在每行的末尾加上一個(gè)逗號(hào)?
  • 了。
  • 3、數(shù)據(jù)導(dǎo)入需要較長(zhǎng)的時(shí)間。
  • 4、導(dǎo)入不同的表需要使用不同的.ctl文件
  • ==========================?????
  • 實(shí)例
  • D盤中input.ctl
  • load?data
  • infile?'data.txt'
  • append?into?table?STUDENT
  • fields?terminated?by?','
  • (SNO,?SNAME)
  • ===========================?????
  • D盤中data.txt
  • 041,Jack,
  • 042,,
  • ===========================????
  • 命令行命令
  • C:/Documents?and?Settings/sun>d:
  • D:/>sqlldr?ams1@hadev/ams1?control=input.ctl
  • SQL*Loader:?Release?10.2.0.1.0?-?Production?on?星期六?10月?11?21:41:05?2008
  • Copyright?(c)?1982,?2005,?Oracle.??All?rights?reserved.
  • 達(dá)到提交點(diǎn)?-?邏輯記錄計(jì)數(shù)?1
  • 達(dá)到提交點(diǎn)?-?邏輯記錄計(jì)數(shù)?2
  • D:/>
  • =============================?????
  • 導(dǎo)入時(shí)可以設(shè)置格式,日期型數(shù)據(jù)則必須要進(jìn)行設(shè)置
  • http://www.eygle.com/archives/2005/07/eciousqlloadero.html
  • load?data??????????????????????????????????????????
  • infile?'test.txt'??????????????????????????????????
  • append?into?table?CC???????????????????????????????
  • fields?terminated?by?','???????????????????????????
  • (???????ACCT_BALANCE_ID,????????????????????
  • ????????ACCT_ID,???????????????????????????
  • ????????EFF_DATE?Date?"yyyymmdd",??????????
  • ????????EXP_DATE?Date?"yyyymmdd",??????????
  • ????????OPT_DATE?Date?"yyyymmddhh24miss",??
  • ????????PAYMENT_ID?????????????????????
  • ?)??????????????????????
  • 這種方式進(jìn)行數(shù)據(jù)導(dǎo)入效率極高,立刻完成
  • 經(jīng)過時(shí)間為:?00:?00:?00.81
  • CPU?時(shí)間為:?00:?00:?00.23???????????????????????????
  • 2008-10-12?Sunday
  • 1.?sqlloader的篩選技巧
  • Load?data
  • infile?'data.txt'
  • Append?into?table?student
  • fields?terminated?by?','
  • (
  • ????SNO,
  • ????x?filler,
  • ????SNAME
  • )
  • 使用filler進(jìn)行過濾
  • 2.?outlook設(shè)置
  • 可以接收郵件,但是不能發(fā)送
  • 修改設(shè)置?
  • 工具----帳戶-----屬性----高級(jí)-----服務(wù)器延時(shí)???時(shí)間拉長(zhǎng)就可以了
  • 10月?第3周
  • 2008-10-13?Monday
  • 1.?sscanf
  • 16進(jìn)制轉(zhuǎn)換為10進(jìn)制
  • int?main()?
  • {?
  • ????const?char*?a="0xff";?
  • ????int?i;?
  • ????sscanf(a,?"%x",?&i);?
  • ????printf("%d",?i);?
  • ????return?0;?
  • }?
  • 2.?SQL語句批量執(zhí)行
  • http://topic.csdn.net/u/20081013/09/e407ad41-b72e-46f4-bb06-485355666c9e.html
  • 如批量的更新或插入放在一個(gè)文件中,如:c:/test.sql?
  • 則在pl/sql或sqlplus下僅需執(zhí)行:@c:/test.sql
  • SQL>?@d:/see.sql
  • 或者
  • SQL>?start?d:/see.sql
  • 附:sqlplus?的使用
  • C:/Documents?and?Settings/sun>sqlplus/nolog
  • SQL*Plus:?Release?10.2.0.1.0?-?Production?on?星期一?10月?13?19:57:22?2008
  • Copyright?(c)?1982,?2005,?Oracle.??All?rights?reserved.
  • SQL>?conn
  • 請(qǐng)輸入用戶名:??ams1@hadev
  • 輸入口令:ams1??注意:這里的輸入不會(huì)顯示出來
  • 已連接。
  • 3.?SQL存儲(chǔ)過程
  • C:/Documents?and?Settings/sun>sqlplus
  • SQL*Plus:?Release?10.2.0.1.0?-?Production?on?星期五?10月?24?14:49:57?2008
  • Copyright?(c)?1982,?2005,?Oracle.??All?rights?reserved.
  • 請(qǐng)輸入用戶名:??sun
  • 輸入口令:
  • 連接到:
  • Oracle?Database?10g?Express?Edition?Release?10.2.0.1.0?-?Production
  • SQL>??create?PROCEDURE?in_stu(no?char,?name?char)
  • ??2???IS
  • ??3???BEGIN
  • ??4???INSERT?INTO?STUDENT?VALUES(no,?name);
  • ??5???COMMIT;
  • ??6???END;
  • ??7???/
  • 過程已創(chuàng)建。
  • SQL>?execute?in_stu('099','Monday')
  • PL/SQL?過程已成功完成。
  • SQL>
  • SQL>?DROP?PROCEDURE?in_stu;
  • 過程已刪除。
  • 4.?PL/SQL導(dǎo)入工具
  • 很好的一個(gè)工具,使用方便,當(dāng)然是會(huì)用了之后,可以任意實(shí)現(xiàn)列的對(duì)應(yīng)
  • Tools-----??Text?Importer
  • 先導(dǎo)入數(shù)據(jù),預(yù)覽,再做設(shè)置,
  • 有疑問點(diǎn)擊Help,講的很清楚
  • 2008-10-14?Tuesday
  • 1.?批量執(zhí)行導(dǎo)入數(shù)據(jù)
  • 寫一個(gè)程序,用sprintf把數(shù)據(jù)寫入到sql文件中,再在sqlplus中執(zhí)行
  • 2.?SQL語句
  • http://topic.csdn.net/u/20080925/12/913dbb1a-b582-4c0b-876b-747ce1293289.html
  • 例如?
  • 表a?
  • 字段??r0??r1??r2?
  • ??????20??-30??50????如何取該行的最大值?
  • SELECT
  • ????(
  • ????????SELECT
  • ????????????MAX(col)?
  • ????????FROM(
  • ????????????SELECT?col?=?r0?UNION?ALL
  • ????????????SELECT?col?=?r1?UNION?ALL
  • ????????????SELECT?col?=?r2
  • ????????)A
  • ????)
  • FROM?表a
  • 2008-10-15?Wednesday
  • 1.?sprintf
  • #include?<iostream.h>
  • int?main()
  • {
  • ????char?a[10]?=?"12345";
  • ????char?buf[10];
  • ????sprintf(buf,?"_%s_",?a?+?1);
  • ????cout?<<?buf?<<?endl;
  • ????return?0;
  • }
  • 結(jié)果
  • _2345_
  • 2.?PLSQL中的命令行
  • File-??New???Command?Window
  • 就可以執(zhí)行命令行語句了
  • 3.?備份表的程序編寫
  • 仿照上次寫的程序,基本上沒有出現(xiàn)什么問題
  • 問題:函數(shù)如何組織起來,分寫多個(gè)函數(shù),還是寫一個(gè)函數(shù),傳入?yún)?shù)實(shí)現(xiàn)多功能
  • 在ams1的用戶中,可以通過ams2.tableName的方式去訪問ams2帳戶的表
  • 2008-10-16?Thursday
  • 1.?關(guān)閉系統(tǒng)自動(dòng)更新
  • 第一,“我的電腦”點(diǎn)右鍵,選“屬性”,“自動(dòng)更新”把有關(guān)自動(dòng)更新的選項(xiàng)去掉。?
  • 第二,“我的電腦”點(diǎn)右鍵,選“管理”,點(diǎn)左邊“服務(wù)和應(yīng)用程序”旁的加號(hào),展開,點(diǎn)“服務(wù)”。?
  • 或者直接在“運(yùn)行”中輸入“Services.msc”打開服務(wù)設(shè)置窗口。?
  • 在“服務(wù)”列表中,找到“AutomaticUpdates”這一項(xiàng),雙擊,彈出的屬性窗口中,“啟動(dòng)類型”設(shè)置為“已禁用”,確定即可。?
  • “AutomaticUpdates”這個(gè)進(jìn)程的作用是:自動(dòng)從WindowsUpdate網(wǎng)絡(luò)更新補(bǔ)丁。利用WindowsUpdate功能進(jìn)行升級(jí)。
  • 2.?字符串連接
  • update?tem_a?set?table_Name?=?table_name||'_G'
  • ||?用于實(shí)現(xiàn)字符串的連接
  • 3.?刪除數(shù)據(jù)
  • 今天在csdn上看到,才知道這個(gè)問題
  • 使用:truncate?table?表名;?
  • 它可以釋放占用的數(shù)據(jù)塊表空間,但此操作不可回退。?
  • 使用delete刪除記錄不能釋放Oracle里被占用的數(shù)據(jù)塊表空間,它只把那些被刪除的數(shù)據(jù)塊標(biāo)成unused。
  • 4.?注意COMMIT
  • 在數(shù)據(jù)庫(kù)的操作中,如用for?update?之后,要及時(shí)的commit,如果出現(xiàn)問題,可以用rollback來取消修改;
  • 2008-10-17?Friday
  • 1.?判斷表是否為空
  • select?count(*)?from?res.SERVE_REPAIR_INFO?where?rownum?=?1
  • 不用全表掃描,只要找出1行記錄就可以,如果僅僅是要看有無記錄
  • 2.?控制臺(tái)實(shí)現(xiàn)輸入密碼不顯示
  • 來自csdn
  • #include?<iostream>?
  • using?namespace?std;?
  • #include?<string>?
  • #include?<conio.h>?
  • int?main()?
  • {?
  • string?password;?
  • char?a;?
  • while((a=_getch())?!=?13)?
  • {?
  • password?+=?a;?
  • putc('*',stdout);?
  • }?
  • cout?<?<password.c_str();?
  • return?0;?
  • }
  • 3.?rownum的應(yīng)用
  • 可以用于取出表中的前若干行數(shù)據(jù)
  • 4.?create?as創(chuàng)建表
  • create?table?tt(aa,cc?)?as?select?sno,?'0'?from?student?union?all?select?sno,?'1'?from?tem
  • select?1?from?student
  • select?*?from?tt
  • drop?table?tt
  • 2008-10-18?Saturday
  • 1.?Insert?into?批量插入
  • 今天才得知,以前忽略了
  • insert?into?tt?select?sno?,?1?from?student
  • insert?into?可以插入?查詢結(jié)果
  • 如果是varchar2?型的數(shù)據(jù),其長(zhǎng)度可以不相等
  • 如果是char型的數(shù)據(jù),長(zhǎng)度必須要相等
  • 2.?truncate?刪除表內(nèi)容
  • Truncate?和?delete的區(qū)別
  • 清除了內(nèi)容,而delete只是設(shè)置了標(biāo)記
  • 2008-10-19?Sunday
  • 改程序
  • 2008-10-20?Monday
  • 1.?編譯問題
  • 程序在更新后,連接編譯出現(xiàn)了嚴(yán)重的問題
  • 解決:Project?->?Settings?????C/C++?選項(xiàng)卡????use?run-time?library
  • 選擇?Debug?Multithreaded
  • Tools?–>?Options????Show?directories?for??查看里面的各項(xiàng)
  • F:/products/HABOSS/haboss_acct/bin/createtable.exe
  • F:/products/HABOSS/haboss_acct/bin/createtree.exe
  • 簡(jiǎn)直讓我崩潰了
  • Project????Set?active?Project?
  • 還是不清楚原因,怎么突然就編譯出錯(cuò),后來不知道怎么又可以了
  • 2008-10-21?Tuesday
  • 1.?Outlook設(shè)置
  • 其實(shí)上次還是沒有解決
  • 找到原因了
  • 在用戶屬性—>?服務(wù)器?中
  • 發(fā)送郵件服務(wù)器
  • 我的服務(wù)器要求身份驗(yàn)證???要選中
  • 使用安全密碼驗(yàn)證登錄???不能選
  • 2.?SQL?SERVER選指定行
  • ORACLE中有rownum這個(gè)方法
  • Select?no=Identity(int,1,1),*?Into?#temptable?From?dbo.teacher_info?order?by?teacher_name--利用Identity函數(shù)生成記錄序號(hào)?
  • Select?*?From?#temptable?Where?no>=10?And?no?<?20?
  • Drop?Table?#temptable--用完后刪除臨時(shí)表?
  • 3.?公交查詢SQL語句
  • 直達(dá)查詢
  • SELECT?a.rout?from?rout_stop?a,?rout_stop?b?where?a.rout?=?b.rout?and?a.stop?=?'3'?and?b.stop?=?'6'
  • 轉(zhuǎn)乘1次
  • select?distinct?a.stop?v?from?rout_stop?a?where?
  • ????(select?rout?from?rout_stop?where?stop?=?'1')?
  • ????????in
  • ????????(select?rout??from?rout_stop?where?stop?=?a.stop)?
  • ????and
  • ????(select?rout?from?rout_stop?where?stop?=?'11')?in?(select?rout??from?rout_stop?where?stop?=?a.stop)
  • 在csdn中可以對(duì)問題關(guān)鍵詞進(jìn)行搜索查詢
  • 2008-10-22?Wednesday
  • 1.?連接數(shù)據(jù)庫(kù)
  • ????j?=?DbFactory.GetConnection(DB_INDEX_SOBAK,?g_struGlobalParam.szCenter,?soConn);
  • 找到配置文件中表,從表中找到一個(gè)連接,連接到一個(gè)庫(kù)中,
  • 就可以對(duì)這個(gè)庫(kù)的的所有用戶進(jìn)行訪問了
  • 2.?Oracle?創(chuàng)建用戶
  • http://hi.baidu.com/cocis/blog/item/7c8f1cdeea120e5dcdbf1a79.html
  • TAB:CREATE?USER
  • 鑒于用戶空間分配和使用問題,建議在創(chuàng)建用戶的時(shí)候就為用戶指定缺省的表空間。
  • 比較完善的創(chuàng)建用戶的語句如下:
  • CREATE?USER?<username>?IDENTIFIED?BY?<password>
  • DEFAULT?TABLESPACE?<tablespace_name>
  • TEMPORARY?TABLESPACE?<tablespace_name>;
  • 以創(chuàng)建katrina用戶為例:
  • SQL>?CREATE?USER?katrina?IDENTIFIED?BY?iloveyou
  • 2?DEFAULT?TABLESPACE?users
  • 3?TEMPORARY?TABLESPACE?temp;
  • User?created.
  • 更改缺省數(shù)據(jù)表空間的語法為:alter?database?default?tablespace?<tablespace_name>;
  • 更改缺省臨時(shí)表空間的語法為:alter?database?default?temporary?tablespace?<tablespace_name>;
  • 配置文件
  • [ORACLE]
  • ConnectString?=?XE
  • PassWord?=sun
  • UserName?=sun
  • 這樣就可以實(shí)現(xiàn)程序和本地?cái)?shù)據(jù)庫(kù)的連接了
  • 程序:
  • int?main()
  • {
  • ????long?j?=?Login("ORACLE");
  • ????if?(j?<=?0)
  • ????{
  • ????????cout?<<?"數(shù)據(jù)庫(kù)連接失敗"?<<?endl;
  • ????????return?-1;
  • ????}
  • ????CRecords?record(DefaultConnect,?1);
  • ????char?str[256];
  • ????int?i?=?0;
  • //??strcpy(str,?"insert?into?student_a?values('002','Jeny')");
  • //??strcpy(str,?"delete?from?student?where?sno?=?'002'");
  • //??strcpy(str,?"select?count(*)?from?student");
  • ????strcpy(str,?"select?*?from?student");
  • ????j?=?record.Query(str);
  • ????if?(j?<=?0)
  • ????{
  • ????????cout?<<?DefaultConnect.GetMsg()?<<?endl;
  • ????????cout?<<?"Query"?<<?endl;
  • ????}
  • ????do?{
  • ????????i++;
  • ????????cout?<<?record.Field(0).Char()?<<?endl;
  • ????}?while(record.Next()?>?0);
  • //??j?=?DefaultConnect.ExecSql(str);
  • //??if?(j?<=?0)
  • //??{
  • //??????cout?<<?DefaultConnect.GetMsg();
  • //??????
  • //??}
  • ????cout?<<?i?<<?endl;
  • ????Logout();
  • ????
  • ????return?0;
  • }
  • 2008-10-23?Thursday
  • 1.?C程序
  • void?foo(int?n)?
  • {?
  • ????if?(n--?>?0)?
  • ????{
  • ??????printf("hello?world!/n");
  • ??????*(&n-1)?-=?5;
  • ????}??
  • }
  • void?main()
  • {
  • ????foo(7);
  • //??int?n?=?6;
  • //??if?(n--?>?0)?
  • //??{
  • //????printf("hello?world!/n");
  • //????*(&n-1)?-=?5;
  • //??}
  • }
  • 構(gòu)成了循環(huán)
  • 2.?PL/SQL語言
  • 簡(jiǎn)單的如
  • begin
  • ?????insert?into?student?values('002',?'Mary');
  • ?????commit;
  • end;
  • 循環(huán)的練習(xí)
  • declare?
  • ??--?Local?variables?here
  • ??i?integer;
  • ??v_counter?binary_integer:=?1;
  • begin
  • ??--?Test?statements?here
  • ??while?v_counter?<?3?loop
  • ????????insert?into?student?values('005',?'Jack');
  • ????????v_counter?:=?v_counter?+?1;
  • ???end?loop;
  • ??commit;
  • end;
  • 3.?execute?immediate
  • http://hi.baidu.com/xtee2003/blog/item/696b43ee3089192c2df534b8.html
  • begin
  • ?????execute?immediate?'insert?into?student?values(:1,:2)'
  • ?????using?'003','Jam';
  • ?????commit;
  • end;
  • 可以用來實(shí)現(xiàn)動(dòng)態(tài)語句
  • 2008-10-24?Friday
  • 1.?狀態(tài)篩選法
  • http://topic.csdn.net/u/20081023/09/5527290d-ee79-4481-8931-d9a7eafdfcb2.html
  • 有1000瓶白酒,其中有1瓶是毒酒,現(xiàn)在用10個(gè)耗子去試酒,耗子喝道毒酒后2個(gè)小時(shí)后毒性發(fā)作。?
  • 現(xiàn)在要在3個(gè)小時(shí)內(nèi),設(shè)計(jì)程序,盡可能多的找出沒有問題的白酒來。
  • 1000瓶酒從1到1000編號(hào),?
  • 10只老鼠以喝和不喝為兩種狀態(tài),?
  • 這樣1000瓶酒可以用10只老鼠的不同組合代表.?
  •     老鼠編號(hào) 9 8 7 6 5 4 3 2 1 0?
  • 酒編號(hào)?
  • 1                          1?
  • 2                        1 0?
  • 3                        1 1?
  • 4                      1 0 0?
  • 5                      1 0 1?
  • 6                      1 1 0?
  • 7                      1 1 1?
  • 8                    1 0 0 0?
  • 9                    1 0 0 1?
  • 10                   1 0 1 0?
  • 11                   1 0 1 1?
  • 12                   1 1 0 0?
  • 13                   1 1 0 1?
  • 14                   1 1 1 0?
  • 15                   1 1 1 1?
  • 16                 1 0 0 0 0?
  •          ...?
  • 999      1 1 1 1 1 0 0 1 1 1?
  • 1000     1 1 1 1 1 0 1 0 0 0
  • 2.?判斷表是否存在
  • select?count(*)?from?user_tables?where?table_name?=?'STUDENT'
  • --alltables
  • 從表名中進(jìn)行查詢
  • 做事情要提高效率,盡快去解決,抓緊時(shí)間,珍惜時(shí)間
  • 3.?公交查詢?cè)O(shè)計(jì)
  • 查詢站點(diǎn)5可以直達(dá)的所有站點(diǎn)
  • SQL>?select?distinct?stop?from?rout_stop?where?rout?in
  • 2???(select?distinct?rout?from?rout_stop?where?stop?=?'5');
  • 應(yīng)該敢于嘗試
  • 寫程序的時(shí)候不清晰,很猶豫,對(duì)整體沒有把握清楚
  • 2008-10-25?Saturday
  • 1.?公交查詢
  • 查詢1條線路經(jīng)過的站點(diǎn)
  • select?s.stop_name,?b.order_no?
  • from?stop_infor?s,?bus_infor?b
  • ?????????where??s.stop_no?=?b.stop_no?and?b.rout?=?'9'?order?by?b.order_no
  • 轉(zhuǎn)乘一次
  • ??select?distinct?a.stop_no?v?from?bus_infor?a?where?--a.stop_no?=?b.stop_no?and
  • ????(select?rout?from?bus_infor?where?stop_no?=?'1')?
  • ????????in
  • ????????(select?rout??from?bus_infor?where?stop_no?=?a.stop_no?)
  • ????and
  • ????(select?rout?from?bus_infor?where?stop_no?=?'9')?in?(select?rout??from?bus_infor?where?stop_no?=?a.stop_no)
  • 2.?編程問題
  • 出現(xiàn)了很多問題,名稱寫錯(cuò),不易發(fā)現(xiàn)的錯(cuò)誤
  • 設(shè)計(jì)思路不清晰,寫程序時(shí)出現(xiàn)偏差
  • 注意:查詢語句應(yīng)該大寫,尤其是列名
  • Alter?table?tname?add?colname?varchar2(2);?
  • 在表中增加列
  • 2008-10-26?Sunday
  • 1.?遠(yuǎn)程連接
  • 運(yùn)行???mstsc
  • 域?HNYD6-D3527AEFF
  • 2.?EXECUTE?Immediate
  • 當(dāng)執(zhí)行SQL語句時(shí),不要用分號(hào),當(dāng)執(zhí)行PL/SQL塊時(shí),在其尾部用分號(hào).
  • declare
  • ???l_cnt?????varchar2(20);
  • begin
  • ???execute?immediate?'select?count(1)?from?emp'
  • ?????into?l_cnt;??--into?在單引號(hào)’’的外面
  • ???dbms_output.put_line(l_cnt);
  • end;
  • 注意這個(gè)寫法,細(xì)節(jié)
  • 練習(xí)
  • declare
  • ????v_count?number?:=?0;
  • begin
  • ????execute?immediate?'select?count(*)?from?user_tables?where?table_name?=?''STUDENT'''?
  • –‘要用2個(gè)
  • ????into?v_count;
  • ????if?v_count?=?1?then
  • ????????dbms_output.put_line('找到');
  • ????else
  • ????????dbms_output.put_line('不存在');
  • ????end?if;
  • end;
  • /
  • 3.?游標(biāo)
  • 可以通過游標(biāo)操縱數(shù)據(jù)庫(kù),對(duì)游標(biāo)所指的行進(jìn)行update,?delete?
  • declare
  • ????v_no????student.sno%type;
  • ????v_name??student.sname%type;
  • ????cursor?s_cur?is?select?sno,?sname?from?student?for?update?of?sname;
  • begin
  • ????for?s_record?in?s_cur?loop
  • ????????fetch?s_cur?into?v_no,v_name;
  • ????????dbms_output.put_line(v_no||'?'||v_name);
  • --??????dbms_output.put_line(v_name||'?');
  • ????????if?v_no?=?'005'?then????????
  • ????????????update?student?set?sname?=?'HH'?where?current?of?s_cur;
  • ????????end?if;
  • ????end?loop;
  • ????commit;
  • end;
  • /
  • 有問題
  • 游標(biāo)的for循環(huán)中,不再需要用fetch了
  • 2008-10-27?Monday
  • 1.?PL/SQL塊調(diào)用過程
  • C:/Documents?and?Settings/sun>sqlplus
  • SQL*Plus:?Release?10.2.0.1.0?-?Production?on?星期一?10月?27?14:04:09?2008
  • Copyright?(c)?1982,?2005,?Oracle.??All?rights?reserved.
  • 請(qǐng)輸入用戶名:??sun
  • 輸入口令:
  • 連接到:
  • Oracle?Database?10g?Express?Edition?Release?10.2.0.1.0?-?Production
  • SQL>?set?serveroutput?on
  • SQL>?start?D:/sql
  • 001?Tom
  • 002?Mary
  • 005?HH
  • 005?HH
  • 003?Jam
  • 006?Hack
  • PL/SQL?過程已成功完成。
  • 2.?塊中的輸出
  • ????dbms_output.put_line(to_char(5));
  • ????dbms_output.put_line(3);
  • 2008-10-28?Tuesday
  • 1.?訪問表每一行的存儲(chǔ)過程
  • Testfor.sql
  • create?or?replace?procedure?testfor
  • is
  • begin
  • ????for?c?in?(select?*?from?student)?loop
  • ????????dbms_output.put_line(c.SNO?||?'??'?||?c.SNAME);
  • ????end?loop;
  • end?testfor;
  • /
  • SQL>?set?serveroutput?on
  • SQL>?start?D:/testfor
  • 過程已創(chuàng)建。
  • SQL>?execute?testfor
  • 001??Tom
  • 002??Mary
  • 005??HH
  • 005??HH
  • 003??Jam
  • 006??Hack
  • PL/SQL?過程已成功完成。
  • execute?testfor??直接調(diào)用過程
  • 通過for?c?in?(select?*?from?student)?loop
  • 這種循環(huán)方式達(dá)到游標(biāo)循環(huán)的效果,比用游標(biāo)要方便
  • 修改數(shù)據(jù)update的時(shí)候
  • create?or?replace?procedure?testfor
  • is
  • begin
  • ????for?c?in?(select?*?from?student)?loop
  • ????????dbms_output.put_line(c.SNO?||?'??'?||?c.SNAME);
  • ????????
  • ????????if?c.SNO?=?'005'?THEN
  • ????????????update?student?set?SNAME?=?'MM'?where?SNO?=?'005';
  • ????????????dbms_output.put_line('if?go');
  • ????????????dbms_output.put_line(c.SNO?||?'??'?||?c.SNAME);
  • ????????end?if;
  • ????????
  • ????end?loop;
  • ????commit;
  • end?testfor;
  • /
  • Update要全表掃描,沒有游標(biāo)那樣的單行處理功能
  • 2.?獲取列名
  • SQL>?select?column_name?from?all_tab_columns?where?table_name?='STUDENT';
  • COLUMN_NAME
  • ------------------------------------------------------------
  • SNO
  • SNAME
  • select?column_name?from?all_tab_columns?where?table_name?='STUDENT';
  • ?select?column_name?from?user_tab_cols?t?where?t.table_name=?'STUDENT'
  • SQL>?show?error
  • 顯示錯(cuò)誤信息
  • 3.?存儲(chǔ)過程練習(xí)
  • 編譯出現(xiàn)問題,要多嘗試
  • create?or?replace?procedure?GetColList(tname?in?varchar2)--,?list?in?out?varchar2)
  • is
  • ????c_list?varchar2(1000)?:=?'';
  • begin
  • ????for?c?in?(select?column_name?from?all_tab_columns?where?table_name?=?tname)?loop
  • ????????c_list?:=?c_list?||?c.COLUMN_NAME?||?',';
  • ????end?loop;
  • ????
  • ????dbms_output.put_line(c_list);
  • end?GetColList;
  • /
  • SQL>?start?D:/testfor
  • 過程已創(chuàng)建。
  • SQL>?execute?GetColList('STUDENT')
  • SNO,SNAME,
  • PL/SQL?過程已成功完成。
  • ????dbms_output.put_line(c_list);
  • SQL>?execute?GetColList('STUDENT')
  • SNO,SNAME
  • 總結(jié)

    以上是生活随笔為你收集整理的笔记(数据库)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。