ORACLE第二版習(xí)題答案_第1頁
ORACLE第二版習(xí)題答案_第2頁
ORACLE第二版習(xí)題答案_第3頁
ORACLE第二版習(xí)題答案_第4頁
ORACLE第二版習(xí)題答案_第5頁
已閱讀5頁,還剩36頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、第1章 Oracle安裝配置1Oracle服務(wù)端安裝好之后,在命令提示符下,利用echo %Path%命令查看此時(shí)的系統(tǒng)變量Path。在Windows系統(tǒng)中,單擊【開始】|【運(yùn)行】,并鍵入“cmd”,如下圖所示:單擊【確定】按鈕,將進(jìn)入Windows命令提示符,如下圖所示:鍵入echo %path%,并按下回車鍵,將顯示此時(shí)變量path的值,如下圖所示:2利用java version命令,查看此時(shí)java環(huán)境的版本,以確認(rèn)是否為Oracle安裝時(shí)自帶的Java文件。 在Windows的【Command】窗口中執(zhí)行java version命令,將看到本機(jī)Java環(huán)境的版本,如下圖所示:3Orac

2、le數(shù)據(jù)庫服務(wù)器安裝之后,在硬盤上搜尋名為oradata的文件夾。其中包含了所有數(shù)據(jù)庫的物理文件,查看已有數(shù)據(jù)庫的子文件夾及文件。一個(gè)數(shù)據(jù)庫的典型文件包括:后綴為CTL的控制文件;后綴為LOG的重做日志;后綴為DBF的數(shù)據(jù)文件。第2章 Oracle常用工具1有時(shí)無法連接數(shù)據(jù)庫,是由于多次安裝了服務(wù)端/客戶端,而導(dǎo)致客戶端軟件尋找TNS配置文件時(shí),混淆了當(dāng)前有效的路徑。此時(shí),可以利用將DNS描述直接作為參數(shù)傳遞給客戶端軟件的方式來登錄數(shù)據(jù)庫,從而不再使用TNS配置文件。嘗試?yán)脭?shù)據(jù)庫ORCL的TNS描述直接登錄數(shù)據(jù)庫。利用sqlplus+TNS配置登錄數(shù)據(jù)庫的命令如下所示:sqlplus sys

3、/abc123(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=)(PORT=1521)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl) as sysdba登錄成功的界面如下所示:2EZConnect是EasyConnect的簡稱。利用EZConnect可以在客戶端以IP+SID的方式登錄數(shù)據(jù)。利用NetManager配置EZConnect的連接方式,并利用客戶端軟件+EZConnect的方式登錄數(shù)據(jù)庫ORCL。首先保證Oracle數(shù)據(jù)庫服務(wù)器支持EZConnect連接方式,如下

4、圖所示:然后,在【Command】窗口中,利用sqlplus登錄數(shù)據(jù)庫:登錄成功的界面如下所示:當(dāng)然,也可以利用PL/SQL Developer進(jìn)行登錄:3客戶端連接Oracle數(shù)據(jù)庫連接時(shí),默認(rèn)端口為1521。創(chuàng)建一個(gè)新的監(jiān)聽程序,其端口為1522。然后將ORCL注冊于該監(jiān)聽程序。1)在Net Manager中創(chuàng)建名為LISTENER_1522。為【監(jiān)聽位置】填寫主機(jī)IP和端口號。注意其端口號為15222)選擇監(jiān)聽程序的【數(shù)據(jù)庫服務(wù)】,并為其輸入ORCL。3)利用【文件】|【保持網(wǎng)絡(luò)配置】,保存監(jiān)聽程序LISTENER_1522的信息。4)在Windows Command窗口中,啟動(dòng)監(jiān)聽程序

5、LISTENER_1522。C:lsnrctl start listener_1522LSNRCTL for 32-bit Windows: Version .2.0 - Production on 31-7月 -2011 19:37:17Copyright (c) 1991, 2004, Oracle. All rights reserved.Starting tnslsnr: please wait.TNSLSNR for 32-bit Windows: Version .2.0 - ProductionSystem parameter file is D:oracleNETWORKADM

6、INlistener.oraLog messages written to d:oraclenetworkloglistener_1522.logListening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.16.5)(PORT=1522)Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.16.5)(PORT=1522)STATUS of the LISTENER-Alias listener_1522Version TNSLSNR for 32-bi

7、t Windows: Version .2.0 - ProductionStart Date 31-7月 -2011 19:37:17Uptime 0 days 0 hr. 0 min. 0 secTrace Level offSecurity ON: Local OS AuthenticationSNMP OFFListener Parameter File D:oracleNETWORKADMINlistener.oraListener Log File d:oraclenetworkloglistener_1522.logListening Endpoints Summary. (DES

8、CRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.16.5)(PORT=1522)Services Summary.Service ORCL has 1 instance(s). Instance ORCL, status UNKNOWN, has 1 handler(s) for this service.The command completed successfully這樣,即使沒有其他監(jiān)聽程序的存在,或者1521端口沖突。Oracle也會(huì)自動(dòng)通過監(jiān)聽程序LISTENER_1522來連接數(shù)據(jù)庫ORCL。第3章 SQL Plus和PL/SQL1利用

9、sqlplus登錄數(shù)據(jù)庫,并查看數(shù)據(jù)庫版本。利用SQL Plus登錄數(shù)據(jù)庫:C:sqlplus / as sysdbaSQL*Plus: Release .2.0 - Production on 星期日 7月 10 18:43:50 2011Copyright (c) 1982, 2004, Oracle. All rights reserved.Connected to:Oracle Database 10g Enterprise Edition Release .2.0 - ProductionWith the Partitioning, OLAP and Data Mining opti

10、onsSQL在控制臺上打印出的信息,可以清楚看到Oracle數(shù)據(jù)庫的版本為.2.0。2在對數(shù)據(jù)庫進(jìn)行重要操作時(shí),首先應(yīng)該確認(rèn)數(shù)據(jù)庫身份,以免在其他數(shù)據(jù)庫上進(jìn)行操作。嘗試?yán)肧QL Plus顯示數(shù)據(jù)庫實(shí)例名稱。1)利用SQL Plus登錄數(shù)據(jù)庫:C:sqlplus / as sysdbaSQL*Plus: Release .2.0 - Production on 星期日 7月 10 18:43:50 2011Copyright (c) 1982, 2004, Oracle. All rights reserved.Connected to:Oracle Database 10g Enterpri

11、se Edition Release .2.0 - ProductionWith the Partitioning, OLAP and Data Mining optionsSQL2)鍵入show parameter instance_name來查看實(shí)例名稱SQL show parameter instance_nameNAME TYPE VALUE- - -instance_name string orcl3試著利用SQL Plus來創(chuàng)建一個(gè)新表test (id number, name varchar2(20)。可以通過如下步驟利用SQL Plus來創(chuàng)建一個(gè)新表:(1)利用SQL Plus

12、登錄數(shù)據(jù)庫ORCL。在Windows的【開始】|【運(yùn)行】的【打開】文本框中輸入sqlplus scott/abc123orcl來登錄數(shù)據(jù)庫ORCL。(2)在SQL Plus命令行下輸入如下命令來創(chuàng)建新表test:create table test (id number, name varchar2(20);(3)在SQL Plus會(huì)出現(xiàn)表創(chuàng)建成功的提示,如圖所示。此時(shí),證明表創(chuàng)建成功。第4章 Oracle數(shù)據(jù)庫1在數(shù)據(jù)庫中創(chuàng)建一個(gè)表lob_source(id number, description clob)。將表lob_test的數(shù)據(jù)導(dǎo)入另外一個(gè)數(shù)據(jù)表lob_dest(id number,

13、description clob)。1)創(chuàng)建表lob_sourceSQL create table lob_source(id number, description clob);Table created.2)向表lob_source中插入測試數(shù)據(jù)SQL insert into lob_source values(1, a clob text from source);1 row created.3)創(chuàng)建測試表lob_destSQL create table lob_dest(id number, description clob);Table created.4)向測試表lob_dest中

14、插入測試數(shù)據(jù),但是不包含clob類型的description列SQL insert into lob_dest(id) values(1);1 row created.5)利用表lob_source中的description信息,更新表lob_dest中的description信息。SQL update lob_dest set description = (select description from lob_source source where source.id = lob_dest.id);1 row updated.SQL select * from lob_dest; ID D

15、ESCRIPTION- -1 a clob text from source該實(shí)例實(shí)際說明了針對lob類型的數(shù)據(jù)的操作方式。由于lob類型的數(shù)據(jù)的特殊性,因此在實(shí)現(xiàn)數(shù)據(jù)庫遷移時(shí),如果遇到棘手的lob類型處理,可以考慮利用本例所演示的方法。2利用exp/imp方式,將數(shù)據(jù)庫orcl中users表的內(nèi)容,遷移到數(shù)據(jù)庫test中。1)在數(shù)據(jù)庫orcl中,創(chuàng)建測試表usersSQL create table users(user_id number, user_name varchar(20);Table created.SQL insert into users values(1, allen);1

16、 row created.SQL insert into users values(2, mike);1 row created.SQL commit;Commit complete. 2)導(dǎo)出表users到d:user.bakC:exp system/abc123/192.168.16.5/orcl tables=(users) file=d:/users.bakExport: Release .2.0 - Production on 星期三 7月 13 00:06:22 2011Copyright (c) 1982, 2004, Oracle. All rights reserved.Co

17、nnected to: Oracle Database 10g Enterprise Edition Release .2.0 - ProductionWith the Partitioning, OLAP and Data Mining optionsExport done in ZHS16GBK character set and AL16UTF16 NCHAR character setAbout to export specified tables via Conventional Path . . exporting table USERS 2 rows exportedExport

18、 terminated successfully without warnings.3)將d:user.bak的內(nèi)容導(dǎo)入數(shù)據(jù)庫testC:imp system/abc123/192.168.16.5/test tables=(users) file=d:/users.bakImport: Release .2.0 - Production on 星期三 7月 13 00:10:09 2011Copyright (c) 1982, 2004, Oracle. All rights reserved.Connected to: Oracle Database 10g Enterprise Edit

19、ion Release .2.0 - ProductionWith the Partitioning, OLAP and Data Mining optionsExport file created by EXPORT:V via conventional pathimport done in ZHS16GBK character set and AL16UTF16 NCHAR character set. importing SYSTEMs objects into SYSTEM. . importing table USERS 2 rows importedImport terminate

20、d successfully without warnings.3如果數(shù)據(jù)庫處于歸檔模式,那么,隨著時(shí)間的累積,歸檔日志將會(huì)占用很大空間。一旦達(dá)到默認(rèn)大小20G,那么將導(dǎo)致數(shù)據(jù)庫掛起,在告警日志中一般會(huì)有如下提示:ORA-00257: archiver error. Connect internal only, until freed。利用修改參數(shù)db_recovery_file_dest_size的方式,快速解決數(shù)據(jù)庫無法歸檔的問題。1)查看默認(rèn)空間大小SQL show parameter db_recovery_file_dest_sizeNAME TYPE VALUE- - -db_re

21、covery_file_dest_size big integer 2G2)修改其大小SQL alter system set db_recovery_file_dest_size=3G scope=both;System altered.這一用法,適合于快速處理現(xiàn)場由于歸檔日志過大導(dǎo)致的數(shù)據(jù)庫掛起。第5章 Oracle數(shù)據(jù)表對象1創(chuàng)建一個(gè)表空間testsize,其數(shù)據(jù)文件大小為2M,并設(shè)置自動(dòng)增長尺寸為1M。在表空間中建立一個(gè)數(shù)據(jù)表,并向其中插入大量數(shù)據(jù),觀察表空間文件的變化。1)創(chuàng)建一個(gè)大小為2M,自動(dòng)增長尺寸為1M的表空間SQL create tablespace testsize da

22、tafile e:databaseoracletestsize_data.dbf size 2M 2 autoextend on next 1M 3 / Tablespace created2)創(chuàng)建一個(gè)數(shù)據(jù)表test_tablespace_size(test_data varchar2(100)SQL create table test_tablespace_size(test_data varchar2(100) tablespace testsize; Table created3)利用如下SQL語句向表test_tablespace_size中插入數(shù)據(jù)SQL begin 2 for i

23、in 1.100000 loop 3 insert into test_tablespace_size values(0123456789); 4 end loop; 5 commit; 6 end; 7 / PL/SQL procedure successfully completed4)此時(shí),表空間文件testsize_data.dbf將增長為3M。2刪除表空間testsize,同時(shí)刪除其物理文件。刪除表空間應(yīng)該使用drop tablespace命令,同時(shí)刪除物理文件,應(yīng)使用including contents and datafiles。SQL drop tablespace tests

24、ize including contents and datafiles;Tablespace dropped.3在數(shù)據(jù)庫中創(chuàng)建一個(gè)表test_bak,并向其中插入10條記錄。利用exp/imp命令來實(shí)現(xiàn)該數(shù)據(jù)表的備份/恢復(fù)。1)在數(shù)據(jù)庫中創(chuàng)建表test_bak(id number)。SQL create table test_bak(id number); Table created2)向其中插入10條數(shù)據(jù)。SQL begin 2 for i in 1.10 loop 3 insert into test_bak values(i); 4 end loop; 5 end; 6 / PL/SQ

25、L procedure successfully completedSQL commit; Commit complete3)利用exp命令備份該表C:exp system/abc123/192.168.16.5/orcl tables=(test_bak) file=d:/test_bak.bakExport: Release .2.0 - Production on 星期六 7月 16 14:51:54 2011Copyright (c) 1982, 2004, Oracle. All rights reserved.Connected to: Oracle Database 10g En

26、terprise Edition Release .2.0 - ProductionWith the Partitioning, OLAP and Data Mining optionsExport done in ZHS16GBK character set and AL16UTF16 NCHAR character setAbout to export specified tables via Conventional Path . . exporting table TEST_BAK 10 rows exportedExport terminated successfully witho

27、ut warnings.4)在數(shù)據(jù)庫中刪除表test_bak。SQL drop table test_bak; Table dropped5)將表test_bak重新導(dǎo)入數(shù)據(jù)庫C:imp system/abc123/192.168.16.5/orcl tables=(test_bak) file=d:/test_bak.bakImport: Release .2.0 - Production on 星期六 7月 16 14:54:24 2011Copyright (c) 1982, 2004, Oracle. All rights reserved.Connected to: Oracle D

28、atabase 10g Enterprise Edition Release .2.0 - ProductionWith the Partitioning, OLAP and Data Mining optionsExport file created by EXPORT:V via conventional pathimport done in ZHS16GBK character set and AL16UTF16 NCHAR character set. importing SYSTEMs objects into SYSTEM. . importing table TEST_BAK 1

29、0 rows importedImport terminated successfully without warnings.6)重新查詢表test_bakSQL select * from test_bak; ID- 1 2 3 4 5 6 7 8 9 10 10 rows selected第6章 約束1查看表customers的主鍵狀況,如果有,則重建其主鍵,如果沒有,選擇其中一列創(chuàng)建主鍵。1)利用如下SQL語句查看表customers的主鍵狀況:SQL select table_name, constraint_name, constraint_type, status from use

30、r_constraints 2 where table_name = CUSTOMERS and constraint_type=P; TABLE_NAME CONSTRAINT_NAME CONSTRAINT_TYPE STATUS- - - -CUSTOMERS SYS_C005015 P ENABLED2)此時(shí),在已有主鍵的情況下,首先刪除主鍵SYS_C005015。SQL alter table customers drop primary key; alter table customers drop primary key ORA-02273: this unique/primar

31、y key is referenced by some foreign keys3)表customers中的主鍵與其他表的外鍵關(guān)聯(lián),可以利用cascade選項(xiàng)來刪除關(guān)聯(lián)約束。SQL alter table customers drop primary key cascade; Table altered4)重新創(chuàng)建基于列customer_id的主鍵。SQL alter table customers add primary key(customer_id); Table altered2在數(shù)據(jù)庫中,創(chuàng)建表country(country_id, country_name)、city(city_i

32、d, country_id,city_name),并建立city.country_id到country.country_id的外鍵關(guān)聯(lián)。1)創(chuàng)建表country和citySQL create table country(country_id number, country_name varchar2(50); Table created SQL create table city(city_id number, city_name varchar2(50), country_id number); Table created2)在表country的country_id列上創(chuàng)建主鍵約束SQL a

33、lter table country add primary key(country_id); Table altered3)在表city上創(chuàng)建country_id到表country(country_id)的外鍵關(guān)聯(lián)SQL alter table city add foreign key (country_id) references country(country_id); Table altered3驗(yàn)證所建外鍵關(guān)聯(lián)的作用。1)嘗試向表city中添加城市信息。SQL insert into city (city_id, city_name, country_id) values (1, 北

34、京, 1); insert into city (city_id, city_name, country_id) values (1, 北京, 1) ORA-02291: integrity constraint (SYSTEM.SYS_C005086) violated - parent key not found由于表country中并不存在country_id為1的值,因此,將導(dǎo)致添加失敗。2)向表country中添加country_id為1的信息。SQL insert into country values(1, 中國); 1 row inserted3)再次為表citry添加城市信息

35、。SQL insert into city (city_id, city_name, country_id) values (1, 北京, 1); 1 row inserted第7章 視圖1在數(shù)據(jù)庫中不存在表animals(animal_id, animal_name, animal_type)的情況下,強(qiáng)制創(chuàng)建視圖vw_animal_cat(animal_id, animal_name)。該視圖中,僅含有animal_type=cat的貓科動(dòng)物的信息。SQL create or replace force view vw_animal_cat(animal_id, animal_name)

36、2 as 3 select animal_id, animal_name, animal_type from animals where ainmal_type=cat 4 / Warning: View created with compilation errors2創(chuàng)建一個(gè)物化視圖mv_user_objects(object_type, objectCount),其數(shù)據(jù)來源于user_objects(owner, count(object_name),也就是對每種object類型統(tǒng)計(jì)其object的數(shù)目。1)因?yàn)槲锘晥D中,不能使用子查詢。而關(guān)系視圖又被當(dāng)做子查詢看待。因此,首先需要獲得u

37、ser_objects的拷貝,創(chuàng)建一個(gè)新表tmp_user_objects。SQL create table tmp_user_objects as select * from user_objects; Table created2)利用新表tmp_user_objects來創(chuàng)建物化視圖SQL create materialized view mv_user_objects 2 as 3 select object_type, count(object_name) object_count from tmp_user_objects 4 group by object_type 5 / Ma

38、terialized view createdSQL select * from mv_user_objects; OBJECT_TYPE OBJECT_COUNT- -FUNCTION 7INDEX 189INDEX PARTITION 31LOB 24PACKAGE 2PACKAGE BODY 2PROCEDURE 9QUEUE 4SEQUENCE 25SYNONYM 8TABLE 197TABLE PARTITION 27TRIGGER 16TYPE 4VIEW 16 15 rows selected3分別啟用/禁用物化視圖mv_user_objects,來查看select object

39、_type, count(object_name) object_count from tmp_user_objects的執(zhí)行效率。1)對于SQL語句,select owner, count(object_name) from dba_objects group by owner未啟用查詢重寫功能時(shí),其執(zhí)行計(jì)劃如下所示:2)利用enable query rewrite選項(xiàng),啟用物化視圖mv_user_objects的查詢重寫功能alter materialized view mv_user_objects enable query rewrite3)重新執(zhí)行相同的SQL語句,查看此時(shí)的執(zhí)行計(jì)劃

40、第8章 函數(shù)與存儲(chǔ)過程1創(chuàng)建一個(gè)函數(shù)is_date,并傳入一個(gè)字符串函數(shù)。如果該字符串可以轉(zhuǎn)換為“YYYY-MM-DD hh24:mi:ss”形式的日期,那么返回為真,否則返回為假。1)首先利用create or replace function命令創(chuàng)建is_date函數(shù)SQL create or replace function is_date (param varchar2) return varchar2 is 2 d date; 3 begin 4 d:=to_date (nvl (param, ), yyyy-mm-dd hh24:mi:ss); 5 return TRUE; 6 7

41、 exception 8 when others then 9 return FALSE; 10 end; 11 / Function createdto_date (nvl (param, ), yyyy-mm-dd hh24:mi:ss)用于將字符串參數(shù)param轉(zhuǎn)換為日期時(shí)間型,如果轉(zhuǎn)換成功,則返回“TRUE”;exception則用于處理異常情況,如果發(fā)生異常,函數(shù)將返回 “TRUE”。2)可以利用如下語句測試is_date()函數(shù)。SQL select is_date(2010) as is_date from dual; IS_DATE-FALSESQL select is_dat

42、e(abc) as is_date from dual; IS_DATE-FALSESQL select is_date(20100512) is_date from dual; IS_DATE-TRUE2創(chuàng)建一個(gè)存儲(chǔ)過程find_student,并傳入?yún)?shù)學(xué)生姓名(studentName),打印表students中所有同名的學(xué)生信息。如果未找到同名學(xué)生,那么打印“無名為xxx的學(xué)生”。1)利用如下SQL語句創(chuàng)建存儲(chǔ)過程find_studentSQL create or replace procedure find_student(studentName varchar2) 2 as 3 4

43、begin 5 declare student_count number; 6 begin 7 select count(*) into student_count from students where student_name=studentName; 8 if student_count0 then 9 dbms_output.put_line(共找到 | student_count | 個(gè)名為 | studentName | 的學(xué)生!); 10 else 11 dbms_output.put_line(未找到名為 | studentName | 的學(xué)生!); 12 end if; 13

44、 end; 14 end; 15 / Procedure created2)嘗試查找名為“張三”的學(xué)生SQL exec find_student(張三); 共找到3個(gè)名為張三的學(xué)生! PL/SQL procedure successfully completed3)嘗試查找名為“李四”的學(xué)生SQL exec find_student(李四); 未找到名為李四的學(xué)生! PL/SQL procedure successfully completed3利用PL/SQL Developer的Debug功能調(diào)試存儲(chǔ)過程find_student。1)在PL/SQL Developer的Procedures

45、下,找到存儲(chǔ)過程find_student。2)在右鍵菜單中選擇【Test】3)在參數(shù)欄內(nèi)填入要傳入的參數(shù),并單擊Debug按鈕或者按下F9。4)此時(shí),調(diào)試步驟按鈕欄將變?yōu)榭捎?。從左至右依次為:Run(繼續(xù)執(zhí)行,直至程序結(jié)束,或者下一個(gè)斷點(diǎn))Step into(進(jìn)入存儲(chǔ)過程/函數(shù)內(nèi)部)Step Over(執(zhí)行當(dāng)前語句,在下一條語句處停止)Step out(跳出當(dāng)前存儲(chǔ)過程/函數(shù))Run to next exception(執(zhí)行直至下次拋出異常)4)利用這5個(gè)按鈕,即可進(jìn)行存儲(chǔ)過程的調(diào)試。第9章 游標(biāo)1聲明一個(gè)游標(biāo)cu_sutdnet,并向該游標(biāo)傳遞參數(shù)studentName,來獲得所有與參數(shù)同名

46、的學(xué)生信息。對該游標(biāo)依次執(zhí)行打開、獲取、關(guān)閉的步驟來依次打印獲得的學(xué)生信息。1)聲明帶有參數(shù)的游標(biāo)時(shí),應(yīng)將參數(shù)列表置于小括號內(nèi)declare cursor cu_student_id_name(studentName)2)聲明變量臨時(shí)存取學(xué)生姓名和學(xué)號 student_id students.student_id%type; student_name students.student_name%type; 3)打開游標(biāo)時(shí),傳入?yún)?shù)studentNameopen cu_student_id_name(張三); 4)獲取游標(biāo)數(shù)據(jù)fetch cu_student_id_name into stude

47、nt_id, student_name; 5)循環(huán)打印學(xué)生信息while cu_student_id_name %found loop dbms_output.put_line(student_id | : | student_name); fetch cu_student_id_name into student_id, student_name; end loop;6)關(guān)閉游標(biāo)close cu_student_id_name; 7)執(zhí)行結(jié)果如下SQL declare cursor cu_sutdnet(studentName in varchar2) is 2 select student

48、_id, student_name 3 from students where student_name=studentName; 4 5 student_id students.student_id%type; 6 student_name students.student_name%type; 7 begin 8 open cu_sutdnet(張三); 9 fetch cu_sutdnet into student_id, student_name; 10 11 while cu_sutdnet%found loop 12 dbms_output.put_line(student_id

49、| : | student_name); 13 fetch cu_sutdnet into student_id, student_name; 14 end loop; 15 16 close cu_sutdnet; 17 end; 18 / 17:張三18:張三21:張三 PL/SQL procedure successfully completed2聲明一個(gè)名為studentname的變量,然后利用cursor for游標(biāo)來實(shí)現(xiàn)習(xí)題1的功能。通過修改studentname的值,來模擬傳入?yún)?shù)功能。SQL begin 2 declare 3 studentname varchar2(20); 4 begin 5 studentname := 張三; 6 for student in (select * from students where student_name = studentname) loop 7 dbms_output.put_line(student.student_id | : | 8 student.stu

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論