Put_Line error pl/sql For multiple variables

606 views Asked by At

I am trying to create a simple anonymous function. I am getting an error with the put_line that I can't find a solution to that is close to my problem.

for Sal in salPtr
loop
    if Sal.ESalary <= Threshold then 
        Tax:=0;
        newSal:=0;
        Tax := Sal.ESalary * Rates.Rate1;
        newSal := Sal.ESalary - Tax;
        dbms_output.put_line(Sal.Eid||': ' || Sal.ESalary ||' '|| Tax || ' '||newSal);
        Taxtotal := Taxtotal + tax;
    end if;

I have salPtr as a cursor and all the other variables are all set to zero in the declare statement. I need to print all the variables on the same line as it is set right now.

ORA-06550: line 42, column 23:
PLS-00382: expression is of wrong type
ORA-06550: line 42, column 13:
PL/SQL: Statement ignored
ORA-06550: line 43, column 34:
PLS-00306: wrong number or types of arguments in call to '||'
ORA-06550: line 43, column 13:
PL/SQL: Statement ignored

Any help would be greatly appreciated. I have the same error in another part for the else case, but trying to understand what I am doing here would really help.

1

There are 1 answers

0
BK Barathi On

I was able to execute below block without any issues. Please check your DBMS statements.

SET SERVEROUTPUT ON;

DECLARE
    tax         NUMBER;
    newsal      NUMBER;
    rates       NUMBER;
    rate1       NUMBER;
    threshold   NUMBER := 0;
    taxtotal    NUMBER;
    CURSOR salptr IS
    SELECT
        1 esalary,2 eid
    FROM
        dual;

BEGIN
    FOR sal IN salptr LOOP
        IF sal.esalary <= threshold THEN
            tax := 0;
            newsal := 0;
            --tax := sal.esalary * rates.rate1;
            newsal := sal.esalary - tax;
            dbms_output.put_line('op' ||sal.eid
                                 || ': '
                                 || sal.esalary
                                 || ' '
                                 || tax
                                 || ' '
                                 || newsal);

            taxtotal := taxtotal + tax;
        END IF;
    END LOOP;
--DBMS_OUTPUT.PUT_LINE ('ERROR :'||l_bt);
EXCEPTION
    WHEN OTHERS THEN
        dbms_output.put_line('ERROR :' || sqlerrm);
END;
/