Error Code: 1109. Unknown table 'revers' in field list

All we need is an easy explanation of the problem, so here it is.

hello everyone this is a program to reverse a string the program works fine when values are given, but can’t fetch the details from the table.If the method is wrong then please tell.thanking everyone for the help.

    CREATE DATABASE rev;
    USE rev;
    CREATE TABLE revers
    (
       entnum MEDIUMINT
    );
    INSERT INTO revers(entnum)
    VALUES(435678);
    DELIMITER //
    CREATE procedure REV.revofnum1(IN P1 MEDIUMINT)
    wholeblock:BEGIN
          DECLARE y MEDIUMINT default 0;
          SET @d = 0;
          SET @rev = 0;
          SET y = P1;
          WHILE y>0 DO
            SET @d = y MOD 10;
            SELECT  @rev = @rev*10 + @d;
            SET y = y - @d;
            SET y = y/10;
        END WHILE;

       SELECT @rev;
    END // 
    CALL revofnum1(revers.entnum); 

And this is the error
:
Error Code: 1109. Unknown table ‘revers’ in field list

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

I don’t think you can pass a table.column to a function this way. I’d define a function:

CREATE function revofnum1(P1 MEDIUMINT) returns mediumint
BEGIN
  DECLARE y MEDIUMINT DEFAULT 0;
      SET @d = 0;
      SET @rev = 0;
      SET y = P1;
      WHILE y>0 DO
        SET @d = y MOD 10;
        SET @rev = @rev*10 + @d;
        SET y = y - @d;
        SET y = y/10;
    END WHILE;
   return @rev; 
END

and use that function in a select statement:

MariaDB [ghp]> select revofnum1(entnum) from revers;
+-------------------+
| revofnum1(entnum) |
+-------------------+
|            876534 |
+-------------------+

An alternative would be to use your procedure in another procedure:

begin not atomic
 declare done int default false;
 declare X mediumint;
 declare c cursor for select * from revers;
 declare continue handler for not found set done = true;
 open c;
 amehoela: loop
  fetch c into X;
  if done then
    leave amehoela;
  end if;
  call revofnum1(X);
 end loop;
 close c;
end
$$

giving:

+--------+
| @rev   |
+--------+
| 876534 |
+--------+
1 row in set (0.01 sec)

If you ever want to give your processors some time of, you could use the following:

CREATE OR REPLACE function revofnum1(P1 MEDIUMINT)
   returns mediumint
 BEGIN
   return convert(reverse(convert(p1,char)),unsigned);
 END

or, if you fail to remember the name of that function:

select convert(reverse(convert(entnum,char)),unsigned) from revers;

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply