I have the following sp:
CREATE OR REPLACE PROCEDURE db.schema.sp_1()
RETURNS DATE
LANGUAGE SQL
AS
$$
DECLARE
select_statement_stream VARCHAR;
select_statement_status VARCHAR;
r INTEGER;
select_date DATE;
stream_result RESULTSET;
query_result RESULTSET;
BEGIN
IF (SYSTEM$STREAM_HAS_DATA('db.schema.stream_1') = true) THEN select_statement_stream := 'SELECT process_date::DATE AS process_date FROM db.schema.stream_1 GROUP BY process_date::DATE LIMIT 1'; -- This stream has data
END IF;
stream_result := (EXECUTE IMMEDIATE :select_statement_stream);
LET c1 CURSOR FOR stream_result;
FOR row_variable IN c1 DO
select_date := to_date(row_variable.process_date);
select_statement_status := 'SELECT stg.process_date::DATE AS process_date, stg.table_name, stg.flag FROM db.schema.status_loads stg WHERE ''' || :select_date || ''' = stg.process_date::DATE';
query_result := (EXECUTE IMMEDIATE :select_statement_status);
LET c2 CURSOR FOR query_result;
FOR row_variable_2 IN c2 DO
r := row_variable_2.flag; -- flag is an integer column
insert into db.schema.test_table values (:r); -- Table db.schema.test_table has only 1 column 'id' declared as INTEGER
END FOR inner_loop;
END FOR outer_loop;
RETURN (:select_date);
END;
$$;
After this i want to do SELECT * FROM db.schema.test_table and see al the 0 and 1 that the db.schema.status_loads table already had loaded in that flag column
But when i called the sp:
call db.schema.sp_1();
Got the error:
Expression type does not match column data type, expecting DATE but
got NUMBER(38,0) for column process_date