获取语句如下: select car_model_id from car_info where no='XXXX'
最后需要的sql语句为:
select * from car_state_123,请问该语句如何写???
------解决方案--------------------
SQL code
FOR RPTT IN (select car_model_id from car_info where no='XXXX') LOOP
select * car_state_'||RPTT.CORP_HEAD||';
end loop;
------解决方案--------------------
SQL code
--在存储过程里面完成呗
--例:
create or replace procedure yyp_cwdh(table_name varchar)
is
str_sql varchar2(400):='';
begin
str_sql:='select * from '||table_name||' where 1=1';
execute immediate str_sql;
end yyp_cwdh;
------解决方案-------------------- 动态语句,就是在存储过程中用到的啊,难道你想一个SQL语句就出来????
------解决方案--------------------
------解决方案-------------------- declare str_l_sql varchar2(1000); begin for c in (select car_model_id from car_info where no='XXXX') loop
str_l_sql := 'select * from car_state_'||c.car_model_id; execute immediate str_l_sql into ...... end loop; end;
------解决方案-------------------- declare tabName varchar(1000); id number; tabSql varchar(1000); begin
select car_model_id into id from car_info where car_lic_plate='XXXXX'; --id:=select car_model_id from car_info where car_lic_plate='XXXXX'; --tabSql:=tabName||id tabSql := 'select * from :a'; EXECUTE IMMEDIATE tabSql USING 'car_state_'||to_char(id); commit; end;
------解决方案-------------------- 大概这样就行咯。。具体我就不写了。。希望你能看懂,我很懒,所以就不写全咯。
SQL code
CURSOR TASKLIST IS
Select JOB_NUM,
JOB_TYPE,
JOB_SERVICE_NAME,
JOB_NAME,
JOB_STATUS,
ERR_CODE,
ERR_MESSAGE,
DATELASTMAINT,
JOB_VALIDATE
From RP_TASKLIST
WHERE JOB_VALIDATE = 1
AND JOB_TYPE = 'GL'
And JOB_STATUS < IN_JOB_STATUS
ORDER BY JOB_NUM;
For R_TASKLIST IN TASKLIST LOOP
JOB_SERVICE_NAME_ := R_TASKLIST.JOB_SERVICE_NAME;
JOB_NUM_ := R_TASKLIST.JOB_NUM;
execute immediate 'BEGIN ' || R_TASKLIST.Job_Service_Name ||
'(:1,:2,:3);END;' --执行子任务
using in in_yyyymmdd, out out_ErrorNbr, out out_ErrorMsg;