oracle 您好,我的代码中有此ORA-01722问题[已关闭]

gudnpqoy  于 2022-12-11  发布在  Oracle
关注(0)|答案(1)|浏览(242)

Closed. This question is not reproducible or was caused by typos . It is not currently accepting answers.

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 days ago.
Improve this question
What happens is that I have this ORA-01722 error despite verifying that my tables have only numeric values but it does not identify it problem what I want is to create a function that adds any column of a query with two tables

create table empleado1(
   cod    varchar2(5) not null,
   nombre varchar2(15) not null,
   sueldo FLOAT not null
);
create table empleado2(
   cod    varchar2(5) not null,
   nombre varchar2(15) not null,
   sueldo FLOAT not null
);

insert into EMPLEADO1 (COD,NOMBRE,SUELDO) values ('00001','Ricardo',100);
insert into EMPLEADO1 (COD,NOMBRE,SUELDO) values ('00002','Jorje',100);
insert into EMPLEADO2 (COD,NOMBRE,SUELDO) values ('00001','Freeman',100);
insert into EMPLEADO2 (COD,NOMBRE,SUELDO) values ('00002','Pepe',100);

CREATE FUNCTION SF_PRE1 (columna FLOAT)
RETURN FLOAT
AS
total FLOAT;
BEGIN
    SELECT SUM(columna) INTO total
    FROM empleado1
    INNER JOIN empleado2 ON empleado1.sueldo = empleado2.sueldo;
    RETURN total;
END;
SELECT SF_PRE1('sueldo')
FROM dual;
this is the code
imzjd6km

imzjd6km1#

That function doesn't make much sense as

  • there's no columna column in any of those tables
  • there's no where condition (why are you passing a parameter, then?)
  • if function was to accept float , why are you passing a string ( 'sueldo' ) to it?

Something that compiles (but I have no idea whether it does what you wanted):

SQL> CREATE OR REPLACE FUNCTION sf_pre1 (p_cod IN empleado1.cod%TYPE)
  2     RETURN FLOAT
  3  AS
  4     total  FLOAT;
  5  BEGIN
  6     SELECT SUM (a.sueldo)
  7       INTO total
  8       FROM empleado1 a INNER JOIN empleado2 b ON a.cod = b.cod
  9      WHERE a.cod = p_cod;
 10
 11     RETURN total;
 12  END;
 13  /

Function created.

SQL> SELECT sf_pre1 ('00001') FROM DUAL;

SF_PRE1('00001')
----------------
             100

SQL>

相关问题