Manish
Manish

Reputation: 37

PL/SQL script giving errors

I've to work on some older EDW scripts, which I think are in PL/SQL and queries fech data from Oracle table as well. But there is some problem with them, the part which declares variables, as shown in the image gives error. I'm unable to understand why?

Below is some part of script,

VARIABLE begin_exp_date varchar2(8)
VARIABLE end_exp_date varchar2(8)
VARIABLE begin_cal_key number

Declare
begin
    :begin_exp_date := 'begin_exp_date';
    :end_exp_date := 'end_exp_date';
    :begin_cal_key := 'begin_cal_key';
end;

These lines produce error ORA-00900: Invalid SQL statement.

Any help?

Upvotes: 0

Views: 117

Answers (2)

Glyphfever
Glyphfever

Reputation: 145

If you plug the script in SQL*Plus, it will be executed without the ORA-00900 error. I guess you received the error when it was run in Toad.

Upvotes: 1

Phil
Phil

Reputation: 164733

If it is indeed PL/SQL, it should be more like this

DECLARE
    begin_exp_date varchar2(8);
    end_exp_date varchar2(8);
    begin_cal_key number;
BEGIN
    begin_exp_date := 'begin_exp_date';
    -- and so on
END;

You can set constant values to the variables in the DECLARE section if you want. Note that you've defined begin_cal_key as a NUMBER so cannot assign the string 'begin_cal_key'

Upvotes: 0

Related Questions