我对 SQL Server 中的 T-SQL 有丰富的经验,但最近开始从事一个使用 Oracle 数据库 (11g) 的项目,并且在编写看似基本的代码时遇到了一些问题。
我需要测试一组值是否是数字,并且只有在是数字时才将它们插入表中。PL/SQL 似乎没有 is_number 函数,所以我根据 AskTom 问题编写了自己的函数。
create or replace
function IS_NUMBER(str in varchar2) return boolean
IS
n number;
BEGIN
select to_number(str) into n from dual;
return (true);
EXCEPTION WHEN OTHERS THEN
return (false);
END;
Run Code Online (Sandbox Code Playgroud)
最终,我想在 WHERE 子句中使用这个函数,但现在我只是想让它运行:
declare
str varchar2(1);
n boolean;
begin
str := '0';
select ca_stage.is_number(str) into n from dual;
end;
Run Code Online (Sandbox Code Playgroud)
在 SQL Developer 中,尝试运行它会给出以下错误报告:
Error report:
ORA-06550: line 6, column 39:
PLS-00382: expression is of wrong type …Run Code Online (Sandbox Code Playgroud)