如何在select中迭代变量?我收到错误消息
DECLARE
ESTACION_ID NUMBER(6) :=3;
BEGIN
SELECT
100*TOTAL_TAX_AMB1/(SELECT COUNT(*) FROM ITV2 WHERE ITV2.C_RESULTADO=1 AND ITV2.C_ESTACION_ID= ESTACION_ID ) AS TAXIS_Y_AMBULANCIAS_PRIMERA
...
END;
答案 0 :(得分:0)
您可以使用USING子句绑定变量
DECLARE
ESTACION_ID NUMBER(6) :=3;
v_sql varchar2(32767);
BEGIN
v_sql := 'SELECT 100*TOTAL_TAX_AMB1/(SELECT COUNT(*) FROM ITV2 WHERE ITV2.C_RESULTADO=1 AND ITV2.C_ESTACION_ID= :1) AS TAXIS_Y_AMBULANCIAS_PRIMERA
...'
EXECUTE IMMEDIATE v_sql INTO ... USING ESTACION_ID;
END;