Decode in query

I have tried to use this query in an application and it never runs the 'Yes' part. I ran it in sqldeveloper and I get the same result regardless of what I put in the variable. I can't see the error in it. Help?
select * from SF_CASE where CASE_NUMBER not in decode(:P57_Used_Cases, 'Yes',
'(Select Case_Number from FAQ_CASE_JUNC)',
'(Select Case_Number from FAQ_CASE_JUNC where Case_Number = ''1'')' )
Andrea

Decode statement doest not take sql queries as
parameter. Actually, it takes.
When it is a scalar subquery:
SQL> with t as (select level from dual connect by level<=4)
  2  --
  3  select * from dual where 1 not in decode('Yes','Yes',(select * from t where rownum=1),2)
  4  /
DUMMY
SQL>
SQL> with t as (select level from dual connect by level<=4)
  2  --
  3  select * from dual where 1 not in decode('Yes','No',(select * from t where rownum=1),2)
  4  /
DUMMY
X
SQL>
SQL> with t as (select level from dual connect by level<=4)
  2  --
  3  select * from dual where 1 not in decode('Yes','No',(select * from t),2)
  4  /
DUMMY
X
SQL>
SQL> with t as (select level from dual connect by level<=4)
  2  --
  3  select * from dual where 1 not in decode('Yes','Yes',(select * from t),2)
  4  /
with t as (select level from dual connect by level<=4)
select * from dual where 1 not in decode('Yes','Yes',(select * from t),2)
ORA-01427: single-row subquery returns more than one row

Similar Messages

  • Decode affecting query performance

    Hi. We have a system that holds two account numbers, in 8 digit and 12 digit formats. I have a screen with an input box where the user can enter either style account number.
    So the select I need to do, must be conditional based on the type used. I've got it working by checking the length of the account number entered:
    select column1 from table1
    where decode(length(:P1_ACCNUM),12,accountno,accno_8digit) = upper(v('P1_ACCNUM'))
    but the performance has gone from instant, to about 3 seconds. In TOAD, the query is unaffected, so maybe it's the subsitution of the variable. I've tried the way coded above, and v('P1_ACCNUM') but there is no difference in Apex.
    Does anyone have any ideas on this?
    Cheers
    Carlton
    (NR - Business as Usual.)

    Hi George. Initially, the code only supported the 12 digit account number,but you know what users are like! So the original query was coded to say
    accountno = :p1_accnum
    The decode was necessary because I had to do the comparison on another column. Both columns are indexed.
    As I say, putting the length() function (and I also do an UPPER conversion too) in hidden fields and using them has made it perform perfectly again. If I had more time, I wouldn't have coded it like this, but it's an urgent throw away application to perform quick account queries.
    Thanks for your response.
    Carlton

  • Problems with decoding an latin1-encoded url

    Hi,
    i have a problem with decoding german umlaut-characters from an URL.
    I'm using Tomcat 5.5 on a Linux server and one on a windows machine for development. Both webapps have the same configurations.
    A servlet decodes the URL-String, parses it and stores the parsed data into a mysql-DB.
    For decoding the query-string i'm using org.apache.commons.codec.net.URLCodec.URLCodec.decode .
    Here's the code:
    String unparsedParameters = request.getQueryString();
    URLCodec codec = new URLCodec("ISO-8859-1");
    result = codec.decode(unparsedParameters);Here an example for a query-string: http://servername:8080/servlet/Import?Etwas%20wurde%20am%2025.08.2010%2010%3A16%3A50%20*ge%E4ndert*
    On the windows machine the word "*ge&auml;ndert*" is decoded correctly. But on the linux server i get "*ge?ndert*". It makes no difference if i write the result into the database or just into a logfile.
    Can anyone help?
    Thanks in advance.
    Edited by: sol1640 on Aug 26, 2010 5:59 AM

    Problem resolved.
    Instead of using the decode-method as described in my fist message now i'm doing the folowing:
    fURLDecodigCharset = "ISO8859-1";
    byte[] bytes = originalParam.getBytes(fURLDecodigCharset);
    byte[] decodeUrl = URLCodec.decodeUrl(bytes);
    result = new String (decodeUrl, fURLDecodigCharset);because the method "decode" decodes the string by using the defaultcharset. And that was the problem.
    >
    The default charset is determined during virtual-machine startup and typically depends upon the locale and charset of the underlying operating system.
    >
    Thats why i've got different behaviours on different systems.
    Thanks

  • Help speed up a long running query.

    I have a connect by query that is taking a long time to run.
    The problem seems to lie in it contains a decode on the CONNECT BY
    CONNECT BY prior p_mat = DECODE(NVL(p_sa,'M'),'S',p_top,NULL)If i remove this or make it default to p_top rather than checking the value of p_sa its fine.
    Any idea how I can achieve the same result of the connect by without the need for the decode?

    query
        SELECT mp_irn,
          level - 1 ,
          1,
          mp_irn
        FROM sfmp,
          sfmat
        WHERE MAT_REF_NUM             = MP_REF_MAT
        AND mp_sl                     =db_pkg_pcs.fun_getbomroute(mp_irn)
          CONNECT BY prior mp_ref_mat = DECODE(NVL(mat_sa,'M'),'S',mp_irn,NULL)
          START WITH mp_irn           = 'K9081-400'
      UNION
      SELECT mp_ref_mat,
        level,
        MP_REF_FREQ,
        mp_irn
      FROM sfmp,
        sfmat
      WHERE NVL(MAT_SA,'M')         = 'S'
      AND MAT_REF_NUM               = MP_REF_MAT
      AND mp_sl                     =db_pkg_pcs.fun_getbomroute(mp_irn)
        CONNECT BY prior mp_ref_mat = mp_irn
        START WITH mp_irn           = 'K9081-400'
      ORDER BY 2
    | Id  | Operation                         | Name          | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                  |               |   822 | 37884 |       |   568   (2)| 00:00:07 |
    |   1 |  SORT UNIQUE                      |               |   822 | 37884 |       |   567   (7)| 00:00:07 |
    |   2 |   UNION-ALL                       |               |       |       |       |            |          |
    |*  3 |    FILTER                         |               |       |       |       |            |          |
    |*  4 |     CONNECT BY WITH FILTERING     |               |       |       |       |            |          |
    |   5 |      NESTED LOOPS                 |               |    24 |  1104 |       |    27   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |*  6 |       INDEX RANGE SCAN            | PK_MP         |    24 |   696 |       |     3   (0)| 00:00:01 |
    |   7 |       TABLE ACCESS BY INDEX ROWID | SFMAT         |     1 |    17 |       |     1   (0)| 00:00:01 |
    |*  8 |        INDEX UNIQUE SCAN          | PK_SFMAT      |     1 |       |       |     0   (0)| 00:00:01 |
    |   9 |      NESTED LOOPS                 |               |       |       |       |            |          |
    |  10 |       CONNECT BY PUMP             |               |       |       |       |            |          |
    |* 11 |       HASH JOIN                   |               |   798 | 36708 |  1080K|   537   (1)| 00:00:07 |
    |  12 |        TABLE ACCESS FULL          | SFMAT         | 38018 |   631K|       |   224   (1)| 00:00:03 |
    |  13 |        INDEX FAST FULL SCAN       | PK_MP         | 79831 |  2260K|       |   103   (1)| 00:00:02 |
    |* 14 |    FILTER                         |               |       |       |       |            |          |
    |* 15 |     CONNECT BY WITH FILTERING     |               |       |       |       |            |          |
    |  16 |      NESTED LOOPS                 |               |    24 |  1176 |       |    28   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |  17 |       TABLE ACCESS BY INDEX ROWID | SFMP          |    24 |   768 |       |     4   (0)| 00:00:01 |
    |* 18 |        INDEX RANGE SCAN           | SFMP_SFJR_IDX |    24 |       |       |     1   (0)| 00:00:01 |
    |  19 |       TABLE ACCESS BY INDEX ROWID | SFMAT         |     1 |    17 |       |     1   (0)| 00:00:01 |
    |* 20 |        INDEX UNIQUE SCAN          | PK_SFMAT      |     1 |       |       |     0   (0)| 00:00:01 |
    |  21 |      NESTED LOOPS                 |               |    24 |  1176 |       |    28   (0)| 00:00:01 |
    |  22 |       NESTED LOOPS                |               |       |       |       |            |          |
    |  23 |        CONNECT BY PUMP            |               |       |       |       |            |          |
    |  24 |        TABLE ACCESS BY INDEX ROWID| SFMP          |    24 |   768 |       |     4   (0)| 00:00:01 |
    |* 25 |         INDEX RANGE SCAN          | SFMP_SFJR_IDX |    24 |       |       |     1   (0)| 00:00:01 |
    |  26 |       TABLE ACCESS BY INDEX ROWID | SFMAT         |     1 |    17 |       |     1   (0)| 00:00:01 |
    |* 27 |        INDEX UNIQUE SCAN          | PK_SFMAT      |     1 |       |       |     0   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       3 - filter("MP_SL"="DB_PKG_PCS"."FUN_GETBOMROUTE"("MP_IRN"))
       4 - access(DECODE(NVL("MAT_SA",'M'),'S',"MP_IRN",NULL)=PRIOR "MP_REF_MAT")
       6 - access("MP_IRN"='K9081-400')
       8 - access("MP_REF_MAT"="MAT_REF_NUM")
      11 - access("MP_REF_MAT"="MAT_REF_NUM")
           filter(DECODE(NVL("MAT_SA",'M'),'S',"MP_IRN",NULL)=PRIOR "MP_REF_MAT")
    PLAN_TABLE_OUTPUT
      14 - filter(NVL("MAT_SA",'M')='S' AND "MP_SL"="DB_PKG_PCS"."FUN_GETBOMROUTE"("MP_IRN"))
      15 - access("MP_IRN"=PRIOR "MP_REF_MAT")
      18 - access("MP_IRN"='K9081-400')
      20 - access("MAT_REF_NUM"="MP_REF_MAT")
      25 - access("MP_IRN"=PRIOR "MP_REF_MAT")
      27 - access("MAT_REF_NUM"="MP_REF_MAT")

  • Deciphering a SAML Message in ColdFusion

    I'm working on an SSO solution for a client.  At this time I'm able to encode an authentication message and successfully send it to the ADFS server.  The ADFS server handles my login and then returns to my site with an HTTP-POST response.  In the POST there is an ADFS encoded SAML message I need to decipher.  I found a few samples of code but none have worked.  This one seemed to have the most promise but...
    <cfscript>
    // Decode the query string from Base 64 
      Decoder = CreateObject("Java", "sun.misc.BASE64Decoder").init();
      SamlByte = Decoder.decodeBuffer(Form.SAMLResponse);
    // Create Byte Array used for the inflation, the CF way 
      ByteClass = CreateObject("Java", "java.lang.Byte").TYPE;
      ByteArray = CreateObject("Java", "java.lang.reflect.Array").NewInstance(ByteClass, 1024);
    // Create Byte Streams needed for inflation
      ByteIn   = CreateObject("Java", "java.io.ByteArrayInputStream").init(SamlByte);
      ByteOut  = CreateObject("Java", "java.io.ByteArrayOutputStream").init();
    // Create Objects needed for inflation 
      Inflater = CreateObject("Java", "java.util.zip.Inflater").init(true);
      InflaterStream = CreateObject("Java", "java.util.zip.InflaterInputStream").init(ByteIn, Inflater);
    // Complete the inflation 
      Count = InflaterStream.read(ByteArray);
      while (Count != -1) {
      ByteOut.write(ByteArray, 0, Count);
      Count = InflaterStream.read(ByteArray);
    // Finished with inflation 
      Inflater.end();
      InflaterStream.close();
    // Convert SAML request back to a string 
      SamlString = CreateObject("Java", "java.lang.String").init(ByteOut.toByteArray());
      </cfscript>
    When the code get to the Count = InflaterStream.read(ByteArray); statement the following error message is returned: oversubscribed dynamic bit lengths tree
    My question is does anybody have a snippet of code that is used to successfully decipher an ADFS encoded SAML response?

    Whatever version came with MX7. When I run it and go to help
    and about, it just shows the version info for cold fusion server.
    Not the report builder. I know it is the latest version however as
    I also downloaded and installed the latest version from
    online.

  • Problem using DECODE() function with a Query of Queries

    I
    posted
    on my blog about an issue I was having trying to use the PL/SQL
    DECODE() function with a Coldfusion Query of Queries. This function
    works fine when you query a database for information. However, when
    you query another query, it seems that CF doesn't recognize it. I
    got errors stating that it found a left parenthesis where it
    expected a FROM key word. Here is a simplified version of what I am
    trying to do:
    quote:
    <!--- Simulated query; similar to what I was calling from
    my database --->
    <cfscript>
    qOriginal = queryNew("Name,Email,CountryCode",
    "VarChar,VarChar,VarChar");
    newRow = queryAddRow(qOriginal, 5);
    querySetCell(qOriginal, "Name", "Joe", 1);
    querySetCell(qOriginal, "Email", "[email protected]", 1);
    querySetCell(qOriginal, "CountryCode", "AMER", 1);
    querySetCell(qOriginal, "Name", "Sally", 2);
    querySetCell(qOriginal, "Email", "[email protected]", 2);
    querySetCell(qOriginal, "CountryCode", "AMER", 2);
    querySetCell(qOriginal, "Name", "Bob", 3);
    querySetCell(qOriginal, "Email", "[email protected]", 3);
    querySetCell(qOriginal, "CountryCode", "ASIA", 3);
    querySetCell(qOriginal, "Name", "Mary", 4);
    querySetCell(qOriginal, "Email", "[email protected]", 4);
    querySetCell(qOriginal, "CountryCode", "EURO", 4);
    querySetCell(qOriginal, "Name", "John", 5);
    querySetCell(qOriginal, "Email", "[email protected]", 5);
    querySetCell(qOriginal, "CountryCode", "EURO", 5);
    </cfscript>
    <cfquery name="qCountries" dbtype="query">
    SELECT DISTINCT(CountryCode) AS CountryCode,
    DECODE(states, "AMER", "North America &amp; Canada",
    "EURO", "Europe &amp; Africa", "ASIA", "Japan &amp;
    Asia","") CountryName
    FROM qOriginal
    ORDER BY CountryCode
    </cfquery>
    <cfdump var="#qCountries#">
    <!--- ========== END OF CODE ========== --->
    So running this returned the following error:
    Query Of Queries syntax error.
    Encountered "(. Incorrect Select Statement, Expecting a
    'FROM', but encountered '(' instead, A select statement should have
    a 'FROM' construct.
    Does anybody know why this doesn't work? Is it just not
    supported? Please note that I have also tried to use the CASE()
    function instead of DECODE() and that resulted in basically the
    same error. For now I an looping over my distinct query with a
    switch statement and manually loading a new query with the data how
    I want it. But it would be a lot cleaner and less code to have the
    DECODE() to work. Thx!

    DECODE() is an Oracle function, not generic SQL. Q-of-Q is a
    very limited subset of SQL and lacks many functions and clauses
    available in standard SQL, especially what you may be used to using
    in your particular RDBMS.
    See
    Query
    of Queries user guide
    Phil

  • Comma delimited in Sql query decode function errors out

    Hi All,
    DB: 11.2.0.3.0
    I am using the below query to generate the comma delimited output in a spool file but it errors out with the message below:
    SQL> set lines 100 pages 50
    SQL> col "USER_CONCURRENT_QUEUE_NAME" format a40;
    SQL> set head off
    SQL> spool /home/xyz/cmrequests.csv
    SQL> SELECT
    2 a.USER_CONCURRENT_QUEUE_NAME || ','
    3 || a.MAX_PROCESSES || ','
    4 || sum(decode(b.PHASE_CODE,'P',decode(b.STATUS_CODE,'Q',1,0),0)) Pending_Standby ||','
    5 ||sum(decode(b.PHASE_CODE,'P',decode(b.STATUS_CODE,'I',1,0),0)) Pending_Normal ||','
    6 ||sum(decode(b.PHASE_CODE,'R',decode(b.STATUS_CODE,'R',1,0),0)) Running_Normal
    7 from FND_CONCURRENT_QUEUES_VL a, FND_CONCURRENT_WORKER_REQUESTS b
    where a.concurrent_queue_id = b.concurrent_queue_id AND b.Requested_Start_Date <= SYSDATE
    8 9 GROUP BY a.USER_CONCURRENT_QUEUE_NAME,a.MAX_PROCESSES;
    || sum(decode(b.PHASE_CODE,'P',decode(b.STATUS_CODE,'Q',1,0),0)) Pending_Standby ||','
    ERROR at line 4:
    ORA-00923: FROM keyword not found where expected
    SQL> spool off;
    SQL>
    Expected output in the spool /home/xyz/cmrequests.csv
    Standard Manager,10,0,1,0
    Thanks for your time!
    Regards,

    Get to work immediately on marking your previous questions ANSWERED if they have been!
    >
    I am using the below query to generate the comma delimited output in a spool file but it errors out with the message below:
    SQL> set lines 100 pages 50
    SQL> col "USER_CONCURRENT_QUEUE_NAME" format a40;
    SQL> set head off
    SQL> spool /home/xyz/cmrequests.csv
    SQL> SELECT
    2 a.USER_CONCURRENT_QUEUE_NAME || ','
    3 || a.MAX_PROCESSES || ','
    4 || sum(decode(b.PHASE_CODE,'P',decode(b.STATUS_CODE,'Q',1,0),0)) Pending_Standby ||','
    5 ||sum(decode(b.PHASE_CODE,'P',decode(b.STATUS_CODE,'I',1,0),0)) Pending_Normal ||','
    6 ||sum(decode(b.PHASE_CODE,'R',decode(b.STATUS_CODE,'R',1,0),0)) Running_Normal
    7 from FND_CONCURRENT_QUEUES_VL a, FND_CONCURRENT_WORKER_REQUESTS b
    where a.concurrent_queue_id = b.concurrent_queue_id AND b.Requested_Start_Date <= SYSDATE
    8 9 GROUP BY a.USER_CONCURRENT_QUEUE_NAME,a.MAX_PROCESSES;
    || sum(decode(b.PHASE_CODE,'P',decode(b.STATUS_CODE,'Q',1,0),0)) Pending_Standby ||','
    >
    Well if you want to spool query results to a file the first thing you need to do is write a query that actually works.
    Why do you think a query like this is valid?
    SELECT 'this, is, my, giant, string, of, columns, with, commas, in, between, each, word'
    GROUP BY this, is, my, giant, stringYou only have one column in the result set but you are trying to group by three columns and none of them are even in the result set.
    What's up with that?
    You can only group by columns that are actually IN the result set.

  • SQL query, Decode function or Case

    Hi,
    I am writing a procedure, receiving IN parameter p_user_type_cd
    where p_user_type possibles values are = 'STUDENT','STAFF','PROVIDER'
    if p_user_type_cd = 'STUDENT' , I would like to select WHERE user_type_cd = 'STUDENT'
    if p_user_type_cd = 'ALL' , then I would like to select all records. i.e I like to select 'STUDENT','STAFF','PROVIDER'.
    SELECT user_type_cd, page_name_cd, access_mode, home_page
    FROM oua_user_page_access
    WHERE user_type_cd = p_user_type_cd
    ORDER BY user_type_cd,home_page;
    Will you pl. modify this query to meet the condition.
    Thanks,
    Murali

    Hi murali,
    I got your situation and its easy to write a decode for the following
    WHERE user_type_cd = p_user_type_cdWHERE user_type_cd = decode(:p_user_type_cd, 'STUDENT','STUDENT','STAFF','STAFF','PROVIDER','PROVIDER',
    p_user_type_cd)
    Here you write the above and you will get the data.
    Hope this helps you,
    Best Wishes,
    Kranthi.

  • Help on converting query with case into decode

    Hi Can anyone help me to revise my plsql query? Below is a portion og the procedure I am changing to meet Oracle 8i.
    SELECT SUM(NVL(CASE WHEN (weeks='wk1' ) THEN qty END, 0)) wk1,
    SUM(NVL(CASE WHEN (weeks='wk2' ) THEN qty END, 0)) wk2,
    SUM(NVL(CASE WHEN (weeks='wk3' ) THEN qty END, 0)) wk3,
    SUM(NVL(CASE WHEN (weeks='wk4' ) THEN qty END, 0)) wk4
    FROM TABLE1
    Thanks in advance.

    pls try this....(code not tested as no create table etc provided).
    select dt
    from (select decode(is_tbd,
    'yes',
    decode(is_tbd_order,
    'no',
    'tbd',
    decode(sign(ex_fac_date - (v_asofdate + 131)),
    1,
    'tbd',
    null),
    decode(sign(ex_fac_date - (v_asofdate + 131)),
    1,
    'tbd',
    null)),
    null) dt
    from dual
    union all
    select decode(sign(ex_fac_date - (v_asofdate - 1)),
    1,
    decode(sign(ex_fac_date - (v_asofdate + 5)),
    0,
    decode(is_tbd, 'no', 'wk1', null),
    null),
    null)
    from dual
    union all
    select decode(sign(ex_fac_date - (v_asofdate + 6)),
    1,
    decode(sign(ex_fac_date - (v_asofdate + 12)),
    0,
    decode(is_tbd, 'no', 'wk2', null),
    null),
    null)
    from dual
    select decode(sign(ex_fac_date - (v_asofdate + 13)),
    1,
    decode(sign(ex_fac_date - (v_asofdate + 19)),
    0,
    decode(is_tbd, 'no', 'wk3', null),
    null),
    null)
    from dual
    union all
    select decode(sign(ex_fac_date - (v_asofdate - 1)),
    0,
    decode(is_tbd, 'no', 'past_due', null),
    null)
    from dual
    where dt is not null
    Regards

  • Decode statement in Select line of a View Object Query

    I attempted to create a view object in expert mode with a customized query.
    The query had a decode statement in the select line of the query. The view
    object compiled correctly but gave an error when run.
    ex: select .... decode(CrpSchools.SCHOOLS_ID,null,CrpCustSchools.SCHOOL_NAME,CrpSchools.SCHOOL_NAME) SCHOOL_VALUE, ...
    from ....
    where ....
    The error was that school_value does not exist in the statement. I got the error when
    doing a vo.executeQuery().
    When I removed the decode statement everything worked correctly. Does anyone know if
    the decode statement cannont be used in the select line of a query in a view object?
    Or maybe I was linking the query column (SCHOOLS_ID) up to the view attribute (SCHOOL_VALUE) incorrectly in the
    Attribute Mappings tab of the VO wizard?

    There should be no problem using a DECODE() statement, provided that you've aliases the column as you have done.
    At design time, if you click on the (Test) button, does your query test ok?
    Are you by chance applying a custom where clause at runtime?
    If so, are you saying:
    setWhereClause("yourtable.column_alias = ?";
    or are you doing:
    setWhereClause("column_alias = ?";
    for an expert-mode query, you'll need to use the latter syntax.

  • Understanding the DECODE statement in an SQL Query......

    Hi,
    This is my query:
    SELECT
    DECODE(IT.master_flag,0,'-',ea_submission_date),
    DECODE(IT.master_flag,0,'-',ea_approval_date),
    DECODE(IT.master_flag,0,'-',ea_date),
    DECODE(IT.master_flag,0,'-',ea_comments)
    FROM
    amendment it,
    {CODE}
    The master_flag on the AMENDMENT table can be 1,0 or NULL.
    I want the above query to output a '-' character in the result set in the 4 columns being selected if the master_flag is either 0 or null.
    If it is one 1 however, then display the value of the column. E.G display the data in 'ea_submission_date', 'ea_approval_date', 'ea_date,  and 'ea_comments' (if there are values in these columns of course.
    Am I right in using the above query?
    Thanks!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Sastry wrote:
    Am I right in using the above query?You're almost there. Just add the logic for the NULL value.
    example
    SELECT
    DECODE(IT.master_flag,0,'-',null, '-', ea_submission_date) ea_submission_date,
    DECODE(IT.master_flag,0,'-',null, '-', ea_approval_date) ea_approval_date,
    DECODE(IT.master_flag,0,'-',null, '-', ea_date) ea_date,
    DECODE(IT.master_flag,0,'-',null, '-', ea_comments) ea_comments
    FROM
    amendment it, ...btw, your closing code tag needs to be in lower case too. Please edit your original post and correct that.

  • Sql query usig round and decode together

    can i get one sql quer for returning whole number using round and decode function
    eg:
    the value 47
    if value=47
    then
    the query should return 50
    if the value =44
    then
    the quer should return 40
    pls give me sql query for above example using round and decode function
    Edited by: user11368167 on Jul 9, 2009 3:35 AM

    A wild guess. If you want the ROUND Function to work only when your column value is 44 or 47 then you could use something like:
    SQL> WITH test_tab AS
      2       (SELECT 44 col_1
      3          FROM DUAL
      4        UNION ALL
      5        SELECT 15 col_1
      6          FROM DUAL
      7        UNION ALL
      8        SELECT 47 col_1
      9          FROM DUAL
    10        UNION ALL
    11        SELECT 45 col_1
    12          FROM DUAL)
    13          -- end of test data
    14  SELECT col_1,
    15         DECODE (col_1,
    16                 44, ROUND (col_1, -1),
    17                 47, ROUND (col_1, -1),
    18                 col_1
    19                ) rounded_value
    20    FROM test_tab
    21  /
         COL_1 ROUNDED_VALUE
            44            40
            15            15
            47            50
            45            45
    4 rows selected.
    SQL> CASE Statement can be used as well instead of DECODE.
    Good Luck,
    Regards,
    Jo

  • Query of Queries decode

    I have a main query that does a decode on a field so that it
    sorts starting with KG then 01,02,03,04,05
    When I then pull the QofQ it spits back the results as
    01,02,03,04,05,KG. Is there a way around that?

    > order by grade
    The QoQ is ordering the values correctly. If you don't want
    the records sorted by grade, you'll need to add a column to your
    main query containing the desired sort order. Then use that column
    in your QoQ
    select grade
    from assessmentData
    order by SortOrderColumn

  • Decode a blob field with a C script in a select query

    HI
    I have a coded field in a table which has been populated using 3rd party software. I need to decode this field so that i could rub a few reports. I have a C script that can decode this field but do not know how to call it up from a select statement.
    Is there any way of decoding this by calling up the C script in a select query.
    Thanks.

    can you duplicate this code into a PL/SQL function?
    Or else, you might try configuring your external procedures setup and call this routine (if it was available as a shared library or a DLL).

  • Sql query in decode

    Hi,
    I want to run query using decode given below:
    decode(
    (select count....from t1),0,(select count...from t2),1)
    MEans, if count of query from table t1 returns 0 then execute query of t2 table else return 1. If then else of query.. can i do this in decode ? if yes, how?
    thanks,
    JP

    CASE is relevant here:
    SQL> select case when (select name from nc_objects where rownum = 1) = 'CSM-AB-155FSH-2W' then 0
      2  else 1 end col1 from dual;
          COL1
             0Rgds.

Maybe you are looking for

  • I want to change the name and password of the administrator on my macbook pro

    I want to pass on my Macbook pro to the next generation so I want some help please to change the name and the password of the administrator.

  • Assignment profit center on customer

    Hello, I want to know if it's possible to assign a profit center on customer and, when I create a post in customer order, this profit center is automatically entered in field "profit center" on tab "Account assignment" of the post data. I would there

  • Request for phone lock code - Nokia E7

    I got updation for my E7 to symbian anna. when i am trying to activate phone lock, it asking password and i tried 12345. But the phone shows incorrect password. It is the first time i am trying to enable this option. pls share other lock codes.

  • NetWeaver 2004

    I'v installeld SAP Netwaver 2004 TRIAL on LINUX SLES 10 SP1 sometimes ago. Now, after downloading and installing GUI for JAVA  7.10r8 I'v tryed to run NetWeaver on the LINUX-box and GUI's on Windows-XP and  Linux too, but no luck. The startup-log for

  • Can't open photoshop CS6 (mac)

    I get an error message "could not open scratch file"  I've tried command alt shift during opening. Can someone help me please.