Pl/sql using DECODE

Hello,
i have question regarding PL/SQL using DECODE when i use following qurey in SQL plus it is working fine but when i try to run in tode it only display value of g.
everything else is blank........
so can u plz assist me on that .....
thanks in advance!!!!!!!!!!
SELECT
b.g,b.s,
COUNT(DECODE(a.u,'R',a.rep)) AS R,
COUNT(DECODE(a.u,'u',a.rep)) AS U,
COUNT(DECODE(a.u,'C',a.rep))AS C,
COUNT(DECODE(a.u,'I',a.rep)) AS I,
COUNT(DECODE(a.u,NULL,a.rep)) AS B
FROM AREA a, data b
WHERE a.rep = '454637'
AND a.rep = b.emp
GROUP BY b.g,b.s

Very strange.
Find out if there are alterations to your SQL*PLUS envirionment. Warren mentioned user/database wierdness; the ALTER SCHEMA and other commands can affect privilges and what objects you can see. Sometimes these commands are buried in LOGIN.SQL and GLOGIN.SQL files (for SQL*PLUS), and more hard to find they can call files buried on a network somewhere.
Try the query without the DECODE() and see what's in the table without trying to modify the values in both envirionments.

Similar Messages

  • Using DECODE Function in SQL

    I need to know if there is any way to use a range of values from
    database and decode to certain text. I am able to do with one
    value.
    for example:
    DECODE(column_name,'216767111','Unlimited',column_name)
    above argument works with one value only. How about a range,
    ex: 216767000 to 216767111. I need to use only SQL. No PL/SQL.
    Kinldly need some body's help
    Thanks
    Munis

    Which version of the database? If it's 8i+ then you can use
    the CASE function
    for example:
    (CASE WHEN column_name between 216767000 and 216767111
    THEN 'Unlimited' ELSE column_name END)
    This won't work in PL/SQL because they're introducing a CASE
    statement does soemthing different.
    rgds, APCHello Andrew
    Thank you for response. I am using 8i. 8.1.6. However using
    CASE, I get inconsistent data type, ORA-00932: inconsistent
    datatypes. I able to work it out with other response using
    DECODE(sign(. Do you have any idea why i am getting this error.
    If time permits, let me know

  • Use sql function decode with Zend code

    Hi,
    I need to use sql function DECODE() in a query for PHP Code. This query works well in sql*plus but PHP returns
    the following error message:
    Parse error: syntax error, unexpected T_STRING in C:\Program Files\Zend\Apache2\htdocs\Compta\compta2.php on line 16
    the query is :
    $query =
    'select substr(c.NUM,1 ,2) Compte ,
    c.designation , a.Periode
    ,decode(substr(c.NUM,1 ,1), '1',1, '2',1,'3',1,-1) cp_type ,
    sum(credit) - sum(debit) Montant
    from ecritures a, clients b, compte c
    where
    b.NUM (+) =a.NUM
    and a.DATEECRITURE between to_date(:debut, \'dd/mm/yy\') and to_date(:fin, \'dd/mm/yy\')
    and substr(a.num,1,2) =c.num
    group by substr(c.NUM,1 ,1), substr(c.NUM,1,2) , c.designation ,a.periode
    order by compte ';
    Can any one help me ???
    Thanks by advance
    nb: Iuse Zend 2.0

    Hi,
    You need to escape single quote mark:
    decode(substr(c.NUM,1 ,1), \'1\',1, \'2\',1,\'3\',1,-1) cp_type ,
    the same way you did for to_date:
    to_date(:debut, \'dd/mm/yy\')
    Regards,
    Paweł

  • SQL Cost of using DECODE built-in

    I'm trying to tune some SQL and wondering about the cost of using DECODE. I believe that by using this function, it prevents any index on the related column from being used.
    Do any "Tuning Gurus" have opinions on the use of DECODE?
    TIA,

    As a general rule, the Oracle built-in functions are pretty fast to execute. You will not really see any difference in performance between a sql statement using a built-in function in the SELECT clause, and one not using one.
    However, a lot depends on where and how you use the DECODE.
    SELECT col1,DECODE(col2,1,'YES',2,'NO',3,'MAYBE')
    FROM table
    will be no slower than
    SELECT col1,col2
    FROM table
    If there is an index on col2, then
    SELECT col1,DECODE(col2,1,'YES',2,'NO',3,'MAYBE')
    FROM table
    WHERE col2 BETWEEN 1 AND 3
    will use it.  However
    SELECT col1,col2
    FROM table
    WHERE DECODE(col2,1,'YES',2,'NO',3,'MAYBE') IN ('YES','NO','MAYBE')
    will not (unless you have a function based index).  But,
    SELECT col1,col3
    FROM table
    WHERE col2 BETWEEN 1 and 3 and
          col3 = DECODE(col2,1,'YES',2,'NO',3,'MAYBE') IN ('YES','NO','MAYBE')
    will.Note that "will" in the above really means can. it is up to the optimizer whether it actually is used or not.
    HTH
    John

  • Using Decode in where clause in free hand sql

    Hi,
        I want to use decode in free hand sql.
    for eg : this is a where condition
    Outlet_Lookup.City  =  @variable('Enter City')
    Requirement :
    if we put the user prompt as "Enter City and % for all cities"
    and the user enters % then the data display should be all cities or else it shld be the specific city entered in the prmpt..
    Can we do that using Decode statement,
    I have tried
    Outlet_Lookup.City  =  Decode(@variable('Enter City'),'%',Outlet_Lookup.City,(@variable('Enter City')))
    This is not working....
    Pls guide on the same..
    Thanks.

    Hi Mathieu,
            Thanks for the solution,
    I tried the following
    ((Outlet_Lookup.City  =  @variable('Enter City or % for All') or @variable('Enter City or % for All')='%'))
    This is working fine....
    Thanks
    Regards,
    Aparna.

  • PL/SQL URL decode function

    I am looking for a pl/sql url decode function. Does not appear to be in owa_util or htp/htf. Does any one have one please?

    You can use the utl_url package that provides public APIs for both encoding and recoding purposes.

  • How to use decode function in oracle apex 3.2.1

    Hello Friends,
    how to use decode
    var_decode := 'decode'||'('|| var1 ||','|| -800000000000000||','||'.A'||','||
    appreciate your help.
    regards/kumar
    Edited by: kumar73 on Apr 23, 2010 12:25 PM
    Edited by: kumar73 on Apr 23, 2010 12:27 PM

    Hey just on this particular point, there's a handy PL/SQL method for escaping quotation characters which may reduce the complexity of the string.
    For example, if I had a string:
    I can't understand why quoting my 'quote' characters never seems to "work"!and I wanted to pass that into a variable, I could do this:
    vc_foo:= 'I can''t understand why my ''quote'' characters never seems to "work"!';or I could use the q function, whereby you enclose your string within a quote delimiter of your choice, like so:
    vc_foo:= q'^I can't understand why quoting my 'quote' characters never seems to "work"!^';
    note: I used the caret (^) character by convention but any valid character will do
    ...all of which leaves your original string more or less unadulterated.
    I find this particularly useful for generating dynamic SQL and dynamic PL/SQL, as it leave the query looking a tad more readable, although if you are chaining together multiple strings with double-pipes, it can make it a little muddier. I find it particularly useful if I'm going to deal with string data from, for example, a field with Irish-derived surnames such as "O'Reilly"...
    Give it a go!

  • How to use DECODE function in Exspression?

    Hi,
    Can we use DECODE in Expression?
    I'm trying to use DECODE function but there is an error during the validation. But when i validate the mapping, it is successfully compiled but it is failed during deployment.
    But if I use CASE instead of DECODE, it works fine.
    Can we use DECODE in OWB???
    Thanks
    Raj

    Hi,
    In OWB 10gR2, if your are using only one DECODE in an expression, it's working. The package will compile when deploying the mapping. OWB will replace the DECODE by a CASE.
    But when you are using nested decode in an expression ( for example : decode(col1, 1, 'M', decode(col2, 'Madame', 'Mme', null)) ) only the first one is replaced by a case at deployment.
    In ROW_BASED mode, text of the expression is used outside of an sql statement and deployment will fails with "PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only."
    If operating mode for the mapping is set to SET_BASED, it's working because the expression is used in an sql statement.
    I have logged a SR in metalink for this issue and a bug is opened (bug 5414112).
    But I agree with you, it's better to use case statement.
    Bernard

  • How to use decode to calculate sum for different date range

    I'm stuck with decode() function:
    I have a table like this:
    (project_id, approve_date, value, builder_code)
    I want to write a SQL query to get sum of values for different month of the approve_date, and group by builder_code)
    The result is like this:
    builder_code Sum(value)_Sep-03 Sum(value)_Oct-03 Sum(value)_Nov03
    1001 1,299 1,322 990
    1002 3,332 1,222 333
    I tried to use decode for this question but could not get the answer.
    Thanks a lot

    I don't think you need a DECODE() here. I'd do something like this-
    create table builder (
        project_id number,
        approve_date date,
        value        number,
        builder_code number
    insert into builder values( 1, to_date('09-01-2003', 'MM-DD-YYYY'), 100, 990 )
    insert into builder values( 2, to_date('09-03-2003', 'MM-DD-YYYY'), 150, 990 )
    insert into builder values( 3, to_date('09-05-2003', 'MM-DD-YYYY'), 250, 990 )
    insert into builder values( 3, to_date('09-05-2003', 'MM-DD-YYYY'), 250, 333)
    SELECT sept.builder_code, sept.sept_sum, oct.oct_sum
    FROM (SELECT builder_code, sum(value) sept_sum
            FROM builder
           WHERE approve_date >= to_date('09-01-2003','MM-DD-YYYY')
             AND approve_date < to_date('10-01-2003','MM-DD-YYYY')
           GROUP BY builder_code) sept,
         (SELECT builder_code, sum(value) oct_sum
            FROM builder
           WHERE approve_date >= to_date('10-01-2003','MM-DD-YYYY')
             AND approve_date < to_date('11-01-2003','MM-DD-YYYY')
           GROUP BY builder_code) oct
    WHERE oct.builder_code(+) = sept.builder_code
    BUILDER_CODE   SEPT_SUM    OCT_SUM
             333        250
             990        500Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • OWB Error for using Decode in Expression

    Debug code deployment messages:
    LINE 4558 ,COLUMN 71:
    PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only
    LINE 4558 ,COLUMN 17:
    PL/SQL: Statement ignored
    End debug code deployment messages
    DBG1012: Debug deployment errors, can't run debug code.

    What i have experience is that if you use Decode inside the expression the OWB cannot validate it .
    But it will execute perfect.
    Use Case statement so that you can validate it and debug then
    Cheers
    Nawneet

  • Using Decode in Collections

    when i using decode in queries written for collection i.e
    wwv_flow_item.select_list_from_query_xl(13,'','select decode(id,123,''XYZ'',name) from mytable ','','NO') Field1,
    I get the error
    report error:
    ORA-06550: line 1, column 120:
    PL/SQL: ORA-00913: too many values
    ORA-06550: line 1, column 7:
    PL/SQL: SQL Statement ignored
    in the front end ?
    Please let me know whether we can use decode in queries wrriten in collections if so how
    Thanks in Advance

    when i using decode in queries written for collection i.e
    wwv_flow_item.select_list_from_query_xl(13,'','select decode(id,123,''XYZ'',name) from mytable ','','NO') Field1,
    I get the error
    report error:
    ORA-06550: line 1, column 120:
    PL/SQL: ORA-00913: too many values
    ORA-06550: line 1, column 7:
    PL/SQL: SQL Statement ignored
    in the front end ?
    Please let me know whether we can use decode in queries wrriten in collections if so how
    Thanks in Advance

  • How to use decode concept in htp.p?

    Hi All,
    How to use decode function in htp.p syntax?
    Thanks,
    Anoo..

    Hi,
    Could you please give more details on what you like to achieve? Decode function works only in sql query.
    You can first do sql query, and then do htp.p.
    Or you can use PL/SQL IF or CASE statements.
    You can also create custom decode function if you need.
    Regards,
    Oleg

  • How to use Decode with a variable

    Maybe you've seen this done.
    I want to take statement strMenu4 and subtract the previous value
    that is stored in an array as shown in strMenu5.
    My problem is this change as shown in strMenu5 produces
    an error code:
    ORA-00904 invalid column name
    So either I'm coding something wrong or it can't be done within the
    SUM(decode) construct. If I replace the variable with a literal
    like 1000 the code works:
    SUM(decode(name,'DBWR lru scans', c1.value) - 1000) DBWR_lru_scans
    but with an array variable or even a constant the code fails:
    SUM(decode(name,'DBWR lru scans', c1.value) - Array(3)) DBWR_lru_scans, "
    Any ideas how I can use Decode with a variable and not have it interrupt it
    as a invalid column name?
    Thanks,
    Joseph Karpinski
    [email protected]
    [email protected]
    strMenu4 = "SELECT d1.instance, " _
    & " to_char(sysdate, 'dd-mon-yy hh24:mi:ss') start_time, " _
    & " SUM(decode(name,'DBWR buffers scanned', c1.value)) DBWR_buffers_scanned, " _
    & " SUM(decode(name,'DBWR lru scans', c1.value)) DBWR_lru_scans, " _
    & " SUM(decode(name,'db block gets', c1.value)) db_block_gets , " _
    & " SUM(decode(name,'consistent gets', c1.value)) consistent_gets , " _
    & " SUM(decode(name,'physical reads', c1.value)) physical_reads " _
    & " from dual, v$sysstat c1, v$thread d1 " _
    & " group by d1.instance "
    strMenu5 = "SELECT d1.instance, " _
    & " to_char(sysdate, 'dd-mon-yy hh24:mi:ss') start_time, " _
    & " SUM(decode(name,'DBWR buffers scanned', c1.value) - Array(2)) DBWR_buffers_scanned, " _
    & " SUM(decode(name,'DBWR lru scans', c1.value) - Array(3)) DBWR_lru_scans, " _
    & " SUM(decode(name,'db block gets', c1.value) - Array(4)) db_block_gets , " _
    & " SUM(decode(name,'consistent gets', c1.value) - Array(5)) consistent_gets , " _
    & " SUM(decode(name,'physical reads', c1.value) - Array(6)) physical_reads " _
    & " from dual, v$sysstat c1, v$thread d1 " _
    & " group by d1.instance "

    Re-posting in the SQL and PL/SQL forum.
    It's more appropriate.
    Thanks,
    Closing

  • Can I use decode( decode...)...)

    Hi,
    Can I use decode function inside decode function.
    It seem doesn't work. Please help
    decode(lv.RANK||' / '||
    decode('('||lv.ONE_YR_PCT||'%)', '(%)','N/A','('||lv.ONE_YR_PCT||'%)'),
    '0 / (0%)','N/A', lv.RANK )
    Thanks

    I'm not quite sure it's the result you intended but your nested decode statement does run ...
    SQL> CREATE TABLE lv (rank number, one_yr_pct number)
      2  /
    Table created.
    SQL> insert into lv values (1, 1)
      2  /
    1 row created.
    SQL> insert into lv values (2,2)
      2  /
    1 row created.
    SQL> insert into lv values (0,0)
      2  /
    1 row created.
    SQL> select decode(lv.RANK||' / '||
      2  decode('('||lv.ONE_YR_PCT||'%)', '(%)','N/A','('||lv.ONE_YR_PCT||'%)'),
      3  '0 / (0%)','N/A', lv.RANK )
      4  from lv
      5  /
    DECODE(LV.RANK||'/'||DECODE('('||LV.ONE_
    1
    2
    N/A
    SQL> If you're having problems maybe you should cut'n'paste the output from your SQL*Plus session so we can see what's happening.
    Alternatively, as CD suggests, you may find it easier to express your logic using CASE.
    Cheers, APC

  • Basic query using DECODE not working as expected.

    Version:11.2.0.3
    Platform: RHEL 5.8
    I am trying to use DECODE function.
    In the below example, If the search encounters the string "Enterprise" , then the decode should
    return 'Enterprise' . But it doesn't seem to work.
    I thought some hidden character was causing the issue, so, I used TRIM. But no luck.
    SQL> create table t (banner varchar2(80));
    Table created.
    SQL> insert into t values ('Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from t;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    SQL> select * from t where banner like '%Database%';
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    -- Trying to use decode. If the search encounters the string "Enterprise" , then return 'Enterprise'
    -- Although the string "Enterprise" is present ,  decode doesn't seem to work.
    -- I tried using trim , upper . But no luck.
    SQL> select 'EDITION', decode(banner,'%Enterprise%','Enterprise','Standard') Edition from t where banner like '%Database%';
    'EDITIO EDITION
    EDITION Standard
    SQL> select 'EDITION', decode(trim(banner), '%Enterprise%','Enterprise','Standard') Edition from t where trim(banner) like '%Database%';
    'EDITIO EDITION
    EDITION Standard
    SQL> select 'EDITION', decode(upper(trim(banner)), '%ENTERPRISE%','Enterprise','Standard') Edition from t where upper(trim(banner)) like '%DATABASE%';
    'EDITIO EDITION
    EDITION Standard
    SQL>
    Just don't understand why decode can't see the string "Enterprise"
    BTW . Where is the preview button ?

    It (a portion string matching) ain't work in DECODE, for this CASE has a advantage of using over it.
    Like
    with t
    as
    (select 'Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production' banner from dual)
    select 'EDITION',
    case when banner like '%Enterprise%' then 'Enterprise' else 'Standard' end edition
    from t
    'EDITIO EDITION
    EDITION Enterprise

Maybe you are looking for