Jump to content

Unknown column in 'field list'

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
ankimo

ankimo

    Newbie

  • Members
  • Pip
  • 3 posts
Hi, everyone. I'm new here. I am trying to write a very simple mysql stored procedure that counts the number of records of any table passed to it. My problem is that when I call it with a table I have called "t4", I get this error:

Quote

Error Code : 1054
Unknown column 't4' in 'field list'
(0 ms taken)

I can't figure it out. Why does it think that my table is a column?


-- file count.sql

-- This procedure counts the number of records of any given table


DROP procedure if exists my_schema.count;


delimiter $$

CREATE procedure my_schema.count(IN tablename varchar(255), OUT num_recs int)


BEGIN

select count(*) from tablename;

END$$

delimiter ;



call my_schema.count(t4,@recs);

select @recs;


Thanks for your help!

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,298 posts
one thing I react on is that you never assign num_recs in your stored procedure

select count(*) from tablename into num_recs;

then, when calling the sp, I believe you would need

call my_schema.count("t4", @recs);
select @recs;
othervise, t4 would represent the column t4 in the current table and not the textstring "t4" that you want to send in.