NVL function in use in PL/SQL

The following SQL statement runs fine and returns data. Notice the ,nvl(fld.MULTSELECT,0).
SELECT exs.PK
,fld.Name
,fld.Desc_
,fld.DataTp
,case when rtrim(fld.InlineName) = '' then
NULL
--convert(nvarchar(255), Null)
else fld.InlineName
end InlineName
,fld.UOM
,fld.High
,fld.Low
,fld.CriticalHigh
,fld.CriticalLow
,fld.ChTp
,nvl(fld.MULTSELECT,0)
,fld.Type
,fld.IsProtected
,fld.RecTp
,fld.RecTpMbrSeq
,fld.SrcEtType
,fld.TargetEtType
,fld.FldCat
--,fc.ChFK FldCateoryFK
-- ,dbo.fn_StripCharacters(fld.Name, '^a-z0-9') SrcStagingFld -- strip out all characters except alphanumeric
,nvl(CAST(trim(fld.PropagateToEAV) AS NUMBER(1,0)),1) PropagateToEAV
,CAST(trim(fld.RecTimeStamp) AS NUMBER(1,0)) RecTimeStamp
,CAST(trim(fld.RecTimeStampEnd) AS NUMBER(1,0)) RecTimeStampEnd
,nvl(CAST(trim(fld.EtTypeTimeStampFld) AS NUMBER(1,0)),0) EtTimeStampFld
,nvl(CAST(trim(fld.EtTypeTimeStampEndFld) AS NUMBER(1,0)),0) EtTypeTimeStampEndFld
,nvl(CAST(trim(fld.EtTypeNameFld) AS NUMBER(1,0)),0) EtTypeNameFld
,nvl(CAST(trim(fld.EtTypeNameFldDeId) AS NUMBER(1,0)),0) EtTypeNameFldDeId
,CAST(trim(fld.EtSrcSystRecKey) AS NUMBER(1,0)) EtSrcSystRecKey
,CAST(trim(fld.EtSrcSystRecAlternativeRecKey) AS NUMBER(1,0)) EtSrcSystAlternativeRecKey
,CAST(trim(fld.ParentEtSrcSystRecKey) AS NUMBER(1,0)) ParentEtSrcSystRecKey
,CAST(trim(fld.MainEtRecTp) AS NUMBER(1,0)) MainEtRecTp
FROM Ld_UD_RecTp fld
-- left join MD_FldCat fc on fld.FldCat = fc.Name
left join Md_Fld exs on fld.RecTp = exs.RecTp and fld.Name = exs.Name
left join Aud_ModDataError Err on err.RecTp = fld.RecTp and Err.BatLogId = 1 -- check if the recordtype has any load errors
where nvl(fld.name,'zzzzzzz') <>'zzzzzzz'
and Err.RecTp is Null
When used in a stored procedure as follows, the procedure doesn't compile
create or replace PROCEDURE MD_Ld_Flds
v_BatLogID IN NUMBER DEFAULT NULL
AS
BEGIN
MERGE INTO MD_Fld targ
USING (SELECT exs.PK
,fld.Name
,fld.Desc_
,fld.DataTp
,case when rtrim(fld.InlineName) = '' then
NULL
--convert(nvarchar(255), Null)
else fld.InlineName
end InlineName
,fld.UOM
,fld.High
,fld.Low
,fld.CriticalHigh
,fld.CriticalLow
,fld.ChTp
,nvl(fld.MULTSELECT,0)
,fld.Type
,fld.IsProtected
,fld.RecTp
,fld.RecTpMbrSeq
,fld.SrcEtType
,fld.TargetEtType
,fld.FldCat
--,fc.ChFK FldCateoryFK
-- ,dbo.fn_StripCharacters(fld.Name, '^a-z0-9') SrcStagingFld -- strip out all characters except alphanumeric
,nvl(CAST(trim(fld.PropagateToEAV) AS NUMBER(1,0)),1) PropagateToEAV
,CAST(trim(fld.RecTimeStamp) AS NUMBER(1,0)) RecTimeStamp
,CAST(trim(fld.RecTimeStampEnd) AS NUMBER(1,0)) RecTimeStampEnd
,nvl(CAST(trim(fld.EtTypeTimeStampFld) AS NUMBER(1,0)),0) EtTimeStampFld
,nvl(CAST(trim(fld.EtTypeTimeStampEndFld) AS NUMBER(1,0)),0) EtTypeTimeStampEndFld
,nvl(CAST(trim(fld.EtTypeNameFld) AS NUMBER(1,0)),0) EtTypeNameFld
,nvl(CAST(trim(fld.EtTypeNameFldDeId) AS NUMBER(1,0)),0) EtTypeNameFldDeId
,CAST(trim(fld.EtSrcSystRecKey) AS NUMBER(1,0)) EtSrcSystRecKey
,CAST(trim(fld.EtSrcSystRecAlternativeRecKey) AS NUMBER(1,0)) EtSrcSystAlternativeRecKey
,CAST(trim(fld.ParentEtSrcSystRecKey) AS NUMBER(1,0)) ParentEtSrcSystRecKey
,CAST(trim(fld.MainEtRecTp) AS NUMBER(1,0)) MainEtRecTp
FROM Ld_UD_RecTp fld
-- left join MD_FldCat fc on fld.FldCat = fc.Name
left join Md_Fld exs on fld.RecTp = exs.RecTp and fld.Name = exs.Name
left join Aud_ModDataError Err on err.RecTp = fld.RecTp and Err.BatLogId = v_BatLogID -- check if the recordtype has any load errors
where nvl(fld.name,'zzzzzzz') <>'zzzzzzz'
and Err.RecTp is Null -- Exclude recordtypes which had errors
) src on (src.PK = Targ.PK)
when matched then
update Set      Targ.Name               =src.Name     
,Targ.Desc_               =src.Desc_     
,Targ.DataTp               =src.DataTp     
,Targ.InlineName               =src.InlineName     
,Targ.UOM               =src.UOM     
,Targ.High               =src.High     
,Targ.Low               =src.Low     
,Targ.CriticalHigh               =src.CriticalHigh     
,Targ.CriticalLow               =src.CriticalLow     
,Targ.ChTp               =src.ChTp     
,Targ.MultSelect               =src.MultSelect     
,Targ.Type               =src.Type     
,Targ.IsProtected               =src.IsProtected     
,Targ.RecTp               =src.RecTp     
,Targ.RecTpMbrSeq               =src.RecTpMbrSeq     
,Targ.SrcEtType               =src.SrcEtType     
,Targ.TargetEtType               =src.TargetEtType     
,Targ.FldCat               =src.FldCat     
--,Targ.SrcStagingFld               =src.SrcStagingFld     
,Targ.PropagateToEAV               =src.PropagateToEAV     
,Targ.RecTimeStamp               =src.RecTimeStamp     
,Targ.RecTimeStampEnd               =src.RecTimeStampEnd     
,Targ.EtTimeStampFld               =src.EtTimeStampFld     
,Targ.EtTimeStampEndFld               =src.EtTypeTimeStampEndFld     
,Targ.EtNameFld               =src.EtTypeNameFld     
,Targ.EtNameFldDeId               =src.EtTypeNameFldDeId     
,Targ.EtSrcSystRecKey               =src.EtSrcSystRecKey     
,Targ.EtSrcSystAlternativeRecKey=src.EtSrcSystAlternativeRecKey     
,Targ.ParentEtSrcSystRecKey               =src.ParentEtSrcSystRecKey     
,Targ.MainEtRecTp               =src.MainEtRecTp     
,targ.LastModified = SYSDATE
when not matched then --target 
insert (Name
,Desc_
,DataTp
,InlineName
,UOM
,High
,Low
,CriticalHigh
,CriticalLow
,ChTp
,MultSelect
,Type
,IsProtected
,RecTp
,RecTpMbrSeq
,SrcEtType
,TargetEtType
,FldCat
--,SrcStagingFld
,PropagateToEAV
,RecTimeStamp
,RecTimeStampEnd
,EtTimeStampFld
,EtTimeStampEndFld
,EtNameFld
,EtNameFldDeId
,EtSrcSystRecKey
,EtSrcSystAlternativeRecKey
,ParentEtSrcSystRecKey
,MainEtRecTp
,LastModified)
values (src.Name
,src.Desc_
,src.DataTp
,src.InlineName
,src.UOM
,src.High
,src.Low
,src.CriticalHigh
,src.CriticalLow
,src.ChTp
,src.MultSelect
,src.Type
,src.IsProtected
,src.RecTp
,src.RecTpMbrSeq
,src.SrcEtType
,src.TargetEtType
,src.FldCat
--,src.SrcStagingFld
,src.PropagateToEAV
,src.RecTimeStamp
,src.RecTimeStampEnd
,src.EtTimeStampFld
,src.EtTypeTimeStampEndFld
,src.EtTypeNameFld
,src.EtTypeNameFldDeId
,src.EtSrcSystRecKey
,src.EtSrcSystAlternativeRecKey
,src.ParentEtSrcSystRecKey
,src.MainEtRecTp
,SYSDATE);
END;
When you show errors you get the following;
7/7 PL/SQL: SQL Statement ignored
125/8 PL/SQL: ORA-00904: 'SRC"."MULTSELECT": invalid identifier
If I compile the procedure without the NVL, the procedure compiles with no errors.
We're running Oracle 11g

Hi,
In a sub-query (such as the USING sub-query in a MERGE statement), each column in the SELECT clause has to have a unique, valid name.
In an unnested SQL query, you don't have to name the columns at all. If you say
SELECT  NVL (dummy, 'FOO')
FROM    dual;In SQL*Plus, it will automatically name the column "NVL(DUMMY,'FOO')" for you, and it doesn't insist that the name be unique.
In a sub-query, you have to explicitly name all the columns, and make sure they're unique; for example
,nvl(fld.MULTSELECT,0)   AS multselect_or_0 
To be excruciatingly precise, some versions of Oracle let you get away with not having aliases in certain circumstances, but there's no point in doing so. Always assign unique aliases to columns in a sub-query.

Similar Messages

  • Types of functions cannot used in PL/SQL

    I'm trying to find out information on what types of functions cannot be used in PL/SQL. Can someone provide me with some directions and assistance?
    Thanks a lot.
    Tony

    its really depends upon your implementation way..
    if u are callinga pl/sql from a trigger, then you can't use any DDL or DML effecting on the same table.
    If u are calling a function then it must return only one value, it should not written more than one value.

  • What functions to use in oracle sql

    how to convert a decimal of 15 to decimal of 10
    and decimal of (15,2) to decimal of (12,2)

    876801 wrote:
    how to convert a decimal of 15 to decimal of 10
    and decimal of (15,2) to decimal of (12,2)Change the actual data type? If data type needs changing, the CAST() function can be used.
    E.g.
    SQL> create table footab(
      2          n       number(5,3)
      3  );
    Table created.
    SQL>
    SQL> insert into footab values( 99.123 );
    1 row created.
    SQL>
    SQL> select
      2          n,
      3          cast( n as number(5,1)) as N51
      4  from       footab;
             N        N51
        99.123       99.1
    SQL>

  • Using NVL function in Dynamic SQL

    Hi ,
    I have created a procedure using the Dynamic SqL and while using the NVL() getting the following error . ORA-00936: missing expression.
    The query I have written as
    SQL_Txt:=' INSERT INTO VF.tblCData (A, B, C, D, E, F,G,H,I,J)
         SELECT '||l_A||',
         '||l_B||',
         '||l_C||',
              '||l_D||',
              NULL ,
              '||L_F||',
              NVL('||Param1||',''''),
              NVL('||Param2||',''''),
              NVL('||Param3||',''''),
              NULL
              FROM '||ParamTbl1||' WHERE ' ;
    and so on.
    For Param1 I have data for one execution and Param2 and Param3 is null for that execution.
    While executing the same I am getting below
    INSERT INTO VF.tblCData (A, B, C, D, E, F,G,H,I,J)
    SELECT 25,
         1,
         7,
              6,
              NULL ,
              5,
              NVL(PurchaseDate,''),
              NVL(,''),
              NVL(,''),
              NULL
              FROM xyz.PBuyer@pocdb WHERE
    and error ORA-00936: missing expression is popping up for Param2 and Param3 NVL(,'')
    Any suggestion to resolve this issue is highly appreciable.
    Thanks
    Sudipta

    NVL(,''),Where's the first argument to NVL? That's the obvious problem. Empty strings are NULL in Oracle anyway, so just lose the NVL and insert the values...
    C:\>                                                                        
    C:\>sqlplus hr/hr                                                           
    SQL*Plus: Release 11.2.0.3.0 Production on Wed May 8 10:08:53 2013          
    Copyright (c) 1982, 2011, Oracle.  All rights reserved.                     
    Connected to:                                                               
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> set NULL I_AM_NULL                                                     
    SQL> create table x(y varchar2(20));                                        
    Table created.                                                              
    SQL> insert into x values ('');                                             
    1 row created.                                                              
    SQL> select * from x;                                                       
    Y                                                                           
    I_AM_NULL                                                                   
    SQL>                                                                        

  • Compilation problems using NVL function in Pro*C subselect

    I have come across a weird oracle problem. When I execute the following query in SQLPlus it works but when
    I include it in Pro*C code in a EXEC SQL statement it gives syntax errors and fails to compile. Any idea what I am doing wrong.
    SELECT DISTINCT
         A.ID_PERSON,
         C.ID_STAGE_PERSON_LINK ,
         A.NM_PERSON_FULL,
         A.NBR_PERSON_AGE,
         A.ADDR_PERSON_ST_LN_1,
         A.ADDR_PERSON_CITY,
         A.ADDR_PERSON_ZIP,
         A.CD_PERSON_STATE,
         A.CD_PERSON_COUNTY,
         A.NBR_PERSON_PHONE,
         C.CD_STAGE_PERS_REL_INT
         FROM
              PERSON A,
              STAGE_PERSON_LINK C
         WHERE
         C.ID_CASE = 88776721
         AND          A.IND_INVALID_PERS IS NULL
         AND          C.CD_STAGE_PERS_TYPE = 'PRN'
         AND          C.ID_PERSON = A.ID_PERSON
         AND C.ID_STAGE_PERSON_LINK =
    NVL (
                   (SELECT MAX(F.ID_STAGE_PERSON_LINK)
                   FROM STAGE_PERSON_LINK F
                   WHERE F.ID_PERSON=C.ID_PERSON
                   AND F.ID_CASE = C.ID_CASE
                        AND F.CD_STAGE_PERS_TYPE = 'PRN'
                        AND F.CD_STAGE_PERS_REL_INT IS NOT NULL)
                   (SELECT MAX(G.ID_STAGE_PERSON_LINK)
                   FROM STAGE_PERSON_LINK G
                   WHERE G.ID_PERSON=C.ID_PERSON
                   AND G.ID_CASE = C.ID_CASE
                        AND G.CD_STAGE_PERS_TYPE = 'PRN')
    AND A.ID_PERSON NOT IN
    SELECT S.ID_PERSON
    FROM STAGE_PERSON_LINK S,STAGE T
    WHERE S.ID_CASE = C.ID_CASE
    AND S.ID_CASE = T.ID_CASE
    AND S.ID_STAGE = T.ID_STAGE
    AND T.CD_STAGE &lt;&gt; 'INT'
    MINUS
    SELECT H.ID_PERSON
    FROM STAGE_PERSON_LINK H, STAGE F
    WHERE H.ID_CASE = F.ID_CASE
    AND H.ID_STAGE = F.ID_STAGE
    AND H.ID_CASE = C.ID_CASE
    AND H.CD_STAGE_PERS_ROLE &lt;&gt; 'XE'
    AND F.CD_STAGE &lt;&gt; 'INT'
    This query returns data when run in sqlplus.When used in a Pro*C C program and compiled the precompiler complains with syntax errors when used with EXEC SQL DECLARE CLSS82D_CURSOR CURSOR FOR &lt; query above &gt;.However removing the NVL function and retaining the subselect clause compiles but that is not what I want to do.
    Syntax error at line 262, column 20, file clss82d.pc:
    Error at line 262, column 20 in file clss82d.pc
    SELECT MAX( F.ID_STAGE_PERSON_LINK )
    ...................1
    PCC-S-02201, Encountered the symbol "MAX" when expecting one of the following:
    ( ) * + - / . @ | at, day, hour, minute, month, second, year,
    The symbol "(" was substituted for "MAX" to continue.
    Syntax error at line 263, column 10, file clss82d.pc:
    Error at line 263, column 10 in file clss82d.pc
    FROM STAGE_PERSON_LINK F
    .........1
    PCC-S-02201, Encountered the symbol "FROM" when expecting one of the following:
    , ) * + - / | at, day, hour, minute, month, second, year,

    Pro*C works bit differently tha sqlplus. try removing the blank line after
    SELECT MAX(G.ID_STAGE_PERSON_LINK)
    FROM STAGE_PERSON_LINK G
    WHERE G.ID_PERSON=C.ID_PERSON
    AND G.ID_CASE = C.ID_CASE
    AND G.CD_STAGE_PERS_TYPE = 'PRN')
    good luck,
    Gauranga

  • Problem Using NVL Function

    I ran across a problem with the format of an ASCI output file of an SQL script. The problem I have is with handling a particular column that contains account numbers. The column is defined with 8 characters. However not every entry has data. I have several fields that don't have any information.
    Originally in my script I had the following line that made the script fail:
    LPAD(TO_CHAR(TO_NUMBER(konten_nr)),8,'0'),
    I then changed the line to the following: (The script ran but now I notice that the formatting is wrong)
    LPAD(TO_NUMBER(LTRIM(konten_nr)),8,'0'),
    I attempted to use the NVL function that will return a value when there is nothing in the column field but it doesn't work. Does anyone know what I'm doing wrong?
    LPAD(NVL(TO_CHAR(TO_NUMBER(konten_nr),'FM999999999'),'0'),8,'0'),

    what is exactly your problem ?
    you want to translater " 1234" in "00001234" ? then simply use to_char(konten_nr,'FM00000000') .
    You want to translate " 1 1 1 1" in "01010101", then use replace(konten_nr,' ','0')
    Give us some samples

  • How to write a java function for use in where clause in SQL statement

    Hi,
    Does anyone know a good tutorial on how to write and include a Java class/function into Oracle.
    I'd like to write mathematical function to use in my queries, but the resources available in PL/SQL are very limited.
    Many thanx

    Pim,
    I see you got an answer in the PL/SQL forum.
    But in case you haven't seen it, perhaps this Web page will help:
    http://www.oracle.com/technology/tech/java/jsp/index.html
    Good Luck,
    Avi.

  • Function which returns multiple values that can then be used in an SQL Sele

    I'd like to create a function which returns multiple values that can then be used in an SQL Select statement's IN( ) clause
    Currently, the select statement is like (well, this is a very simplified version):
    select application, clientid
    from tbl_apps, tbl_status
    where tbl_apps.statusid = tbl_status.statusid
    and tbl_status.approved > 0;
    I'd like to pull the checking of the tbl_status into a PL/SQL function so my select would look something like :
    select application, clientid
    from tbl_apps
    where tbl_apps.statusid in (myfunction);
    So my function would be running this sql:
    select statusid from tbl_status where approved > 0;
    ... will return values 1, 5, 15, 32 (and more)
    ... but I haven't been able to figure out how to return the results so they can be used in SQL.
    Thanks for any help you can give me!!
    Trisha Gorr

    Perhaps take a look at pipelined functions:
    Single column example:
    SQL> CREATE OR REPLACE TYPE split_tbl IS TABLE OF VARCHAR2(32767);
      2  /
    Type created.
    SQL> CREATE OR REPLACE FUNCTION split (p_list VARCHAR2, p_delim VARCHAR2:=' ') RETURN SPLIT_TBL PIPELINED IS
      2      l_idx    PLS_INTEGER;
      3      l_list   VARCHAR2(32767) := p_list;
      4      l_value  VARCHAR2(32767);
      5    BEGIN
      6      LOOP
      7        l_idx := INSTR(l_list, p_delim);
      8        IF l_idx > 0 THEN
      9          PIPE ROW(SUBSTR(l_list, 1, l_idx-1));
    10          l_list := SUBSTR(l_list, l_idx+LENGTH(p_delim));
    11        ELSE
    12          PIPE ROW(l_list);
    13          EXIT;
    14        END IF;
    15      END LOOP;
    16      RETURN;
    17    END SPLIT;
    18  /
    Function created.
    SQL> SELECT column_value
      2  FROM TABLE(split('FRED,JIM,BOB,TED,MARK',','));
    COLUMN_VALUE
    FRED
    JIM
    BOB
    TED
    MARK
    SQL> create table mytable (val VARCHAR2(20));
    Table created.
    SQL> insert into mytable
      2  select column_value
      3  from TABLE(split('FRED,JIM,BOB,TED,MARK',','));
    5 rows created.
    SQL> select * from mytable;
    VAL
    FRED
    JIM
    BOB
    TED
    MARK
    SQL>Multiple column example:
    SQL> CREATE OR REPLACE TYPE myrec AS OBJECT
      2  ( col1   VARCHAR2(10),
      3    col2   VARCHAR2(10)
      4  )
      5  /
    Type created.
    SQL>
    SQL> CREATE OR REPLACE TYPE myrectable AS TABLE OF myrec
      2  /
    Type created.
    SQL>
    SQL> CREATE OR REPLACE FUNCTION pipedata(p_str IN VARCHAR2) RETURN myrectable PIPELINED IS
      2    v_str VARCHAR2(4000) := REPLACE(REPLACE(p_str, '('),')');
      3    v_obj myrec := myrec(NULL,NULL);
      4  BEGIN
      5    LOOP
      6      EXIT WHEN v_str IS NULL;
      7      v_obj.col1 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
      8      v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
      9      IF INSTR(v_str,',')>0 THEN
    10        v_obj.col2 := SUBSTR(v_str,1,INSTR(v_str,',')-1);
    11        v_str := SUBSTR(v_str,INSTR(v_str,',')+1);
    12      ELSE
    13        v_obj.col2 := v_str;
    14        v_str := NULL;
    15      END IF;
    16      PIPE ROW (v_obj);
    17    END LOOP;
    18    RETURN;
    19  END;
    20  /
    Function created.
    SQL>
    SQL> create table mytab (col1 varchar2(10), col2 varchar2(10));
    Table created.
    SQL>
    SQL> insert into mytab (col1, col2) select col1, col2 from table(pipedata('(1,2),(2,3),(4,5)'));
    3 rows created.
    SQL>
    SQL> select * from mytab;
    COL1       COL2
    1          2
    2          3
    4          5

  • Using insert command in NVL function

    How can we use insert command in a NVL function
    exapmle : INSERT INTO employee
    VALUES ( (NVL ( (SELECT emp_id
    FROM employee
    WHERE emp_name LIKE 'Test'),
    (insert into employee values((select max(emp_id)+1 from employee),'Test')))));
    I mean i will check for the record to exist in the table and if not exist i will add it to the table.

    998504 wrote:
    How can we use insert command in a NVL function
    exapmle : INSERT INTO employee
    VALUES ( (NVL ( (SELECT emp_id
    FROM employee
    WHERE emp_name LIKE 'Test'),
    (insert into employee values((select max(emp_id)+1 from employee),'Test')))));
    I mean i will check for the record to exist in the table and if not exist i will add it to the table.The first thing caught my eye is this
    max(emp_id) +1A real bad piece of code. Never do that. Ever thought about multi user environment? Use a SEQUENCE.
    If you want EMP_NAME to be unique (Which looks strange to me), then just add a UNIQUE constraint. You dont try to do what oracle already does really well.

  • How to use NVL Function

    hi,
    i want to use nvl Function in that Quary
    select f_words(SUM(a.AMOUNT)+sum(a.vat_amount) +
    nvl( (select sum(b.LABOUR_AMT)+sum(b.service_tax_amt)
    from LAB_WORK_DTL b
    where a.bill_no =b.bill_no), 0)
    )) as t
    from TRANSACTION_DETAILS a
    where a.bill_no =:P42_bill_no
    group by a.BILL_NO;
    i am using NVL in that Quary Like This
    select f_words*(nvl(S*UM(a.AMOUNT)+sum(a.vat_amount) +
    nvl( (select sum(b.LABOUR_AMT)+sum(b.service_tax_amt)
    from LAB_WORK_DTL b
    where a.bill_no =b.bill_no), 0)
    )) as t
    from TRANSACTION_DETAILS a
    where a.bill_no =:P42_bill_no
    group by a.BILL_NO;
    I want to use NVL Function In BOLD
    How Can I use NVL Functiion.
    Thanks
    Edited by: Manoj Kaushik on Mar 25, 2010 5:55 AM

    hi,
    select f_wordsl(SUM(a.AMOUNT)+sum(a.vat_amount) +
    nvl( (select sum(b.LABOUR_AMT)+sum(b.service_tax_amt)
    from LAB_WORK_DTL b
    where a.bill_no =b.bill_no), 0)
    )) as t
    from TRANSACTION_DETAILS a
    where a.bill_no =:P42_bill_no
    group by a.BILL_NO;
    i have two tables Bill no is comman field in both tables if i have not enter value in any one of the table .
    so how can i show Total amount in words if Bill NO are not in any one table.
    Thanks

  • Decode statement using nvl function

    I have inherited some code that using a decode and nvl. I'm unsure the purpose of it and want confirmation that it is flawed logic and a mistake. The situation can be recreated by setting up the following.
    CREATE TABLE XX_TEST
    (ID NUMBER,
    FIELD VARCHAR2(255)
    INSERT INTO XX_TEST(ID,FIELD) VALUES (1,'Yes')
    INSERT INTO XX_TEST(ID,FIELD) VALUES (2,'No')
    INSERT INTO XX_TEST(ID,FIELD) VALUES (3,NULL)
    commit
    SELECT ID,
    FIELD,
    DECODE(FIELD,'Yes','Yes Result do this', NVL(FIELD,'No'),'No result do this','catch all result do this')
    FROM XX_TEST
    I'm unsure of the NVL(FIELD,'No') I think the creator maybe thought this would catch the nulls but it doesn't.
    The values Null is not converted to No and instead drops into the catch all. Can anyone help with an explaination of of how oracle is interpretting the select statement. Any ideas on why NVL would be used like this? Seems a mistake?

    Hi,
    What about this -
    SQL>
    SQL>
    SQL>
    SQL> SELECT ID,
      2  FIELD,
      3  DECODE(nvl(FIELD,'No'),'Yes','Yes Result do this','No','No result do this','catch all result do this')
      4  FROM XX_TEST;
            ID FIELD                                              DECODE(NVL(FIELD,'NO'),'
             1 Yes                                                Yes Result do this
             2 No                                                 No result do this
             3                                                    No result do this
    Elapsed: 00:00:00.00
    SQL>
    SQL>

  • Use of Pl/Sql and Function

    Hi,
    Can we use a PL/Sql package or a Function in a sql query. If yes How.??
    Regards
    Sameer

    Sameer8 wrote:
    Can we use a PL/Sql package or a Function in a sql query. If yes How.??A function (whether declared in a package or a stand alone stored function) may be used in SQL providing it does not contain any OUT parameters...
    SQL> create function testf(x OUT number) return number is
      2  begin
      3    x := 1;
      4    return 2;
      5  end;
      6  /
    Function created.
    SQL> var my_x number
    SQL> select testf(:my_x) from dual;
    select testf(:my_x) from dual
    ERROR at line 1:
    ORA-06572: Function TESTF has out argumentsAnd it doesn't do any DML...
    SQL> create table x (x number);
    Table created.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace function testf return number is
      2  begin
      3    insert into x values (1);
      4    return 1;
      5* end;
    SQL> /
    Function created.
    SQL> select testf() from dual;
    select testf() from dual
    ERROR at line 1:
    ORA-14551: cannot perform a DML operation inside a query
    ORA-06512: at "SCOTT.TESTF", line 3

  • Which SQL function to use to get previous month's data?

    Hi
    The reporting need: Display of two month's payroll run results....current and previous (based on the parameter passed) in Oracle Discoverer.
    Data source: A table in which run result values are stored. Of course to be linked to number of other tables.
    Can somebody guide me on which SQL function to use to get the data for previous month?
    Secondly, as Discoverer does not support parameters, I cannot put parameter in the query itself. I'll be applying parameter later while generating my report.
    Please advice.
    Thanks and regards,
    Aparna

    It's not very clear in my head... but you can try :
    SQL> select * from test;
    ENAM        SAL DT
    TOTO       1000 30/05/06
    TOTO       1001 20/04/06
    TOTO       1002 11/03/06
    TATA       2000 30/05/06
    TATA       1500 20/04/06
    TUTU       3500 30/05/06
    6 rows selected.
    SQL> select ename, dt, sal currmonth,
                case when trunc(lag(dt,1,dt) over (partition by ename order by dt),'MM') = trunc(add_months(dt,-1),'MM')
                     then lag(sal,1,sal) over (partition by ename order by dt)
                     else null end prevmonth
         from   test
    SQL> /
    ENAM DT        CURRMONTH  PREVMONTH
    TATA 20/04/06       1500
    TATA 30/05/06       2000       1500
    TOTO 11/03/06       1002
    TOTO 20/04/06       1001       1002
    TOTO 30/05/06       1000       1001
    TUTU 30/05/06       3500
    6 rows selected.
    SQL>
    SQL> Nicolas.
    Just an additional question : do the previous month is current month-1, or is there hole in month suite (e.g. the previous month can be current month-2) ?
    Message was edited by:
    N. Gasparotto

  • Binding problem when using NVL function

    Hello.
    I have a problem with my ADF application (11.1.2.1).
    I use VO with a query (database view) - pivot table.
    If i use where clause like table.attr = :p_attr, everything works ok.
    If i use where clause like table.attr = NVL (:p_attr, table.attr) and put a value in :p_attr (executeWithParam) , query executes as if there is a null value.
    Debug console shows:
    Binding null of type 12 for "p_attr".
    Query with NVL works ok in sqldeveloper.
    But in jdev, as if the table attribute isn't bind to bind variable.
    If a just remove NVL function, it works.
    Any idea?
    Thanks.
    Regards
    Edited by: DejanH on Oct 6, 2011 1:32 PM

    Hello.
    I enter 50 in p_depart parameter and click "ExecuteWithParams". Query is executed and shows records (pivot table).
    But if i look at the log window i see that an empty query was executed first.
    <OracleSQLBuilderImpl> <bindParamValue> [427] Binding null of type 12 for "p_depart"
    <OracleSQLBuilderImpl> <bindParamValue> [428] Binding null of type 12 for "p_job"
    <OracleSQLBuilderImpl> <bindParamValue> [429] Binding null of type 12 for "p_hire_od"
    <OracleSQLBuilderImpl> <bindParamValue> [430] Binding null of type 12 for "p_hire_do"
    Then, it is autoexecuted for the second time with parameter set to the value i inserted.
    <OracleSQLBuilderImpl> <bindParamValue> [470] Binding param "p_depart": 50
    <OracleSQLBuilderImpl> <bindParamValue> [471] Binding null of type 12 for "p_job"
    <OracleSQLBuilderImpl> <bindParamValue> [472] Binding null of type 12 for "p_hire_od"
    <OracleSQLBuilderImpl> <bindParamValue> [473] Binding null of type 12 for "p_hire_do"
    The same happens in our query. But ours is much more complex and it takes a lot of time to first execute "empty" query and then with inserted parameter.
    We cannot use it.
    It looks like bug.
    Regards
    Edited by: DejanH on Oct 11, 2011 6:52 AM

  • How to find listing of modules which has used xyz PL/SQL function?

    Hi,
    How I can find the list of forms/reports which has used xyz pl/sql function?
    I want to delete a pl/sql function but before that I would like to
    make sure this function is not being used by any forms/report.
    Thanks for your help!!
    D

    There are many tools available for finding out the particular string across many forms in one shot.
    One such utility is forms apimaster.
    You can download it's 30 days free trial from the internet.

Maybe you are looking for

  • After Quicktime dowloads, it freezes half way through.

    I made a QT movie (size 640x480, H 264, K frame 24, frame reorder: yes, D rate: 2.30 mbits, sound: IMA 4:1 mono, about 76MB).  It runs fine on my MacBook. I uploaded it to my website, it was then sent through an email and downloaded to another MacBoo

  • Fill floating KF problem

    Hello In extractor and ODS I have key figure type floating. Sometimes extractors return value '0' for this field. In such cases, in update rules,   I fill KF using FM CONVERT_TO_LOCAL_CURRENCY. Problem is when I read value '4.1' i get '4.099999996E00

  • Data source from Oracle 10g problem

    Dear Sir, We met a problem when we moved on Oracle 10g from Oracle 9i in the loading process. The scenario is that SQL Server as Data Warehouse, SSIS as ETL tool. But the length of string column as data source table in SSIS grows up 4 times when usin

  • Old Mail Re-Appearing

    Having logged onto a wi-fi network in a hotel yesterday all the mail from the past 3-5 months keeps being resent to my mailbox even though it has been read and/or deleted. Obviously this is slowiing down the mailbox and because there are large emails

  • No of questions in sccm 2012 70-243 exam and the time duration

    how many question in sccm 70-243 exam and time duration for the exam