Query regarding oracle functions

Hi all

I tried to work with decode them and output of NVL to get the following:

Output value
1 NULL
0 1
1 1
2 2
3 3


to do this, I wrote the following query:
SELECT DECODE (NVL(high_value,1), 0.1, NVL(high_value,1)) in tab1.

Can there be a replacement of this using other functions?

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
AMT for Solaris: release 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

Thank you
Nikhil

Can be with decoding

with t_data as
(
select null as val from dual union all
select 0 from dual union all
select 1 from dual union all
select 2 from dual union all
select 3 from dual
)
SELECT
     val,decode(val,null,1,0,1, val) output
from t_data

Tags: Database

Similar Questions

  • query not given function function index in oracle 11g

    I have a query that uses function based indexes when run in oracle 9i, but when I run the same query
    without any change, it does not consider the index. This is the query:

    SELECT distinct patient_role.domain_key, patient_role.patient_role_key,
    patient_role.emergency_contact_name,
    patient_role.emergency_contact_phone, patient_role.emergency_contact_note,
    patient_role.emergency_contact_relation_id,
    patient_role.financial_class_desc_id, no_known_allergies, patient_role. CREATED_BY,
    patient_role. CREATED_TIMESTAMP,
    patient_role. CREATED_TIMESTAMP_TZ, patient_role. UPDATED_BY, patient_role. UPDATED_TIMESTAMP,
    patient_role. UPDATED_TIMESTAMP_TZ,
    patient_role.discontinued_date
    MEETING, patient_role
    WHERE patient_role.patient_role_key = encounter.patient_role_key
    AND SUPERIOR (TRIM (main: encounter.account_number SYS_B_0)) = UPPER (TRIM (main: SYS_B_1 of))
    ((: SYS_B_2))
    AND patient_role.discontinued_date IS null
    AND encounter.discontinued_date IS null;

    Definition of the index:

    CREATE INDEX "user1". "' IX_TRIM_ACCOUNT_NUMBER ' ON 'user1 '. MEETING"(AT THE TOP (TRIM (LEADING))
    ('0' TO 'ACCOUNT_NUMBER')), 'PATIENT_ROLE_KEY', 'DOMAIN_KEY', 'DISCONTINUED_DATE')
    PCTFREE, INITRANS 10 2 MAXTRANS 255 COMPUTE STATISTICS
    STORAGE (INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645)
    PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
    DEFAULT USER_TABLES)
    TABLESPACE "user1".

    Database: Oracle 11g (11.2.0.3)
    O / s: 64-bit Linux (the query does not consider the index even on the windows operating system)

    Any suggestions?

    -Onkar

    Published by: onkar.nath on July 2, 2012 15:32

    Onkar,

    I don't appreciate posting you this issue in several forums at the same time.
    If I know you also posted this on Asktom, I wouldn't even bother.
    As for your "problem":
    First of all: some kind cursor_sharing MUST have been implemented. Oracle is a predictable system, not a fruitmachine.
    Anyway, your statement that '0' is replaced by a variable binding is simply false. If you really believe this isn't fake, SUBMIT an SR.

    But your real problem isn't Oracle: it is your 'application', which is a mess anyway. Allowing for alphanumeric numbers is a very bad idea.
    Now, you already put workaround on workaround on workaround on workaround.
    Question is this: it is terminal, and you must either to kill him or to replace it.

    -------------
    Sybrand Bakker
    Senior Oracle DBA

  • 12.1.3 extension XSLT editor Query-database mapping function

    Hello

    , We are trying to move from 11.1.1.7 to 12.1.3 JDeveloper. We have developed a number of xsl maps in 11.1.1.7 using the function oraext:query - database Oracle extension (where the namespace oraext is xmlns:oraext ="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc" "). This works in JDeveloper 11.1.1.7 when the test of the card where the call to the map looks like this:

    < xsl: value-of select = "oraext:query - database (concat (& quot; Select fvalue GetMapCodeList ("param1", "param2", "param3") of double, quot;), false (), false (), & quot;jdbc:oracle:thin:dbuser/dbpassword@dbhost:1521:dbservicename & quot;) "/ >"

    In the statement select above is "select GetMapCodeList" which is a function defined in the database which takes 3 parameters. This works very well for us in 11.1.1.7. We are new to 12.1.3 and we get an error test map XSLT in JDeveloper. The error is

    file:/[file path] / [file name] .xsl: XML-22044: function (error) Extension error: Error invoking 'queryDatabase':'java.lang.NoClassDefFoundError: oracle/jdbc/OracleConnection '.

    It seems that it cannot find the ojdbc6.jar file, but I don't see where that should be added.

    Edit:

    OK, I realized that the extension functions XPath of Oracle do not appear in my XSLT Map Editor component palette. I also see that when I change the XPath of the oraext:query - database is highlighted by JDev as being invalid. I think my problem is with the extension being not loaded XPath functions.

    Thanks in advance.

    Steve

    OK, after working with the support of the Oracle, the answer is that the ojdbc6.jar did indeed need to be added to the configuration of JDeveloper 12.1.3. To do this the following line was added at the end of the jdev.conf file:

    AddVMOption - Xbootclasspath/r:... /... /.. /oracle_common/modules/Oracle.jdbc_12.1.0/ojdbc6.jar

    The jdev.conf file is located in your Oracle_Home\jdeveloper\jdev\bin directory. Don't forget to adjust the relative path to match your environment. In addition, please note that the only spaces in the AddVMOption line are a space immediately after "AddVMOption".

    Another concern in this thread that the functions of data base in the XPath Group advanced components from the component Palette was missing. The groups Advanced general XPath XPath and XSLT components model will appear only in the component Palette if the application is a SOA application.

    A score more. I don't know if Oracle sees this as a bug and the ojdbc6.jar to be in the classpath without the user set it up like that in the jdev.conf. If it's a bug, and then if all goes well it will be resolved in a future release, and this configuration will be necessary.

  • Convert the SQL query to Oracle

    Hi all

    I have two SQL queries to create the table.

    Query1.

    CREATE TABLE [dbo]. [DocumentType] (
    [DocType] [varchar] (20) GATHER SQL_Latin1_General_CP1_CI_AS NOT NULL,.
    [SubCat] [varchar] (20) GATHER SQL_Latin1_General_CP1_CI_AS NOT NULL
    ) ON [PRIMARY]
    GO
    ALTER TABLE [dbo]. [DocumentType] ADD
    CONSTRAINT [PK_DocumentType] PRIMARY KEY CLUSTER
    (
    [DocType],
    [SubCat]) ON [PRIMARY]


    Query2.

    CREATE TABLE [dbo]. [SBU] (
    [SBU] [varchar] (51) GATHER SQL_Latin1_General_CP1_CI_AS NOT NULL
    ) ON [PRIMARY]
    GO
    ALTER TABLE [dbo]. [SBU] ADD
    [PK_SBU] CLUSTERED PRIMARY KEY CONSTRAINT
    (
    [SBU]
    ) ON [PRIMARY]

    What will be the query in Oracle?

    Please suggest!
    Kind regards
    Shah

    Query1.

    CREATE TABLE dbo. DocumentType)
    DocType varchar2 (20) NOT NULL,
    SubCat varchar (20) NOT NULL,
    CONSTRAINT PK_DocumentType PRIMARY KEY (DocType, SubCat)
    )
    /

    Query2.

    CREATE TABLE dbo. SBU)
    SBU varchar2 (51),
    CONSTRAINT PK_SBU PRIMARY KEY (UDF)
    )
    /

    It is useful for you?

    Published by: insa on June 12, 2012 22:42

  • Where should I contact regarding the functions of newsgroups in Windows Mail and Windows Live Mail?

    Where should I contact regarding the functions of newsgroups in Windows Mail and Windows Live Mail?

    I seem to have problems with Windows Mail, perhaps caused by the update KB978542 and/or run the program WMUtil.

    One of my Windows Vista Home Premium SP2 64-bit machines, whenever I try to start Windows Mail, it displays 0x800C0155 error message, then a message saying that he was unable to start because MSOE. DLL could not be initialized.

    The other has problems of material type instead: it's a laptop with no mouse and no reliable connection to the internet.

    On my Windows Vista Home Premium SP2 32-bit machine, I can start Windows Mail, but most local issues have disappeared - only the Inbox is visible.  I already checked that subdirectories for the other files are still present.

    All three of these machines have had problems of backups for months and have had no successful backup for the last two months.

    I have trouble finding enough information about Windows Live Mail without having to install this program if it could avoid these problems or just make it worse.

    http://www.Vistax64.com/tutorials/62560-Windows-Mail-problems.html

    The link above covers solutions to many problems with Windows Mail.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    «The other has problems of material type instead - it's a laptop without mouse and reliable connection to the internet.»

    A computer repair shop will help you with hardware problems.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    http://www.google.com.au/search?hl=en&q=Windows+Live+Mail&btnG=Search&aq=f&aqi=G2G-c1g7&AQL=&OQ=&gs_rfai=

    Read the info at Google re Windows Live Mail.

    See you soon.

    Mick Murphy - Microsoft partner

  • pass the query to oracle

    Hi all

    How can I send a query to oracle using cfstoredprod?

    Try this:

    < datasource = "" #application.dsn # cfstoredproc "procedure =" #importTable #">"

    < cfprocparam type = 'in' cfsqltype = "cf_sql_refcursor" value = "#myQuery #" >

    < / cfstoredproc >

    The Oracle code:

    Procedure importTable (v_table IN SYS_REFCURSOR) is

    Error: [Oracle JDBC Driver] impossible to determine the type of the specified object.

    Any ideas?

    Thanks in advance.

    Get your drives and put them in a query object (if they aren't already), let's call it getRecs, and:

    
    INSERT ALL
       
          INTO schema.tableName(columnA, columnB, columnC, etc)
          VALUES (,,,)
       
       SELECT * FROM DUAL
    
    

    You must include the "SELECT * FROM DUAL" after the loop to exit.  Connect it to your database (Oracle), insert all the lines and disconnect.  Place it in a CFTRANSACTION tag to make sure that they are all inserted or all cancelled.

    HTH,

    ^_^

  • SQL Query for Oracle DB followed by using vCOPS

    Hi guys,.

    I installed a general SQL adapter to monitor an Oracle database in my environment. But I am not able to make it work there are a lot of problems in writing a SQL Quries. I work with one of the DBA and we are still not able to write the query to the right. Can someone give me an example of a query so that I can test it or tell me how to write the query to Oracle DB. Examples of files that are given under/samples/folder conf in the plug-in does not help us. So if someone has a link or if someone has it please help me with query files.

    Thanks in advance

    fix. the biggest challenge with the SQL adapter is to write the query in such a way the release of product that is easily consumable by vcops and maps directly to RESOURCEKIND and RESOURCENAME in vcops. The result can also be hierarchical for more efficiency, i.e.

    metric

    -submetric1

    -submetric2

  • What is the best way to optimize a SQL query: call a function or doing a join?

    Hi, I want to know what is the best way to optimize a SQL query, call a function inside the SELECT statement, or make a simple join?

    It depends on.  Could be a.  Could be the other.  Could be no difference.  You would need to compare with your tables in your environment with your settings.

    If you put a gun to my head, I was given no other information and required that I answered the question, I would tend to wait that the join would be more effective.  In general, if you can do something in pure SQL, it will be more effective than if you call PL/SQL.

    Justin

  • Failed to open oracle functions after R12 installation on windows 2008 64 bit

    Hi guys
    I installed oracle R12.1.1 on windows server 2008 R2 64-bit, then the application opens but all forms of oracle functions cannot open, the message appear frm-92101, I try the solutions in the net, but no effect and I get another windows which and this message appears when trying to open an another oracle functions
    ""
    program currently running on this computer is attempting to display a message, then
    title of the message:
    E:\oracle\VIS\apps\tech_st\10.1.3\appsutil\jdk\bin\java '-serv ".


    This problem come when a program is not completely compatible with windows
    ""
    This message when you start windows too, but the path of java inside files of oracle applications, please help me if oracle r12.1.1 compatible with win 2008 64 bit or not?

    I installed oracle R12.1.1 on windows server 2008 R2 64-bit, then the application opens but all forms of oracle functions cannot open, the message appear frm-92101, I try the solutions in the net, but no effect and I get another windows which and this message appears when trying to open an another oracle functions

    Direct installation of R12 on Windows 2008 64 bit is not supported. You install it on a Windows 32-bit operating system, and then migrate to Windows 64 - bit.

    Oracle E-Business Suite installation and upgrade version Notes 12 (12.1.1) for Microsoft Windows Server (32-bit) [ID 761567.1]
    Migration Oracle E-Business Suite R12 to Microsoft Windows Server 2008 R2 [ID 1188535.1]

    Thank you
    Hussein

  • A query regarding the creation of shared objects.

    Hello

    I have a query regarding the creation of shared objects.

    I saw an example where the author is creatining Shared Object as shown
    below:


    SharedObj = null;
    sharedObj = SharedObject.getLocal ("myTasks");

    and there is nothing related to the word "myTasks" anywhere in the Application.

    Can someone please let me know what this word "myTasks" mean here?

    Thanks in advance.

    Hello

    With a shared object, it will create one if it does not exist, then "myTasks" becomes the name of the shared object or if it exists it will load all the objects that are in the shared object.

    Here is a simple example that uses the sharedobjects to store the connection information.

    http://gumbo.flashhub.NET/login/

    David

  • The HTML that is returned by an Oracle function...

    What is the best way to view the HTML code that is returned by an Oracle function (Apex 3.2.1.00.10)?

    I tried in many ways...

    I don't want to have a visible, but even when I do that, the first returned row Editor:

    < b > text < /b >

    It shows in "BOLD", but for some reason, it escapes from the second < \b > and the fact like that "& lt;" \b & gt; "so it's show < \b > and everything is"BOLD"...

    tward wrote:
    What is the best way to view the HTML code that is returned by an Oracle function (Apex 3.2.1.00.10)?

    I tried in many ways...

    I don't want to have a visible, but even when I do that, the first returned row Editor:

    a text

    It shows in "BOLD", but for some reason, it escapes from the second <\b>and done like this '< \b >"so he showed <\b>and everything is"BOLD"...

    you have the backslash "close tag"... it should be
    < b > text < /b >

    Note the slash!

  • Conversion in Oracle function.

    Hello

    So here's the scenario I have. I was wondering if there is any oracle function provides or is it possible that I could achieve this goal.
    CREATE OR REPLACE procedure TestA 
    (
          partnumber               IN  number,
          partsubnum               IN  varchar2,
          errstring             OUT varchar2
    ) as
    
    --  Declare local variables
    
    ll_inputpartnum varchar2(100);
    
    
    Begin
    
        ll_inputpartnum := partnumber || partsubnum; -- Concatinate partnumber and partsubnum
      -- Will need to convert this variable to number.
    
        TestB.Process(ll_inputpartnum,parameter2, s_errstring, errnum); --ll_inputpartnum must be of type number 
         if  errnum <> compkg.success then
           errstring := s_errstring;
           return;
         end if;
      
      
    Exception 
        When others then 
        Null;    
    End;
    /
    I don't have the ability to change anything about how to TestB.Process.

    There are therefore two problem I am trying to solve in this scenario.

    First, the input parameter - ll_inputpartnum in TestB.Process takes input of only of number type. So I need to convert somehow the concatenated in full ll_inputpartnum.

    Second problem, procedure TestB.Process - after completing his treatment, goes from ll_inputpartnum to the third procedure. Let's say TestC procedure. TestC procedure, so I need to break in again value concatenated in original partnumber and partsubnum.

    The value concatenated - ll_inputpartnum does not change through this process.

    So, I'm trying to understand the best way to approach this situation.

    Thank you

    Published by: Ramses on May 25, 2010 13:18

    with a function like (using also the package of William)

    function combine_parts(p_partnum in integer,p_partsubnum in varchar2) return integer is
      l_length pls_integer := 5;  /* adjust to the maximum possible length of partsubnum */
      hex_val  varchar2(5) := '';
    begin
      if length(p_partsubnum) > l_length then
        return 0;
      end if;
      for i in 1 .. l_length loop
        hex_val := hex_val || to_base(ascii(substr(lpad(p_partsubnum,l_length,chr(0)),i,1)),16)
      end loop;
      return p_partnum * power(256,l_length) + to_decimal(hex_val,16);
    end;
    

    You can simply

    ll_inputpartnum := combine_parts(partnum,partsubnum);
    

    and finally, the parameter ll_inputpartnum can be connected to the appropriate process
    you will need another function to find partnum and partsubnum in another process, because it will be just ll_inputpartnum

    function concatenated_parts(p_number in integer,p_separator in varchar2 default '|') return varchar2 is
      l_length pls_integer := 5;  /* adjust to the maximum possible length of partsubnum */
      hex_val  varchar2(5);
      chr_val  varchar2(5) := '';
      l_partnum integer;
    begin
      l_partnum := trunc(p_number / power(256,l_length));
      hex_val := to_base(p_number - l_partnum * power(256,l_length),16);
      if length(hex_val) > l_length then
        return '';
      end if;
      for i in 1 .. l_length loop
        chr_val := chr_val || chr(to_decimal(substr(hex_val,i,1),16));
      end loop;
      return to_char(l_partnum) || p_separator || chr_val;
    end;
    

    Concerning

    Etbin

    p.s. features are not tested (no database home)

  • UNIX_TIMESTAMP and FROM_UNIXTIME from MySQL to ORACLE functions

    Hi all

    I'm migrating some functions and stored procedures in MySQL to ORACLE, and I the next instruction

    Set valuedat = FROM_UNIXTIME (valor + UNIX_TIMESTAMP ('2000-1-01 00:00:00 '));

    Since MySQL.

    Look, I found that:

    UNIX_TIMESTAMP ('2000-1-01 00:00:00 ')

    can be equivalent to the following query:

    SELECT (to_date (January 1, 2000 "," MON-DD-YYYY')-to_date('01-jan-1970','DD-MON-YYYY')) * (86400) as dt FROM dual;

    but testing the numbers is not the same

    Please can someone help me!

    Specifically, I need to know how to build the equivalent in oracle for FROM_UNIXTIME and UNIX_TIMESTAMP functions

    Thank you and best regards!

    CRGM

    Hello

    These are functions that I built to solve the original requirement, thanks for all your comments.

    ************************************************************************************************************************************

    CREATE OR REPLACE FUNCTION FROM_UNIXTIME

    (

    TIMESTAMP_ NUMBER

    ) AS OF DATE OF RETURN

    NUMBER OF SECONDS_PER_DAY: = 86400;

    MASK (50 CHAR) VARCHAR2: = 'DD-Mon-YYYY HH24:MI:SS ";

    DATE OF REF_DATE;

    BEGIN

    REF_DATE: = TO_DATE ('01 - ENE - 1970 00:00:00 ', MASK);

    RETURN REF_DATE + (TIMESTAMP_/SECONDS_PER_DAY);

    END FROM_UNIXTIME;

    **********************************************************************************************************************************

    CREATE OR REPLACE FUNCTION UNIX_TIMESTAMP

    (

    DATE_ IN DATE

    ) RETURN AS NUMBER

    NUMBER OF SECONDS_PER_DAY: = 86400;

    NUMBER OF DIFF_BETWEEN_DATES;

    MASK (50 CHAR) VARCHAR2: = 'DD-Mon-YYYY HH24:MI:SS ";

    DATE OF REF_DATE;

    BEGIN

    REF_DATE: = TO_DATE ('01 - ENE - 1970 00:00:00 ', MASK);

    DIFF_BETWEEN_DATES: = TO_DATE (TO_CHAR (SYS_EXTRACT_UTC (DATE_), MASK), MASK)

    -REF_DATE;

    RETURN DIFF_BETWEEN_DATES * SECONDS_PER_DAY;

    END UNIX_TIMESTAMP;

    ******************************************************************************************************************************

    Concerning

  • convert the access query to oracle sql

    I'm trying to convert this query MS Access to oracle sql:

    Sum (IIf (IsNull ([INV_MTL_MATERIAL_TRANSACTIONS1]! [PRIMARY_QUANTITY]), 0,-[INV_MTL_MATERIAL_TRANSACTIONS1]! [PRIMARY_QUANTITY])) AS PRIMARY_QTY


    I tried to convert myself but still no luck.  Invalid number of arguments.


    Sum (if (NVL (INV. MTL_MATERIAL_TRANSACTIONS1. PRIMARY_QUANTITY), 0,-INV. MTL_MATERIAL_TRANSACTIONS1. PRIMARY_QUANTITY)) AS PRIMARY_QTY


    Can someone help me convert this request? Thank you.

    The immediate if (IIF) statement said:

    If primary_quantity is null return 0 for another return negative primary_quantity.

    Since there is no difference at all between 0 and - 0 I would write it as:

    sum (nvl (primary_quantity, 0) * - 1).

    Change a minute later, never send before thinking.

    Because you are just adding up the values obtained, he must not care about NULL values at all as aggregate functions generally ignore nulls, it should just be:

    Sum (primary_quantity * - 1).

    John

  • Restrict a query to oracle

    Hello

    I have a query that takes a long time to run is there a way I can set a timeout for the query so that the query & not the session is killed on the oracle 10g database.

    Thanks in advance

    Hello

    I think that you referenced http://www.pythian.com/blog/oracle-limiting-query-runtime-without-killing-the-session/

    Excerpt from the ORACLE_BASE

    CANCEL_SQL and KILL_SESSION

    In addition to switching automatically consumer groups, CREATE_PLAN_DIRECTIVE procedure to automatically cancel a SQL statement or kill the session if it exceeds its limit SWITCH_TIME. To achieve this set the SWITCH_TIME must be defined as usual, but the SWITCH_GROUP should be set to CANCEL_SQL or KILL_SESSION instead of a consumer group name.

    Kind regards

    Suntrupth

Maybe you are looking for