- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
作为标题,我正在写一些关于 Oracle 的存储过程,首先我检查了版本
SELECT * FROM v$version;
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
select 'Test: ' || nvl2('...', 'things', 'nothing') from dual;
select 'Test: ' || nvl2('', 'things', 'nothing') from dual;
Test: things
Test: nothing
create or replace procedure my_schema.SP_READ_MEMBER(noP in varchar2, nameP in varchar2, idNoP in varchar2, birthdayP in varchar2, resultP out sys_refcursor)
is
v_prg_name varchar2(20) := 'SP_READ_MEMBER';
sys_sql varchar2(1000);
begin
Insertlog(SYSDATE, v_prg_name, '1.0 Start');
sys_sql := sys_sql || 'select a.no, a.name, a.id_no, to_char(a.birthday, ''yyyy/MM/dd'') as birthday, ''REGISTERED'' as type, email, mobile from rep where 1=1 ';
sys_sql := sys_sql || nvl2(noP,'and no='''|| noP ||'''', ''); --PLS-00201
open resultP for sys_sql;
Insertlog(SYSDATE, v_prg_name, '2.0 Finished w/o error');
exception
when others then
declare
error_time VARCHAR2(30) := RTRIM(TO_CHAR(SYSDATE, 'YYYY/MM/DD, HH24:MI:SS'));
error_code NUMBER := SQLCODE;
error_msg VARCHAR2(300) := SQLERRM;
begin
rollback;
DBMS_OUTPUT.PUT_LINE(error_time || ',' || TO_CHAR(error_code) || ',' || error_msg);
Insertlog(SYSDATE, v_prg_name, error_msg || ', 3.0 ERROR, sql:' || sys_sql);
end;
end;
/
最佳答案
NVL2
适用于 SQL 但不适用于 PL/SQL。
不是每个 SQL 关键字都适用于 PL/SQL,这很愚蠢,但以前发生过几次。 Oracle 一直在逐步统一 SQL 和 PL/SQL,他们很有可能最终会使用这个功能。目前,我认为 My Oracle Support 文档 Note 359506.1 Pls-00201 Assigning The Result of NVL2() To A Variable In a PLSQL Block
涵盖了这个问题。 .尽管该文档不可用,即使对于具有支持访问权限的人也是如此。
现在,我建议使用不同的语法。我个人认为 CASE
版本更清晰,即使它有点冗长。
改变:
sys_sql := sys_sql || nvl2(noP,'and no='''|| noP ||'''', '');
sys_sql := sys_sql || case when nop is not null then 'and no='''|| noP ||'''' else '' end;
关于Oracle nvl2 在存储过程 PLS-00201 : identifier 'NVL2' must be declared 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57138515/
有时我会在代码中看到一个nvl()函数。对于 Java,它看起来像这样: public static String nvl(String value, String alternateValue) {
我正在尝试分析由离职开发人员编写的现有 Oracle 查询。我不精通 Oracle,我对使用此 DECODE 有点困惑Microfocus COBOL 中的函数app(其中 :BV-POS_YEAR
我有此表,其中NULL是NULL值,而不是字符串NULL: MYCOL -------- NULL example 为什么此查询不返回NULL行? select * from example_so w
select nvl(trunc(null),trunc(sysdate)) from dual; 在执行上述查询时,我收到以下错误 ORA-00932: inconsistent datatypes
我们有一个在 NVL 语句中使用 case 的查询但是我认为可以删除 NVL 请引用以下查询部分 - select f1, NVL(( CASE WHEN PR
select NVL(B.SEQID, A.LVL5_ID) LVL6_ID, NVL(B.NAME, ' ') LVL6_NAME, A.LVL5_ID FROM LVL5 A, ABC B WH
尝试执行使用空参数值的 native SQL 查询时出现 Oracle 错误。我把它归结为这个测试用例: String SQL_SELECT = "select * fro
我有以下代码: SELECT cr_ts, msg_id, info FROM messaging_log WHERE UPPER(INFO) LIKE '%' || TRIM(UPPER(P_INF
我试图在我的数据库中传递一个空值作为其他东西,它似乎在没有这样的 Where 子句的情况下工作 select NVL(column1, '0') column1 from table1 产生这个
我正在做一些从 Oracle 到 MSSQL 的转换,我正在阅读 Oracle 在 B Supported SQL Syntax and Functions 上的指南. 我注意到有人说有一个 NOT
我在 SQL Server 上执行以下查询但出现错误: SELECT DISTINCT t1.p_id "Id", (TO_CHAR("sysdate", 'YYYY') + least(SIGN((
我有一个 Web 表单,允许用户根据传递到过程的参数搜索和编辑 Oracle 表中的记录。这是我的数据: CAE_SEC_ID SEC_CODE APPR_STATUS 1 A
有人知道为什么 Oracle 的 NVL (和 NVL2)函数总是计算第二个参数,即使第一个参数不是 NULL ? 简单测试: CREATE FUNCTION nvl_test RETURN NUMB
我有两个 Oracle 12c (12.1.0.2.0) 数据库,其中一个对于以下查询(使用 SQL Developer 3.2.20.10)返回 'ok',而另一个则返回 ORA-01722:无效数
我在 SQL Server 上执行以下查询但出现错误: SELECT DISTINCT t1.p_id "Id", (TO_CHAR("sysdate", 'YYYY') + least(SIGN((
我正在使用 Java 6 和 Oracle 10。我有一个 java 语句,我想测试 null 或空字符串。 我的代码如下所示: PreparedStatement stmt = null; Stri
一段时间以来,我一直想知道 DECODE 和 NVL 函数的内部工作是如何完成的。如果其中的参数数量更多,DECODE 函数是否会产生更多开销? 此外,NVL 函数是否评估给定的值而不是 NULL,即
我正在尝试运行以下查询: select a.*, case when NVL (SELECT max(b.field1) FROM b where b.fiel
oracle 有一个很好的内置函数,用于 if null,但是我想做 if = 0;有没有一种简单的方法可以做到这一点? nvl(instr(substr(ovrflo_adrs_info,instr
有了这个, set serveroutput on size 900000; DECLARE test VARCHAR(255):=0; BEGIN SELECT id INTO test
我是一名优秀的程序员,十分优秀!