1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| ![p1](D:\blog\数据库实验五\p1.JPG)create table major_J314 ( MajorNo varchar(20) primary key, MNAME varchar(50), loc varchar(20), mdean varchar(20), constraint mj_loc check (loc IN ('主校区', '南校区', '新校区', '铁道校区', '湘雅校区')) );
create or replace procedure P_table_J314( tname in char, fname in char) is l_file utl_file.file_type; v_sql varchar2(100); v_count number; begin l_file := utl_file.fopen('FILEPATH', fname, 'W'); utl_file.put_line(l_file,'create table '||tname); utl_file.put_line(l_file,'('); for name in (select column_name, data_type from user_tab_columns where table_name = upper(tname))loop utl_file.put_line(l_file, ' '||name.column_name||' '||name.data_type||' '); end loop; utl_file.put_line(l_file,');');
utl_file.fclose(l_file); end P_table_J314; . / exec P_table_J314('major_J314', '123.txt')
execute immediate 'select * from '||tname into v_sql for a in (v_sql)loop utl_file.put_line(l_file,'insert into '||tname||' values('); end loop; v_sql:='select * from ' || tname; execute immediate v_sql into v_count; utl_file.put_line(l_file,v_count); utl_file.put_line(l_file,')');
for a in (select * from major_J314)loop end loop;
for a in (select * from major_J314)loop utl_file.put_line(l_file,'insert into '||tname||' values('); for name in (select column_name from user_tab_columns where table_name = upper(tname))loop v_sql := name.column_name; utl_file.put_line(l_file,a.v_sql); end loop; utl_file.put_line(l_file,')'); end loop;
utl_file.put_line(l_file,'MajorNo varchar(20) primary key,MNAME varchar(50),loc varchar(20),mdean varchar(20)'); utl_file.put_line(l_file, select 'insert into '||tname||' values('||')');
select dbms_metadata.get_ddl('TABLE','major_J314','Tester') from dual;
utl_file.put_line(l_file, SELECT DBMS_METADATA.GET_DDL('TABLE','DEPT','SCOTT') FROM DUAL;) select * from cols WHERE TABLE_name=upper('table_name');
|