0

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.

2
  • select .. FROM where? The parser [error] says, "I expected 'from' here, but I found 'in'. The position of the syntax error is indicated by the asterisk. The purpose of 'using [in] c' here is unclear and the question would benefit from having the goal explained. Commented Oct 1, 2016 at 17:08
  • edited the code ... that was a mistake... here now is the code Commented Oct 1, 2016 at 17:19

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks! why have to use "into" and not "in" ?
You should ask Oracle this question, this is how the langauge is built :)
In should be used as an sql condition docs.oracle.com/cd/B19306_01/server.102/b14200/…
For one thing, in is already in use for something else, while select into is the documented syntax for putting the output of a select query into a variable. (To a native English speaker, select count(*) in c would make no sense.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.