Apoorv singhai Apoorv singhai - 2 months ago 7
SQL Question

Pl-sql code showing error

I am a newbie to pl-sql. the following code is generating error

declare
c number;
a varchar2(20);
b varchar2(20);
begin
a:='appy';
b:='1234';
select count(*) in c from userdetails where userid=a and password=b;
dbms_output.put_line('=--=-='||c);
end;
/


is generating the error message

select count(*) in c from userdetails where userid=a and password=p;
*
ERROR at line 8:
ORA-06550: line 8, column 17:
PL/SQL: ORA-00923: FROM keyword not found where expected
ORA-06550: line 8, column 1:
PL/SQL: SQL Statement ignored


My table is userdetails with 2 columns userid and password both are varchar2 type.

Answer

If you want to select your query result into c try replace the "in" to "into" and you should also specify the table you are selecting from:

declare
    c number;
    a varchar2(20);
    b varchar2(20);
begin
    a:='appy';
    b:='1234';
    select count(*) into c from userdetails where userid=a and password=b;
    dbms_output.put_line('=--=-='||c);
end;

For more info you can read the docs.

Comments