Using mysql decode function in Java

Hi everybody,
mysql documentation says:
DECODE(crypt_str,pass_str) -->
Decrypts the encrypted string crypt_str using pass_str as the password. crypt_str should be a string returned from ENCODE().
I used the above function in a Python script and had no problem, but have difficulty using the same thing in my Java code.
I receive runtime error when tried decode() in my Java code in executeQuery("s");. As far as I know the decode() function should be compiled, I can't run the decode() in the mysql command tool and receive a response (as I compiled and ran it in my Python script).
Has anybody ever used this function in the Java code? How? What format did you use? What I should use instead of "s" in this code?
conn is a database connection:
stmt = conn.createStatement();
rs = stmt.executeQuery("s");
I even tried PreparedStatement, but no luck.
Any help is greatly appreciated.

stmt.executeQuery("select blahblahblah, DECODE(fieldName, password), blahblahblah FROM blahblah...")

Similar Messages

  • Use of DECODE function in Discoverer 3.1

    Hi all,
    Is there any better way of using DECODE in Discoverer 3.1, i dont want to use that function in my Discoverer User edition or Admin ed.
    Many of my queries use the DECODE function.
    Your help is greatly appreciated.

    If you created an instance of your time class that you called myTime
    var myTime:Time = new Time(15,15,0);
    and later you wanted another instance with the same time you could write
    var myTime2:Time = myTime.clone()
    It is just there for convienience and doesn't have anything much to do with MVC

  • Why static is used before any function in java

    Sir/Madem
    I'm new in java. I have just started learning java.
    please tell me
    "why static is used before any function in java??????"
    I have searched on net and in soime bokks .But i was unable toget it. what is exact reson of using static in java.

    tandm-malviya wrote:
    Sir/Madem
    I'm new in java. I have just started learning java.
    please tell me
    "why static is used before any function in java??????"
    I have searched on net and in soime bokks .But i was unable toget it. what is exact reson of using static in java.It's actually seldom used in "real" applications. static associates the method with the class instead of an instance.
    Kaj

  • How Can I use Mysql's  PROCEDURE by Java Can you give me sample???

    �������^���������������H�iBEGIN�`END�u���b�N�j�@��TOP
    ORACLE�@MSSQL�@SSA�@MySQL�@
    ���{�I���������������������������B
    MySQL�������A ORACLE��MSSSQL��������������BEGIN�`END�u���b�N�����s�������������������������B
    ���������s�������������K���X�g�A�h�v���O�����������R���p�C�������K�v�����������B
    �i�����F�������������������A���w�E�������������K�r�����������j
    --drop PROCEDURE sp_hoge;
    --�f���~�^�����X��������
    delimiter //
    CREATE PROCEDURE sp_hoge()
    DETERMINISTIC
    BEGIN
    /* �������� */
    DECLARE mystr VARCHAR(20);
    DECLARE mycnt INTEGER(2);
    /* �l������ */
    SET mycnt = 0;
    SET mystr = '����';
    /* IF�� */
    IF mycnt = 0 THEN
    SET mystr = '�����Q';
    select mystr;
    ELSE
    select '�����R';
    END IF;
    /* CASE�� */
    CASE extract(month from now())
    WHEN 1 THEN SET mystr = '1��';
    WHEN 2 THEN SET mystr = '2��';
    WHEN 3 THEN SET mystr = '3��';
    WHEN 4 THEN SET mystr = '4��';
    ELSE SET mystr = '1�`4�����O';
    END CASE;
    select mystr;
    /* WHILE-LOOP */
    WHILE mycnt <= 5 DO
    SET mycnt = mycnt + 1;
    select mycnt;
    END WHILE;
    /* BEGIN-END�u���b�N������SELECT�������s */
    /* PROCEDURE�������\�iFUNCTION���������������j */
    select * from help_topic;
    END//
    delimiter ;
    --�X�g�A�h�v���V�[�W�����s
    call sp_hoge();
    �X�g�A�h�v���V�[�W�����T���v���i�J�[�\�����g�p������LOOP�����j�@��TOP
    ORACLE�@MSSQL�@SSA�@MySQL�@
    �J�[�\�����g�p����LOOP�������T���v�������B
    �����p�����[�^���w�����������������Y�������������������A���E���w�X�^�b�t�x�������������A�����������w�c���X�^�b�t�F�x���\���������B
    --drop PROCEDURE sp_hoge;
    --�f���~�^�����X��������
    delimiter //
    CREATE PROCEDURE sp_hoge(inum INTEGER(3))
    DETERMINISTIC
    BEGIN
    /* �������� */
    /* �J�[�\���g�p�����f�[�^�L�����f���g�p */
    DECLARE done INT DEFAULT 0;
    /* �������O������ */
    DECLARE v_mystr VARCHAR(20);
    /* �J�[�\���g�p�� */
    DECLARE v_empnm VARCHAR(40);
    DECLARE v_job VARCHAR(20);
    /* �J�[�\������ �� �����������������`���� */
    DECLARE cur1 CURSOR FOR
    select empnm,job from kemp where deptno = inum;
    /* �f�[�^��������LOOP�E�o�p���������� */
    DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
    /* �J�[�\���I�[�v�� */
    OPEN cur1;
    /* LOOP */
    LOOPPROC:REPEAT
    FETCH cur1 INTO v_empnm,v_job;
    IF NOT done THEN
    IF v_job = '�X�^�b�t' THEN
    SET v_mystr = '�c���X�^�b�t�F';
    ELSE
    SET v_mystr = '';
    END IF;
    select CONCAT(v_mystr,v_empnm);
    /* ������������LOOP���E�o����������LEAVE�� */
    /* LEAVE LOOPPROC; */
    END IF;
    UNTIL done END REPEAT;
    /* �J�[�\���N���[�Y */
    CLOSE cur1;
    END//
    --�f���~�^���Z�~�R�����i�f�t�H���g�j������������
    delimiter ;
    --�X�g�A�h�v���V�[�W�����s
    call sp_hoge(1);
    12.2. Control Flow Functions
    CASE value WHEN [compare_value] THEN result [WHEN [compare_value] THEN result ...] [ELSE result] END
    CASE WHEN [condition] THEN result [WHEN [condition] THEN result ...] [ELSE result] END
    The first version returns the result where value=compare_value. The second version returns the result for the first condition that is true. If there was no matching result value, the result after ELSE is returned, or NULL if there is no ELSE part.
    mysql> SELECT CASE 1 WHEN 1 THEN 'one'
    -> WHEN 2 THEN 'two' ELSE 'more' END;
    -> 'one'
    mysql> SELECT CASE WHEN 1>0 THEN 'true' ELSE 'false' END;
    -> 'true'
    mysql> SELECT CASE BINARY 'B'
    -> WHEN 'a' THEN 1 WHEN 'b' THEN 2 END;
    -> NULL
    The default return type of a CASE expression is the compatible aggregated type of all return values, but also depends on the context in which it is used. If used in a string context, the result is returned as a string. If used in a numeric context, then the result is returned as a decimal, real, or integer value.
    Note: The syntax of the CASE expression shown here differs slightly from that of the SQL CASE statement described in Section 17.2.10.2, �gCASE Statement�h, for use inside stored routines. The CASE statement cannot have an ELSE NULL clause, and it is terminated with END CASE instead of END.
    IF(expr1,expr2,expr3)
    If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL) then IF() returns expr2; otherwise it returns expr3. IF() returns a numeric or string value, depending on the context in which it is used.
    mysql> SELECT IF(1>2,2,3);
    -> 3
    mysql> SELECT IF(1<2,'yes','no');
    -> 'yes'
    mysql> SELECT IF(STRCMP('test','test1'),'no','yes');
    -> 'no'
    If only one of expr2 or expr3 is explicitly NULL, the result type of the IF() function is the type of the non-NULL expression.
    expr1 is evaluated as an integer value, which means that if you are testing floating-point or string values, you should do so using a comparison operation.
    mysql> SELECT IF(0.1,1,0);
    -> 0
    mysql> SELECT IF(0.1<>0,1,0);
    -> 1
    In the first case shown, IF(0.1) returns 0 because 0.1 is converted to an integer value, resulting in a test of IF(0). This may not be what you expect. In the second case, the comparison tests the original floating-point value to see whether it is non-zero. The result of the comparison is used as an integer.
    The default return type of IF() (which may matter when it is stored into a temporary table) is calculated as follows:
    Expression Return Value
    expr2 or expr3 returns a string string
    expr2 or expr3 returns a floating-point value floating-point
    expr2 or expr3 returns an integer integer
    If expr2 and expr3 are both strings, the result is case sensitive if either string is case sensitive.
    Note: There is also an IF statement, which differs from the IF() function described here. See Section 17.2.10.1, �gIF Statement�h.
    IFNULL(expr1,expr2)
    If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2. IFNULL() returns a numeric or string value, depending on the context in which it is used.
    mysql> SELECT IFNULL(1,0);
    -> 1
    mysql> SELECT IFNULL(NULL,10);
    -> 10
    mysql> SELECT IFNULL(1/0,10);
    -> 10
    mysql> SELECT IFNULL(1/0,'yes');
    -> 'yes'
    The default result value of IFNULL(expr1,expr2) is the more �ggeneral�h of the two expressions, in the order STRING, REAL, or INTEGER. Consider the case of a table based on expressions or where MySQL must internally store a value returned by IFNULL() in a temporary table:
    mysql> CREATE TABLE tmp SELECT IFNULL(1,'test') AS test;
    mysql> DESCRIBE tmp;
    -------------------------------------------+
    | Field | Type | Null | Key | Default | Extra |
    -------------------------------------------+
    | test | char(4) | | | | |
    -------------------------------------------+
    In this example, the type of the test column is CHAR(4).
    NULLIF(expr1,expr2)
    Returns NULL if expr1 = expr2 is true, otherwise returns expr1. This is the same as CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END.
    mysql> SELECT NULLIF(1,1);
    -> NULL
    mysql> SELECT NULLIF(1,2);
    -> 1
    Note that MySQL evaluates expr1 twice if the arguments are not equal.
    Previous / Next / Up / Table of Contents
    User Comments
    Posted by I W on July 12 2005 5:52pm [Delete] [Edit]
    Don't use IFNULL for comparisons (especially not for Joins)
    (example:
    select aa from a left join b ON IFNULL(a.col,1)=IFNULL(b.col,1)
    It's terrible slow (ran for days on two tables with approx 250k rows).
    Use <=> (NULL-safe comparison) instead. It did the same job in less than 15 minutes!!
    Posted by [name withheld] on November 10 2005 12:12am [Delete] [Edit]
    IFNULL is like oracle's NVL function (these should help people searching for NVL() ..)
    Posted by Philip Mak on May 26 2006 7:14am [Delete] [Edit]
    When using CASE, remember that NULL != NULL, so if you write "WHEN NULL", it will never match. (I guess you have to use IFNULL() instead...)
    Posted by Marc Grue on June 24 2006 2:03pm [Delete] [Edit]
    You can ORDER BY a dynamic column_name parameter using a CASE expression in the ORDER BY clause of the SELECT statement:
    CREATE PROCEDURE `orderby`(IN _orderby VARCHAR(50))
    BEGIN
    SELECT id, first_name, last_name, birthday
    FROM table
    ORDER BY
    -- numeric columns
    CASE _orderby WHEN 'id' THEN id END ASC,
    CASE orderby WHEN 'desc id' THEN id END DESC,
    -- string columns
    CASE orderby WHEN 'firstname' THEN first_name WHEN 'last_name' THEN last_name END ASC,
    CASE orderby WHEN 'descfirst_name' THEN first_name WHEN 'desc_last_name' THEN last_name END DESC,
    -- datetime columns
    CASE _orderby WHEN 'birthday' THEN birthday END ASC,
    CASE orderby WHEN 'desc birthday' THEN birthday END DESC;
    END
    Since the CASE expression returns the "compatible aggregated type of all return values", you need to isolate each column type in a separate CASE expression to get the desired result.
    If you mixed the columns like
    CASE _orderby
    WHEN 'id' THEN id
    WHEN 'first_name' THEN first_name
    ...etc...
    END ASC
    .. both the id and first_name would be returned as a string value, and ids would be sorted as a string to '1,12,2,24,5' and not as integers to '1,2,5,12,24'.
    Note that you don't need a "ELSE null" in the CASE expressions, since the CASE expression automatically returns null if there's no match. In that case, you get a "null ASC" in your ORDER BY clause which doesn't affect the sort order. If for instance orderby is 'descfirst_name', the ORDER BY clause evaluates to:
    ORDER BY null ASC, null DESC, null ASC, first_name DESC, null ASC, null DESC
    Effectively the same as "ORDER BY first_name DESC". You could even add a new set of CASE expressions for a second order column (or more..) if you like.
    Add your own comment.

    What is that post supposed to be?

  • How to use a decode function

    I want to use the following with decode, recently started on BODS.
    Can you please provide the steps to use decode function
    in source tabke fieldname is ordid and in target fieldname is Orderid
    decode(Order_ID = 1709,lpad(Order_ID,7,'700'),Order_ID)
    thank you very much for the helpful i

    1) In the mapping tab of target column, click on Functions, select Miscellaneous Functions category, you can find decode function in it. Lpad can be found in String functions category.
    OR
    2) You can directly script this or paste this code at the mapping tab. In this case, remove the Order_ID from the script wherever used, drag and drop this column from the input schema of Query transform to avoid the syntax error. 
    Regards,
    Suneer

  • How to use dll's(Functions) in java ?

    Hi
    I want to use the windows : shell32.dll. The declaration is as follows:
    Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
         ByVal hwnd As Long, _
         ByVal lpOperation As String, _
         ByVal lpFile As String, _
         ByVal lpParameters As String, _
         ByVal lpDirectory As String, _
         ByVal nShowCmd As Long) As Long
    I load the library via System.loadLibrary("shell32") and define the native methods(in java code):
    public native long ShellExecute(
    long hwnd, String lpOperation, String lpFile,
              String lpParameters, String lpDrectory, long nShowCmd);
    but i get a: java.lang.UnsatisfiedLinkError: ShellExecute. Whats wrong ? For long hwnd i used "0" for the first time, but this shouldn't be the problem. Any idea ?
    hte problem i have is to execute a very difficult programm. this need a system(windows) shell to run. so i try to start it with the shell32.dll. in VisualBasic i found my aim using this topic, but it doesn't run in java.
    thanks for help.
    pain
    pain

    work at this addresses: http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.html
    If you understand anything write me, too. because I have the same problem and I worked and I coul not understand
    Good Luck..
    ABDURRAH&#304;M KAPLAN [email protected]

  • Using oracle decode function in ssQueryText

    Hi,
    I am populating the values for ssQueryText, ssSortField etc from the fragment parameters. Then i am using these field values in fragment jsp, put those values in the serverbean and executing the service. I am getting the results, and the results are also sorted the way i want.
    The problem is i want to fetch the data from the DB, while fetching i want to check a column value, based on the value i want to temporarily modify that column value and only after modifying i want to sort the data in the table based on the value of modified column.
    If some one has tried this earlier please suggest.
    Thanks,
    Santosh

    stmt.executeQuery("select blahblahblah, DECODE(fieldName, password), blahblahblah FROM blahblah...")

  • How to use to_char(oracle function) in java

    Hi,
    I am getting the value as a integer from one table in my java file and want to insert it into another table as a varChar..
    I found one method in oracle like to_char().. can i use this in java..
    can u pls let me know how to use this in java..or is there any other way to convert it..
    for example, i am getting the value is : 4 (number) from one table. and want to insert it into another table like : 04 (varchar)..
    how can i convert it and insert into another table as a varchar..
    please help me

    Well part of the answer depends on what db your using but semantically if I just HAD to do what you're doing I would use a stored procedure to do the insert into the second table or better yet do the whole thing in a stored procedure which would make life much easier all the way around.
    Implicit lesson here: Use the RIGHT tool for the job at hand.
    The big question though is why do you have data that's of one type in one place and another type in another place?
    PS.

  • Using DECODE Function to change data

    I am trying to use the Decode function in a SQL statement to find a field that has a specific type, and when it finds that type, I want to blank out the results in a different field.
    For example:
    DECODE(ADDR_TYPE,'HOME',PHONE='') HOME_PHONE

    something like:
    SQL> with t as
      2   (select 219 id,
      3           'BUS' addr_type,
      4           '505-555-5555' phone
      5      from dual
      6    union
      7    select 219 id,
      8           'HOME' addr_type,
      9           null   phone
    10      from dual
    11    union
    12    select 220 id,
    13           'BUS' addr_type,
    14           '101-111-1111'   phone
    15      from dual
    16    union
    17    select 220 id,
    18           'HOME' addr_type,
    19           null   phone
    20      from dual
    21    union
    22    select 223 id,
    23           'BUS' addr_type,
    24           '202-222-2222'   phone
    25      from dual
    26    union
    27    select 224 id,
    28           'HOME' addr_type,
    29           '303-333-3333'   phone
    30      from dual
    31    union
    32    select 225 id,
    33           'BUS' addr_type,
    34           null   phone
    35      from dual
    36    union
    37    select 226 id,
    38           'HOME' addr_type,
    39           null   phone
    40      from dual)
    41  select a.id,
    42         a.addr_type,
    43         decode(a.addr_type,'BUS',phone,null) phone
    44    from (select id, addr_type, phone,
    45                 row_number() over (partition by id order by id, decode(addr_type,'BUS',1,2)) rn
    46            from t) a
    47   where a.rn = 1;
            ID ADDR PHONE
           219 BUS  505-555-5555
           220 BUS  101-111-1111
           223 BUS  202-222-2222
           224 HOME
           225 BUS
           226 HOME
    6 rows selected.
    SQL>

  • Order by clause using decode function

    Hi everybody,
    i need below order in my report.
    Connecticut
    greenwich
    stamford
    bridgeport
    New York
    NYC
    wrestcher
    byram
    Georgia
    atlanta
    athens
    oconny
    first i need above order in my view out put.
    so in order by clause i used first decode function for State ordering
    and in second decode function for city ordering.
    i do not need order by ascending or descending.
    so pls anybody can help me.
    any help is greatly appreciated.
    thanks.

    add asc after the decode. default is desc

  • How to use decode function

    Hello Friends,
    I have a query that has different columns and I am not sure what the data type of each column is ...
    I want to use decode function which displays the following if the value of the column is like this ..
    if the value of column is -714E ie -700000000000000 then display as .A
    if the value of column is -814E ie -800000000000000 then display as .B
    NOTE ; don't know which column is having the value - and i don't know the data type of the column is ..
    got to use the decode function for all the columns selected ..
    I want to use decode function pls let me know how to write for this kind of requirement.
    appreciate your help in this rgds.
    thanks/kumar

    Dear Sir / Madam,
    Thanks for your understanding.
    Right now I am facing a unique problem.
    I am using decode function in a select statement. The columns are dynamic some columns are of type number and some are varchar datatypes. I want to apply decode function for every column irrespective of datatype.
    What i am finding difficult is if the column is a number datatype , the decode funciton is working good but if the column datatype is varchar or char datatype then i am getting ..
    here's the decode function..
    decode (CHAI.EVNDRIVE,
    -800000000000000,'.A',
    -700000000000000, '.B',
    -600000000000000 ,'.C',
    -500000000000000 , '.D',
    -400000000000000 , '.E',
    -300000000000000 , '.F',
    -200000000000000, '.G',
    -100000000000000 , '.H',
    -1000000000, '.R' ,CHAI.EVNDRIVE ) EVNDRIVE
    report error:
    ORA-01722: invalid number
    pls let me know how to over come this kind of scenario.
    is their a way to find whether the column datatype is number or char , so that i can check the column datatype before the decode funciton is applied ..
    thanks ..
    kumar

  • Mysql 5 Functions HELP

    Heres a recap of the problem.
    Im migrating from coldfusion using oracle db with packages to
    coldfusion using mysql5 and hoping to use mysql 5 functions in
    place of the oracle packages.
    Now the problem is when I try to use a function inside of a
    sql statement in coldfusion the mysql server shuts down and
    coldfusion bombs with an error..
    Heres some of my code.
    I can successfully run this:
    <cfquery name="Test" datasource="kiwanis" maxrows="10">
    Select kiwanis.GetPositionDesc('CU') test
    </cfquery>
    I cannot run this:
    <cfquery name="Test" datasource="kiwanis" maxrows="10">
    Select kiwanis.GetPositionDesc('CU') test from
    kiwanis.members
    </cfquery>
    The code im changing is just for testing purposes. when I run
    this code, mysql 5 stops and then coldfusion bombs with a no
    connection to db error:
    "Communications link failure due to underlying exception: **
    BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE:
    Connection reset STACKTRACE: java.net.SocketException: Connection
    reset at java.net.SocketInputStream.read(Unknown Source) at
    com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
    at
    com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInp utStream.java:160)
    at
    com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1910) at
    com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304) at
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803) at
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573) at
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665) at
    com.mysql.jdbc.Connection.execSQL(Connection.java:3118) at
    com.mysql.jdbc.Connection.execSQL(Connection.java:3047) at
    com.mysql.jdbc.Statement.execute(Statement.java:690) at col... "
    Now I can take my sql statements and run them in the mysql
    query browser just fine. I get the correct output.
    Why is coldfusion killing the connection?
    I've tried running coldfusion 6 and coldfusion 7.
    I've tried running ever possible J connector I could find on
    the mysql site.
    I've messed around with syntax etc with the queries and Im
    still no where.
    I havn't been able to find information if any about mysql
    functions. Are these fully supported?
    Any help would be greatly apreaciated, thanks.
    -Dan

    I had issues as well which I eventually overcame.
    See the following thread :-
    http://discussions.apple.com/message.jspa?messageID=5649480#5649480

  • DECODE function to validate date value and sort the records

    Hi Friends,
    I am looking for some query which can give me the required output,
    I need to do this using SQL query only and I have tried using the MIN() and MAX() functions it was working fine with limited data, now after inserting the last record(in the below table) which has date for start_range and end_range in(mm/dd/yyyy hh24:mi:ss) format.
    Because the data type is VARCHAR2 if I am using the MIN() function it is sorting as a string value, hence the min date is incorrect. I tried using validating the value to date or non date and tried to using MIN() and MAX() functions using the DECODE function, I am getting this error "ORA-01840: input value not long enough for date format".
    select table_name,
    DECODE(substr(START_RANGE,3,1)||substr(START_RANGE,6,1)||substr(START_RANGE,11,1)||substr(START_RANGE,14,1)||substr(START_RANGE,17,1),'// ::',
    to_char(min(to_date(start_range,'mm/dd/yyyy hh24:mi:ss')),'MM/DD/YYYY HH24:MI:SS'),min(start_range)) MIN_RUNS_START_RANGE,
    DECODE(substr(END_RANGE,3,1)||substr(A.END_RANGE,6,1)||substr(END_RANGE,11,1)||substr(END_RANGE,14,1)||substr(END_RANGE,17,1),'// ::',
    to_char(max(to_date(END_RANGE,'mm/dd/yyyy hh24:mi:ss')),'MM/DD/YYYY HH24:MI:SS'),max(END_RANGE)) MAX_RUNS_END_RANGE
    from MY_TABLE
    GROUP BY table_name,
    (substr(START_RANGE,3,1)||substr(START_RANGE,6,1)||substr(START_RANGE,11,1)||substr(START_RANGE,14,1)||substr(START_RANGE,17,1)),
    (substr(END_RANGE,3,1)||substr(END_RANGE,6,1)||substr(END_RANGE,11,1)||substr(END_RANGE,14,1)||substr(END_RANGE,17,1))
    Can sombody please advise what is the best way I can query this data with the required output.
    The following are the source table and records and the out put records using the sql query.
    MY_TABLE
    TABLE_NAME(VARCHAR2),START_RANGE(VARCHAR2),END_RANGE(VARCHAR2)
    TABLE1,1000,10000
    TABLE2,ABCD,EEEE
    TABLE3,01/12/2010 00:00:00,12/31/2010 23:59:59
    TABLE1,10001,20000
    TABLE2,EEEF,GGGG
    TABLE3,01/01/2011 00:00:00,01/31/2011 23:59:59
    OUTPUT :
    TABLE_NAME,MIN(START_RANGE),MAX(END_RANGE)
    TABLE1,1000,20000
    TABLE2,ABCD,GGGG
    TABLE3,01/12/2010 00:00:00,01/31/2011 23:59:59
    Thanks
    Kalycs

    i also think this is a very bad table design ...
    but if you are not able to change it, you could split the select (date and non-date data) and combine the result with UNION like this:
    with t as
    SELECT 'TABLE1' table_name,'1000' start_range,'10000' end_range FROM dual UNION
    SELECT 'TABLE2','ABCD','EEEE' FROM dual UNION
    SELECT 'TABLE3','01/12/2010 00:00:00','12/31/2010 23:59:59' FROM dual UNION
    SELECT 'TABLE1','10001','20000' FROM dual UNION
    SELECT 'TABLE2','EEEF','GGGG' FROM dual UNION
    SELECT 'TABLE3','01/01/2011 00:00:00','01/31/2011 23:59:59' FROM dual
    SELECT table_name,
           TO_CHAR(MIN(TO_DATE(start_range, 'MM/DD/YYYY HH24:MI:SS')), 'MM/DD/YYYY HH24:MI:SS'),
           TO_CHAR(MAX(TO_DATE(end_range, 'MM/DD/YYYY HH24:MI:SS')), 'MM/DD/YYYY HH24:MI:SS')
    FROM t
    WHERE start_range LIKE '%/%/%:%:%'
    GROUP BY table_name
    UNION
    SELECT table_name,
           MIN(start_range),
           MAX(end_range)
    FROM t
    WHERE start_range NOT LIKE '%/%/%:%:%'
    GROUP BY
        table_name;
    TABLE_ MIN_VALUE           MAX_VALUE
    TABLE1 1000                20000
    TABLE2 ABCD                GGGG
    TABLE3 01/12/2010 00:00:00 01/31/2011 23:59:59

  • DECODE Function In Reports 3.0

    Hi,
    When I use the decode function in a query (Reports 3.0.5.8.0) I receive an error message "Bind Variable Does Not Exist" (ORA-1006). When I remove the decode function from the query, the query compiles fine. All table and column references are existing.
    Also, the same query runs perfectly fine from SQL*Plus. The OS is Win 2000, SP2
    Any idea if this is a bug? Is there any way out? Do get back as this is very urgent.
    The database is Oracle 8i Ent, 8.1.7 on AIX 4.3
    The query is as follows:
    SELECT NAM_CMP , COD_CMP , COD_CMP_REG ,
    DECODE(FLG_CMP_SHP,'Y','S/',' /') || DECODE(FLG_CMP_AGT,'Y','A/',' /') || DECODE(FLG_CMP_CNE,'Y','C',' ') TYPE ,
    DES_ADD_STT , DES_ADD_PLC , DES_ADD_STA , DES_ADD_POS , COD_CTY , COD_cou_iso ,
    DAT_LST_AST , DAT_LST_UPD,
    cod_dcl_box_num, decode(cod_imp_chg_way,'C','CASH','CREDIT') cod_imp_chg_way,
    decode(cod_imp_cre_way,'W','WEEKLY','F','FIFTEEN DAYS','M','MONTHLY', NULL) cod_imp_cre_way,
    decode(flg_imp_prn_inv, 'N', null, flg_imp_prn_inv) flg_imp_prn_inv,
    cod_bro_box_num, decode(cod_exp_chg_way,'C','CASH','CREDIT') cod_exp_chg_way,
    decode(cod_exp_cre_way,'W','WEEKLY','F','FIFTEEN DAYS','M','MONTHLY', NULL) cod_exp_cre_way,
    decode(flg_exp_prn_inv, 'N', null, flg_exp_prn_inv) flg_exp_prn_inv
    FROM CMP
    where dat_can is null

    Try TO_CHAR(NULL) instead of NULL in all DECODE functions.
    For example:
    decode(cod_imp_cre_way,'W','WEEKLY','F','FIFTEEN DAYS','M','MONTHLY', TO_CHAR(NULL))
    instead of:
    decode(cod_imp_cre_way,'W','WEEKLY','F','FIFTEEN DAYS','M','MONTHLY', NULL).

  • Decode function involving 2 fields (urgent)

    Hi .. I am trying to use the decode function involving 2 fields.
    The query runs but does not produce the correct results. If
    anyone knows, please reply .. Usually decode function involves
    one column only but I have more
    than one. The situation is : If ins_code = 2 or special_code =
    MMI, put a 'Y', otherwise, it's a 'N'. Does anyone know how to
    put this in a decode statement? Thanks

    Thanks, Suresh ... but I have to put this condition using the
    decode statement because that's how the rest of the program is
    written. It's part of the script that I have to change. The
    current statement is this: decode(ins_code, '2', 'Y', 'N'). I
    have to change it to ins_code =2 or special_feature = MMI.
    Please reply ... thanks a lot....

Maybe you are looking for

  • Unable to Reboot After Latest Apple Updates (SA-2011-06-23-1 and Security Update 2011-004)

    Hi All, After applying today's updates (06/23/2011) in APPLE-SA-2011-06-23-1 Mac OS X v10.6.8 and Security Update 2011-004, my MacBook will no longer boot. Prior to updating, the MacBook workked perfectly (except for the occasional error entry in the

  • Create a text file output from within a procedure

    I can output to a file from within SQL+ using the spool command but how do I do this from within a procedure? I have got a table called ABC and want to output columns A and B to a new text file based on variables pased through when the procedure is r

  • Listening to audiobooks on iPhone3GS

    Hello everyone, I will be flying for many hours. I want to download an audiobook onto my iPhone 3GS. how does one listen to it? and, if I decide to have a nap, will it begin where it left off? I tried it on a Shuffle last time when I pressed stop. wh

  • Stopping/Starting SAP Systems on System i

    Hello, Currently we are stopping/starting our SAP systems that run on our i5/OS weekly. I'm just curious if anyone else has any recommendations of if this is a good practice or even necessary. This was started about 5 years ago with our R/3 system ju

  • How SharePoint works on orphan blobs

    hi How  SharePoint works on orphan blobs when these orphan blobs created ?, I configured RBS storage  to a  content database of a webapplication, and  in my scenario many users upload documents daily into document library of  this web application adi