ORACLE中SQL产生记录的例子
如果要插入固定有序的数据,用一个SQL可以用下面的方法
select rownum-1 from dual connect by rownum < 21
但只支持9I或者更高版本,如果是8I就要建立个临时表了:alter table CMES.C_PARAMETER_NUM_T
drop primary key cascade;
drop table CMES.C_PARAMETER_NUM_T cascade constraints;
create table CMES.C_PARAMETER_NUM_T (
NUM_ID NUMBER(20) not null
);
alter table CMES.C_PARAMETER_NUM_T
add constraint PK_C_PARAMETER_NUM_T primary key (NUM_ID);
declare i integer;
begin
i:= 0;
loop
exit when i> 400 ;
i:=i+1;
INSERT INTO CMES.C_PARAMETER_NUM_T (NUM_ID)VALUES(I);
end loop;
end;
/
COMMIT;
drop primary key cascade;
drop table CMES.C_PARAMETER_NUM_T cascade constraints;
create table CMES.C_PARAMETER_NUM_T (
NUM_ID NUMBER(20) not null
);
alter table CMES.C_PARAMETER_NUM_T
add constraint PK_C_PARAMETER_NUM_T primary key (NUM_ID);
declare i integer;
begin
i:= 0;
loop
exit when i> 400 ;
i:=i+1;
INSERT INTO CMES.C_PARAMETER_NUM_T (NUM_ID)VALUES(I);
end loop;
end;
/
COMMIT;
这里还有注意一下,NULL列
如果UNION一个空值列,如:
select num_id,null qty from c_parameter_num_t where num_id < 20
在9I中可,但8I就要看相UNION的字段类型,否则会报类型不对,比如上面的例子就需要TO_NUMBER(NULL) QTY