In pl/sql string comparison

Hello

I ran the code below and found that the output should be 5 but it shows 7 (always on the other). It does not compare the string in the case. can someone indicate why.

declare
date of check_in_date;
var_day varchar2 (11);
number of rate_id;

Start

check_in_date: = "23-mar-2013;"

Select to_char (check_in_date, 'DAY') in the double var_day;
dbms_output.put_line (var_day);
Select the case sensitive option
When VAR_DAY = 'SATURDAY' THEN
5
WHEN VAR_DAY = "SUNDAY" THEN
6
ON THE OTHER
7

END

in rate_id
Double;

DBMS_OUTPUT. Put_line (rate_id);

end;


Thank you.
Vipin

Change this

Select to_char (check_in_date, 'DAY') in the double var_day;

as

Select to_char (check_in_date, 'fmDAY') in the double var_day;

You can use the "fm" (template format) specificaton otherwise the value will be right padded with a space for the size max.

SQL> select '"' || to_char(sysdate+level, 'DAY') || '"' without_fm,
  2         '"' || to_char(sysdate+level, 'fmDAY') || '"' with_fm
  3    from dual
  4  connect by level <= 7;

WITHOUT_FM  WITH_FM
----------- -----------
"FRIDAY   " "FRIDAY"
"SATURDAY " "SATURDAY"
"SUNDAY   " "SUNDAY"
"MONDAY   " "MONDAY"
"TUESDAY  " "TUESDAY"
"WEDNESDAY" "WEDNESDAY"
"THURSDAY " "THURSDAY"

7 rows selected.

Tags: Database

Similar Questions

  • String comparisons

    Greetings,

    I am a novice user (stating the obvious here) difficulties with string comparisons. The little attached vi ran an once turned green, but never after that I can't seem to indicate green regardless of entry.

    My ultimate goal will be to determine if a device generates the string "enter user ID: "Chain of true/false game" prefaced by a certain type of channel setting would be an acceptable method?

    Thank you

    JVH

    Hi Don,.

    There is a function 'Trim spaces' in the string functions palette...

  • 12 c call Webservice JDeveloper get "SQL string is not a DML statement" as a SQLException exception

    Hi guys,.

    I developed a java class to access the database using the OracleDataSource class and run a SQL query with a select statement. It works very well. I have built a wrapper class and as a Web service. I get "SQL string is not a DML statement" as a SQLException exception when I run as a Web service, but it works very well as an application.

    No idea why I get this error? Not sure why WebSercie is having a problem while this works as an application.

    Thank you and best regards,

    Srini Mel

    Solved the problem by myself.

    The first release "SQL string is not a DML statement" is due to an additional line (pstmt2.executeUpdate ()) in the code.

    Second question, receives not the query response is due to bad user input. I walked into 13.21651 instead of 31.21651.

    Thank you!

    Srini

  • How to call the package from a SQL string function

    I create a SQL string in my c# application. Within the selection, I have a function call to a package in my diagram.

    ex.

    "Select id, package1.fncFormat (text) of tblText".

    If I run this within Oracle it works fine but when I run my application and the SQL runs the use of OracleDataReader I get


    «ORA-00904: "PACKAGE1".» ' FNCFORMAT': invalid identifier.

    Is this possible to do?

    It is a dynamic sql string that is built using many different options.

    Thanks for any help

    Do you run this application and directly on DB package by the same user?
    Check the privileges of the user on the application.

    Kind regards
    Bobin

  • How do 3 similar fun generate different sql string in the call of 1 db

    Hi all
    In my sql package I use 3 different functions to create two different sql strings and the 3rd function does some calculations of percentage. My Db architect on the revision of the code suggest to me that these two functions are almost the same except the sql string, it generates. Then she asked me to write a function that does everything in a db call.

    "_Function 1_ '.

    FUNCTION get_class_select_text
    (
    in_report_parameter_id in NUMBERS
    )
    RETURN VARCHAR2
    IS

    my_class_select_text VARCHAR2 (10000);
    my_class_select_value VARCHAR2 (10000);

    CURSOR class_select_text IS
    SELECT ' SUM (DECODE (bin_id, ' | report_parameters.report_parameter_value))
    || bin_value, 0)) ' Class' | report_parameters.report_parameter_value | '" '
    OF report_parameters
    WHERE report_parameters.report_parameter_id = in_report_parameter_id
    AND report_parameters.report_parameter_group = 'CLASS '.
    AND report_parameters.report_parameter_name = 'CLASS '.
    GROUP BY
    report_parameters.report_parameter_value
    ORDER BY
    CAST (report_parameters.report_parameter_value AS NUMBER);

    BEGIN

    my_class_select_text: = ";

    OPEN class_select_text.

    LOOP

    SEEK class_select_text INTO my_class_select_value;

    EXIT WHEN class_select_text % NOTFOUND;

    my_class_select_text: = my_class_select_text | ', ' || my_class_select_value;

    END LOOP;

    CLOSE Class_select_text;

    RETURN my_class_select_text;

    END get_class_select_text;

    FUNCTION 2:


    FUNCTION get_class_sum_text
    (
    in_report_parameter_id in NUMBERS
    )
    RETURN VARCHAR2
    IS

    my_class_sum_text VARCHAR2 (10000);
    my_class_sum_value VARCHAR2 (10000);

    CURSOR class_sum_text IS
    SELECT ' SUM (NVL ("Class' |")) report_parameters.report_parameter_value | ""(, 0)) ' class' | "" report_parameters.report_parameter_value | '" '
    OF report_parameters
    WHERE report_parameters.report_parameter_id = in_report_parameter_id
    AND report_parameters.report_parameter_group = 'CLASS '.
    AND report_parameters.report_parameter_name = 'CLASS '.
    GROUP BY
    report_parameters.report_parameter_value
    ORDER BY
    CAST (report_parameters.report_parameter_value AS NUMBER);

    BEGIN

    my_class_sum_text: = ";

    OPEN class_sum_text.

    LOOP

    SEEK class_sum_text INTO my_class_sum_value;

    EXIT WHEN class_sum_text % NOTFOUND;

    my_class_sum_text: = my_class_sum_text | ', ' || my_class_sum_value;

    END LOOP;

    CLOSE Class_sum_text;

    RETURN my_class_sum_text;

    END get_class_sum_text;

    FEATURE 3:


    FUNCTION get_class_perc_text
    (
    in_report_parameter_id in NUMBERS
    )
    RETURN VARCHAR2
    IS

    my_class_perc_text VARCHAR2 (10000);
    my_class_perc_value VARCHAR2 (10000);

    CURSOR class_perc_text IS
    SELECT ' ROUND ((("Class' ||)) report_parameters.report_parameter_value | "' / 'Total') (* 100)(, 2) ' class |" " report_parameters.report_parameter_value | '" '
    OF report_parameters
    WHERE report_parameters.report_parameter_id = in_report_parameter_id
    AND report_parameters.report_parameter_group = 'CLASS '.
    AND report_parameters.report_parameter_name = 'CLASS '.
    GROUP BY
    report_parameters.report_parameter_value
    ORDER BY
    CAST (report_parameters.report_parameter_value AS NUMBER);

    BEGIN

    my_class_perc_text: = ";

    OPEN class_perc_text.

    LOOP

    SEEK class_perc_text INTO my_class_perc_value;

    EXIT WHEN class_perc_text % NOTFOUND;

    my_class_perc_text: = my_class_perc_text | ', ' || my_class_perc_value;

    END LOOP;

    CLOSE Class_perc_text;

    my_class_perc_text: = my_class_perc_text | ', ' || ' DECODE 'Total' ('Total', -1, 0, 100) ';

    RETURN my_class_perc_text;

    END get_class_perc_text;


    Could someone help me?

    Thanks in advance.

    Hello
    Never write, not to mention NPA, not formatted.
    Use the spaces so that how the code appears on the screen reflects what it does.
    In particular, to align the bunk directly following each other.
    (a) IS, BEGIN, EXCEPTION and END statements
    (2) the instructions of LOOP and END LOOP
    (3) provisions (SELECT, FROM, WHERE,...) in SQL statements
    (4) number of arguments for the same function (unless they are very simple)
    When displaying a kind of formatting text on this site, type the 6 characters:
    {code}
    (small letters only, inside curly braces) before and after the formatted text, to maintain spacing.

    user10641405 wrote:
    Hi all
    In my sql package I use 3 different functions to create two different sql strings and the 3rd function does some calculations of percentage. My Db architect on the revision of the code suggest to me that these two functions are almost the same except the sql string, it generates. Then she asked me to write a function that does everything in a db call.

    Looks like you are using 3 different functions to create 3 different channels.
    All 3 functions return the results of a query that has a column, a string that is made by concatenating strings under 5.
    It looks like the only differences between the 3 functions are:
    (a) the chains under 1st and 3rd in the concatenation are different in each case
    (b) of the function, we add additional text at the end of the query results

    Here's a way to combine these functions, so that you call
    get_class_text (x, "SELECT") instead of get_class_select_text (x),
    get_class_text (x, "SUM") instead of get_class_sum_text (x), and
    get_class_text (x, "PERC") instead of get_class_perc_text (x).

    FUNCTION get_class_text
    (
         in_report_parameter_id IN NUMBER
         in_which            IN VARCHAR2 DEFAULT 'SELECT'
    )
    RETURN VARCHAR2
    IS
         end_text        VARCHAR2 (50)   := '';
    
         my_class_perc_text VARCHAR2(10000) := '';
    
         CURSOR class_perc_text ( c_1_text     VARCHAR2 (50)
                                 , c_2_text     VARCHAR2 (50)
                          )
         IS     SELECT  c_1_text || report_parameters.report_parameter_value
                               || c_3_text
                               || report_parameters.report_parameter_value
                               || '" '
         FROM    report_parameters
         WHERE     report_parameters.report_parameter_id     = in_report_parameter_id
         AND     report_parameters.report_parameter_group  = 'CLASS'
         AND     report_parameters.report_parameter_name   = 'CLASS'
         GROUP BY
                 report_parameters.report_parameter_value
         ORDER BY
                 CAST(report_parameters.report_parameter_value AS NUMBER);
    BEGIN
         IF  UPPER (in_which) = 'SUM'
         THEN
              OPEN class_perc_text ( 'SUM(NVL("Class '
                                  , '", 0)) "Class '
                             );
         ELSIF  UPPER (in_which) = 'PERC'
              OPEN class_perc_text ( 'ROUND((("Class '
                                  , '" / "Total") * 100), 2) "Class '
                             );
              end_text := ', DECODE("Total", -1, 0, 100) "Total" ';
         ELSE
              OPEN class_perc_text ( 'SUM(DECODE(bin_id, '
                                  , ', bin_value, 0)) "Class '
                             );
         END IF;
    
         LOOP
              FETCH class_perc_text INTO my_class_perc_value;
              EXIT WHEN class_perc_text%NOTFOUND;
    
              my_class_perc_text := my_class_perc_text || ', ' || my_class_perc_value;
         END LOOP;
    
         CLOSE class_perc_text;
         my_class_perc_text := my_class_perc_text || end_text;
    
         RETURN my_class_perc_text;
    END get_class_text;
    

    Note how you can have settings for a cursor, so that certain expressions used in the cursor must not be known when the cursor is declared: they can be given when the cursor is opened.

  • dynamic SQL for OPEN will not take the SQL string in the form of a string variable

    Hello

    I use "OPEN-for", not "EXECUTE IMMEDIATE" because I want to do multi lines request. However, 'OPEN-for' won't take a variable "strSQL' in the clause, it only took fixed ropes?

    create or replace function fnEnumSystemUser
    (
    LogonFilter nvarchar2,
    ...
    AdditionalWhereClause nvarchar2,
    OrderByClause nvarchar2
    )
    RETURN xxxxx.cursorType
    AS
    strSQL nvarchar2 (2000);

    FormatAdditionalWhereClause nvarchar2 (2000);
    FormatOrderByClause nvarchar2 (2000);

    SystemUserCursor xxxxx.cursorType;
    BEGIN

    If AdditionalWhereClause IS NULL THEN
    FormatAdditionalWhereClause: = ' ';
    ON THE OTHER
    FormatAdditionalWhereClause: = TRIM (AdditionalWhereClause);
    END IF;

    If OrderByClause IS NULL THEN
    FormatOrderByClause: = ' ';
    ON THE OTHER
    FormatOrderByClause: = TRIM (OrderByClause);
    END IF;

    strSQL: = 'select Id, FirstName, MiddleName, LastName, PrimaryEmail, PersonType, CreateDate, CreatedBy, LastUpdate, LastUpdateBy, connection, PasswdHash, IsSuspended, had left join SystemUser person on SystemUser.PersonId = Person.Id';
    -It won't work, just says "WARNING: compiled, but with compilation errors" when I tried to create the function
    Open SystemUserCursor for strSQL;

    -This is to call "ORA-01006: bind variable does not exist.
    Open SystemUserCursor
    ' select Id, FirstName, MiddleName, LastName, PrimaryEmail, PersonType, CreateDate, CreatedBy, LastUpdate, LastUpdateBy, connection, PasswdHash, IsSuspended, had left join SystemUser person on SystemUser.PersonId = Person.Id WHERE SystemUser.Logon like: x: y ' using LogonFilter, OrderByClause;

    -This failed also (on call, "ORA-00900: invalid SQL statement")
    Open SystemUserCursor
    ' select Id, FirstName, MiddleName, LastName, PrimaryEmail, PersonType, CreateDate, CreatedBy, LastUpdate, LastUpdateBy, connection, PasswdHash, IsSuspended, had left join SystemUser person on SystemUser.PersonId = Person.Id WHERE SystemUser.Logon like: x' | OrderByClause using LogonFilter;

    RETURN SystemUserCursor;
    END;

    That's how I invoked:
    declare
    Int NumItemsSelected;
    lstResult xxxxx.cursorType;

    TYPE SystemUserRecordType IS RECORD
    (
    ID numeric (19.0),.
    FirstName nvarchar2 (50).
    MiddleName nvarchar2 (50).
    LastName nvarchar2 (50).
    PrimaryEmail nvarchar2 (190),
    PersonType int,
    CreateDate timestamp,
    CreatedBy numeric (19.0),.
    LastUpdate timestamp,
    LastUpdateBy numeric (19.0),.

    Logon nvarchar2 (75).
    PasswdHash int,
    IsSuspended tank,
    Display timestamp
    );
    SystemUserRecordType oUser;
    Start

    lstResult: = fnEnumSystemUser (...) '%',... Person.PrimaryEmail like '% a %', "order by ASC Logon", 0, 10, NumItemsSelected);
    LOOP
    extract lstResult in oUser;
    When the output lstResult % notfound;
    dbms_output.put_line ('Id: ' | oUser.Id);
    END LOOP;
    end;

    I need the ability to add to the SQL string because ultimately say I need to join:
    1. ORDER BY section
    2 call a FUNCTION in WHERE Clause
    3 pagination and ROW_NUMBER() clause

    What can I do? Thank you!

    1. why you use NVARCHAR2 to the SQL string. Use VARCHAR2 or LONG.

    2. use

     tags to preserve formatting of your code.
    
    3. In the bind variable does not exist example it looks like you have one bind, :y, but are trying to bind two variables logonfilter and orderbyclause.
    
    4. In the third example, try logging the sql string in a table or dbms_output and running it in sql - you should get the same error and it might then be easier to diagnose.
    
    Cheers,
    Dominic                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
    
  • How to run a SQL string to a procedure of forms?

    Hello

    first the background. I have a Varchar2 column in a Table with a SQL string.
    Now I want to read this chain in forms and run the SQL statement - but I don't know how.

    This is the SQL string:
    Select the country from p_1 from countries where country_nr = p_2

    P_1 and p_2 are Variables in the procedure of forms.

    Most people forget that groups Records are excellent tools for dynamic queries like this. Search for Populate_group_with_query.

    Only you need to change your sql, it is not in the sentence, like this:

    Select the country as P_1
    country
    where country_nr = p_2
    and p_3 = p_3
    and p_4 = p_4

    Select name as P_1
    of the customer
    where customer_nr = p_2
    and country_nr = p_3
    and p_4 = p_4

    Your rec group would have a single column, P_1, where the data would be accessible after the query. Get_group_char_cell allows you to retrieve the value of P_1.  I don't know, but you should not "AS P_1" expression in the select, as long as you have created the record group initially with a specific column name.

    The only thing that is not clear, however, is your use of variables in the where clause. You can either hardcode the literal values in the SQL string, like this:

    'where country_nr = ''123'' and...'

    Note as you build your text string SQL, you use two apostrophes instead of one, given that pl/sql uses the apostrophe of beginning and end of the string.

    Or alternatively, you can use bind variables for your where the variables paragraph as follows:

    where customer_nr = :Parameter.var_2
    and country_nr = :Parameter.var_3

    Then, you can move a value in the: parameter values before completing the Group rec. You can use elements in a block of control rather than the settings, too.

    Here is an example of using dynamic query in a record group: Re: dynamic query

  • a single comparison string and get pure SQL strings,

    Hi all

    These are two strings

    S1 = "HAS, B, C, D, F;
    S2 ='C, F, H, B, A, K';

    output should be like unique string values.

    S3 = A, B, C, D, F, H, K;


    How to get this in pure sql...

    Thanks in advance,

    Roots

    Hello

    In a relational database, each column of each row needs to store a value, not a repleating group of values, such as a delimited list. It is so basic to the design of database it is called "First Normal Form." You don't have to follow the rules like that, but if you do not, your code will be complicated, inefficient and prone to errors. It might be better to re-design your application so that each value was on a separate line.

    If you can't do that, then you can start by dividing your lists of delimitd in separate lines. Then you can easily fond distinct values and use any technique of chain aggregation to combine the results into an output line.
    Here's a way to do this:

    WITH     got_params     AS
    (
         SELECT     'A,B,C,D,F' AS str, 1 AS str_id     FROM dual     UNION ALL
         SELECT     'C,F,H,B,A,K',          2            FROM dual
    )
    ,     got_part_cnt     AS
    (
         SELECT     str
         ,     1 + LENGTH (str)
                - LENGTH (REPLACE (str, ','))     AS part_cnt
         FROM    got_params
    )
    ,     cntr          AS
    (
         SELECT     LEVEL     AS n
         FROM     (
                  SELECT  MAX (part_cnt)     AS max_part_cnt
                  FROM    got_part_cnt
              )
         CONNECT BY     LEVEL     <= max_part_cnt
    )
    ,     got_substr     AS
    (
         SELECT DISTINCT
                REGEXP_SUBSTR ( p.str
                               , '[^,]+'
                        , 1
                        , c.n
                        )          AS sub_str
         FROM    got_part_cnt p
         JOIN     cntr          c  ON     c.n     <= p.part_cnt
    )
    ,     got_r_num     AS
    (
         SELECT     sub_str
         ,     ROW_NUMBER () OVER (ORDER BY  sub_str)     AS r_num
         ,     ROWNUM                                        AS r
         FROM     got_substr
    )
    SELECT     MIN ( SUBSTR ( SYS_CONNECT_BY_PATH (sub_str, ',')
                          , 2
                          )
             )          AS unique_sub_strs
    FROM    got_r_num
    WHERE     CONNECT_BY_ISLEAF     = 1
    -- START WITH     r_num     = 1
    CONNECT BY     r_num     = 1 + PRIOR r_num
    ;
    

    It works in 10.2.0.2.0 Oracle Express Edition, which is the only database, can I use it right now. For the main query, you should be able to say:

    SELECT     SUBSTR ( SYS_CONNECT_BY_PATH (sub_str, ',')
                , 2
                )     AS unique_sub_strs
    FROM    got_r_num
    WHERE     CONNECT_BY_ISLEAF     = 1
    START WITH     r_num     = 1
    CONNECT BY     r_num     = 1 + PRIOR r_num
    ;
    

    but, when I try it on my database, I get only "A, B" as output. CONNECT is very buggy in Oracle 10.2; If you have Oracle 10.1, simplest form might work.

    The above query can be shortened, some, but I wrote it this way to make it easier to understand.
    For example, you can combine got_sub_str and got_r_num subqueries. If you do so, substitute DENSE_RANK, ROW_NUMBER.

    This does not imply that the sub-qtrings are all 1 characters long. If they are, the query can be simplified.

    For more information on aggregation of chain, see
    http://www.Oracle-base.com/articles/10G/StringAggregationTechniques.php

  • CAN string comparison to see if I have the right one.

    I am writing a program to test a product that we produce using CAN.  How would I go see if I have a CAN message string to know that our alarm is turned on, on the product?  Is there a way to compare channels incomming and pass it some Boolean value when it does?  Thank you, Fred

    Hi Fred420,

    You can use the simple comparison function to compare two strings. If you have a list of channels, then you can store them in a table and use the search function of table 1 d. Two find a portion of a string in another string, you can use the search and replace function.

    It will be useful.

    Mike

  • How to create a connection for Toolkit CVI/SQL string when connecting to SQL Server 2008

    I tried to connect to my database of MS SQL Server 2008 for two days using the CVI/SQL Toolbox with no luck.  I use the function of connection BD and I tried a lot of different formats for the connection string with no luck.  I get an error "SQL Server doesn't exist or the access denied" after a long pause, trying to connect.  Anyone know what's the right format for this string?  I even setup of SQL Server on my local machine and I still not able to get the right format for the connection string.

    -Tom

    I have successfully connected to the database, I thank you all for your help.  It was a combination of errors of syntax and configurations that had to be changed.

  • Problem with string comparison

    I have a web service that I use two compares two strings, one from the service web xml of my application.

    XML retrieves a string when I compare it like this

    If (xmlVersion == 'true') {}

    }

    It never enter the if condition when I print the value I get from the service I think like this (real).

    So, what's the problem here?

    The way you wrote the comparison. you simply compare the addresses of the two strings.

    Try this instead:

    xmlVersion.equals ("true").

    In fact, you might want to consider getting these out to the back to avoid would be Null Pointer Exceptions, like this:

    If (true".equals (xmlVersion)) {" "}

    }

  • Parse the JSON using PL/SQL string

    I created a script that reads data from the Mobile App DB (which is based on MongoDB) of Oracle SQL Developer. The result is the string JSON stored in l_response_text VARCHAR2 (32767);

    The string has the format such as:


    [{"Postcode":"47100","OutletCode":"128039251","MobileNumber":"0123071303","_createdAt":"2014-11-10 06:12:49.837","_updatedAt":"2014-11-10 06:12:49.837"}, {"Postcode":"32100","OutletCode":"118034251", ..... ]
    
    
    
    
    

    However, I need to analyze this l_response_text such that each table will in his column in a table called appery_test. appery_test table has the same number of columns pairs JSON and in the same order (e.g. name of the first column is 'postal Code')

    I searched and I found most of the results on the analysis of the Oracle in JSON table and not the other way around. I found, however, that link which is somewhat similar to my problem. However, the library suggested in the answer doesn't have an example on how to use it to insert JSON into conventional table using PL/SQL.

    N.B.: I use g 11 and not 12 c. If the functions built by are not available for me.

    Thank you very much

    Sorry, I am a novice in this area too.

    However, it worked for me:

    declare

    l_list json_list;

    l_data CLOB;

    Code postal clob;

    l_val json_value;

    Start

    -json data recovery

    Select the data in l_data from jsons where id = 1;

    l_list: = json_list (l_data);

    I'm looping 1.l_list.count

    l_val: = json_ext.get_json_value (json (l_list.get (i)), 'Postcode');

    DBMS_LOB.CREATETEMPORARY (zip, true, 2);

    json_value.get_string (l_val, postal code);

    -Put some things

    dbms_output.put_line (DBMS_LOB. GetLength (Postcode));

    dbms_output.put_line (dbms_lob.substr (postal code, 20, 1));

    DBMS_LOB.freeTemporary (Postcode);

    end loop;

    end;

    47328

    9J / / 4AAQSkZJRgABAQAA

    Added dbms_lob.freetemporary (postcode);

  • SQL string

    Hello world

    I have a column in a table that contains data like this:
    BK704/123
    896/00123/456
    765/098/0056
    0786/342
    511/3/234
    76/00234
    908/786/112
    897/34/200/234
    JB56/3/765
    I have two requests to the above topic:
    one) writing SQL for sort the data above based on the latest figures i.e. digits after the last ' / ' such as when the latest figures are equal, the line with the single ' / ' must precede the line with two characters "/" and so on.
    (b) write a SQL to select lines with characters "/" 2 or more.

    What options are available for the above?

    You want to sort as strings? If so:

    with t as (
               select 'BK704/123' str from dual union all
               select '896/00123/456' from dual union all
               select '765/098/0056' from dual union all
               select '0786/342' from dual union all
               select '511/3/234' from dual union all
               select '76/00234' from dual union all
               select '908/786/112' from dual union all
               select '897/34/200/234' from dual union all
               select 'JB56/3/765' from dual
              )
    select  str
      from  t
      order by substr(str,instr(str,'/',-1) + 1),
               regexp_replace(str,'[^/]') nulls first
    /
    
    STR
    --------------
    76/00234
    765/098/0056
    908/786/112
    BK704/123
    511/3/234
    897/34/200/234
    0786/342
    896/00123/456
    JB56/3/765
    
    9 rows selected.
    
    SQL> 
    

    If all the data between slashes is digital and you want to sort as such:

    with t as (
               select 'BK704/123' str from dual union all
               select '896/00123/456' from dual union all
               select '765/098/0056' from dual union all
               select '0786/342' from dual union all
               select '511/3/234' from dual union all
               select '76/00234' from dual union all
               select '908/786/112' from dual union all
               select '897/34/200/234' from dual union all
               select 'JB56/3/765' from dual
              )
    select  str
      from  t
      order by to_number(substr(str,instr(str,'/',-1) + 1)),
               regexp_replace(str,'[^/]') nulls first
    /
    
    STR
    --------------
    765/098/0056
    908/786/112
    BK704/123
    76/00234
    511/3/234
    897/34/200/234
    0786/342
    896/00123/456
    JB56/3/765
    
    9 rows selected.
    
    SQL> 
    

    Second task:

    with t as (
               select 'BK704/123' str from dual union all
               select '896/00123/456' from dual union all
               select '765/098/0056' from dual union all
               select '0786/342' from dual union all
               select '511/3/234' from dual union all
               select '76/00234' from dual union all
               select '908/786/112' from dual union all
               select '897/34/200/234' from dual union all
               select 'JB56/3/765' from dual
              )
    select  str
      from  t
      where length(str) - nvl(length(replace(str,'/')),0) >= 2
    /
    
    STR
    --------------
    896/00123/456
    765/098/0056
    511/3/234
    908/786/112
    897/34/200/234
    JB56/3/765
    
    6 rows selected.
    
    SQL> 
    

    And for 11g:

    with t as (
               select 'BK704/123' str from dual union all
               select '896/00123/456' from dual union all
               select '765/098/0056' from dual union all
               select '0786/342' from dual union all
               select '511/3/234' from dual union all
               select '76/00234' from dual union all
               select '908/786/112' from dual union all
               select '897/34/200/234' from dual union all
               select 'JB56/3/765' from dual
              )
    select  str
      from  t
      where regexp_count(str,'/') >= 2
    /
    
    STR
    --------------
    896/00123/456
    765/098/0056
    511/3/234
    908/786/112
    897/34/200/234
    JB56/3/765
    
    6 rows selected.
    
    SQL> 
    

    SY.

  • String comparison between columns in different tables

    Hi all

    I have two tables. Table A and table B with Column3 column Column1 respectively I would search for lines in the Table B Column3 containing strings that exist in table Column1 has.

    For example,.

    Table A table B
    < here >
    Column1 Column3
    < here >
    Vol01/net/ddrr-pp01-ts001/flight/vol03
    vol02 \\ddrr-xx01-ts001\yy123-ds02
    vol03/net/ddrr-zz01-ts001/flight/vol01/4555/xxx
    XXX01 \\ddrr-pp01-ps001\vol01\yyyy\
    xx0333/net/ddrr-pp01-ds001/flight/vol01/xxx/77777
    / net/ddrr-pp00-ts001/flight/vol02 yy123-ds02

    I tried to play with substr but have not found it is repeating until I wanted to do... with something like this

    Select a.column1, b.column3 from tableA, tableB b where a.column1 = substr (b.column3, 5, max (length (a.column1)))

    Any help to guide me in the right direction will be greatly appreciated.

    Thank you.

    Or we can use the combination of SUBSTR and INSTR REGEXP_LIKE:

    with a as (
               select 'vol01' column1 from dual union all
               select 'vol02' from dual union all
               select 'vol03' from dual union all
               select 'xxx01' from dual union all
               select 'xx0333' from dual union all
               select 'yy123[ds02' from dual
              ),
         b as (
               select '/net/ddrr-pp01-ts001/vol/vol03' column3 from dual union all
               select '/net/ddrr-pp01-ts001/vol032/123' from dual union all
               select '\\ddrr-xx01-ts001\yy123[ds02' from dual union all
               select '/net/ddrr-zz01-ts001/vol/vol01/4555/xxx' from dual union all
               select '\\ddrr-pp01-ps001\vol01\yyyy\' from dual union all
               select '/net/ddrr-pp01-ds001/vol/vol01/xxx/77777' from dual union all
               select '/net/ddrr-pp00-ts001/vol/vol02' from dual
              ),
    -- end of on-the-fly data sample
         c as (
               select  column1,
                       column3,
                       instr(column3,column1) position
                 from  a,
                       b
                 where instr(column3,column1) > 0
              )
    select  column1,
            column3
      from  c
      where regexp_like(substr('!' || column3,position),'\W')
        and regexp_like(substr(column3 || '!',position + length(column1)),'\W')
    /
    
    COLUMN1    COLUMN3
    ---------- ----------------------------------------
    vol01      /net/ddrr-zz01-ts001/vol/vol01/4555/xxx
    vol01      \\ddrr-pp01-ps001\vol01\yyyy\
    vol01      /net/ddrr-pp01-ds001/vol/vol01/xxx/77777
    vol02      /net/ddrr-pp00-ts001/vol/vol02
    vol03      /net/ddrr-pp01-ts001/vol/vol03
    vol03      /net/ddrr-pp01-ts001/vol032/123
    yy123[ds02 \\ddrr-xx01-ts001\yy123[ds02
    
    7 rows selected.
    
    SQL> 
    

    SY.

  • build the sql string

    I build my sql in java string and then pass it to Hibernate query

    I add several conditions based on user research

    This is a simple condition 'and' I create and add
              if(StringUtils.isNotBlank(stgAuditGeneral.getAuditeename())){
                   filter=" and lower(AUDITEE_NAME) like '%?%' ";
                   sqlqQuery=sqlqQuery+StringUtils.replace(filter, param, StringUtils.lowerCase(stgAuditGeneral.getAuditeename()));
              }
    Assume that the user has entered
     lourt's 
    generated SQL will be
    and lower(AUDITEE_NAME) like '%lourt's%'  and   ......
    If the user enters the quotes for stgAuditGeneral.getAuditeename () my String sql will be curreprted and I get sql exception

    Please suggest me how to avoid this problem

    user11138293 wrote:
    I'm using hibernate,
    I pass the query parameter is the request that I create, please tell me in this case can I use preparedstatement way settings?

    Hibernate provides similar functionality. Review the class SQLQuery (createSQLQuery returns). It has methods like setString(), setInteger() that allow you to replace the two positional parameters (as? 1? 2) or of named parameters (as: param1,: param2) in the query.
    There is absolutely no reason why this day and age everyone should be concatenating queries SQL and parameters set as strings.

Maybe you are looking for