Click here to Skip to main content
15,886,077 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
dear all

have to call sql file from a batch file and pass a parameter .

if parameter passed is a then select sum(a) column
if parameter passed is b then select sum(b)
if parameter passed is c then select sum(a+b)

and save output into file name after parameter passed.



it gives me error pls 00428

What I have tried:

set verify off

spool &&1


var param VARCHAR2(20);
begin
:param :=  '&&1';
end;
/

begin
if (:param = 'a9001') then
 :param := 'a233+a244';


else
if (:param = 'a9002') then
:param := 'a596+a561-a501';

end if;
end if;

DBMS_OUTPUT.PUT_LINE (:param);

select 
NVL(sum( case when yr=2017 and mon=3 then  :param end),0) MARCH17,
NVL(sum( case when yr=2018 and mon=3 then  :param end),0) MARCH18
from sales



end;
/
spool off

exit;
Posted
Updated 5-Nov-18 21:40pm

1 solution

That error means "an INTO clause is expected in this SELECT"

You need to put the results of your select "into" a variable so that you can access the return value from the procedure.

Have a look at the solutions here[^] which was literally the first link displayed when I googled for "error pls 00428"

E.g. (untested)
SQL
select 
NVL(sum( case when yr=2017 and mon=3 then  :param end),0) INTO MARCH17
from sales
The code you have posted bears only the slightest resemblance to the problem as you described it though ... I don't understand why you are attempting to get two return values nor why you would hard code the year and month ... they should be parameters that are passed in.

[EDIT] - I missed the use of SUM so the OP is now getting ORA-00934.

If I was approaching this problem from scratch I would probably do something like the following (again untested sorry, I don't have an Oracle instance here)
SQL
select sum(colA) totA, sum(colB) totB, sum(colA + colB) totC
into totA, totB, totC
FROM ... etc
rather than attempting to do some clever dynamic sql. That should move the group function SUM "out of the way" of the INTO.
 
Share this answer
 
v2
Comments
Shilpa_g2 6-Nov-18 3:57am    
thanks for replying

"Why you would hard code the year and month"

thats what is next change .

putting into before march17 giving error PL/SQL: ORA-00934
CHill60 6-Nov-18 4:53am    
I've updated my solution. Sorry I'm not able to test these suggestions properly at the moment
Shilpa_g2 6-Nov-18 6:04am    
i have to choose column depending upon the parameter passed. all values not to be shown.
CHill60 6-Nov-18 6:17am    
Having summed the totals you then decide which value to return based on the parameter passed using a CASE statement.
By the way, do you really have columns called 'a596', 'a561' and 'a501'?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900