Sql query related to beaking the string based on string postion

Hi,
I have coloumn in this way
city_state
texas tx
sanantanio tx
newyork ny
newjersy nj
newyork
newjersy
landon 1000
I want to get the last characters after the space from the string(eg: texas tx) only tx, that means i want to only break the strings that have space in the 3rd position when counting the string from back. the others records that do not match as above stated should decoded as 'unknown'
(eg 'landon 1000' decode as unknown or 'newyork' decode to unknown )
can anyone please help out on this query.
thanks,
Ram

with t as (
           select 'texas tx' city_state from dual union all
           select 'sanantanio tx' from dual union all
           select 'newyork ny' from dual union all
           select 'newjersy nj' from dual union all
           select 'newyork ' from dual union all
           select 'newjersy' from dual union all
           select 'landon 1000' from dual
select  city_state,
        case
          when regexp_like(city_state,' ..$') then substr(city_state,-2)
          else 'unknown'
        end state
  from  t
CITY_STATE    STATE
texas tx      tx
sanantanio tx tx
newyork ny    ny
newjersy nj   nj
newyork       unknown
newjersy      unknown
landon 1000   unknown
7 rows selected.
SQL> SY.

Similar Messages

  • Sql query to identify all the responsibilities attached to a form

    (oracle - apps) Can anyone help me by giving a sql query to identify all the responsibilities attached to a form and corresponding menu should not be in the menu exclusion.
    Thanks in advance
    Venki

    Bump

  • SQL query  which return all the NET SERVICES which are avaiable in tnsname

    hi all
    how to write a sql query which return all the net services which are avaiable in tnsname.ora
    Regards
    s

    Also, tnsnames.ora is stored on the client, and not necessarily on the server; it's possible (and quite likely) that the name I use for a database in my tnsnames.ora could be different from the name you use for the same database; conversely we might use the same name for two different databases.
    Regards Nigel

  • SQL Query involved to Generate the reports

    Hi,
    I have created Vendor report which internally refers two tables from the vendor and store table (Both the tables are not directly Joined each other)
    i want to see the SQL Query involved to generate the report.
    where can i see that?
    Regards,
    Prasanthi

    in nqquery.log file:
    10g -> $BI_ORACLE_HOME/server/Log
    11g -> $ORACLE_INSTANCE/diagnostics/logs/OracleBIServerComponent/coreapplication_obis1

  • OTL I am trying to wright a SQL query that will return the date the timesheet was submitted and date/time it was approved, can anyone guide me on this?

    Hi
    I am trying to wright a SQL query that will return the date the timesheet was submitted and date/time it was approved, can anyone guide me on this?
    I basically need person name who submitted, date - time it was submitted for approval, then the person who approved it and the date - time that it was approved
    Thanks
    Ruby

    Ruby,
    you can start with HXC_TIMECARD_SUMMARY table for submitter detail. But for approver details, i think you need WF tables to get the data for item type HXCEMP.

  • SQL Query of an OWB map (row based)

    If I trace a session, execute an OWB map (row based), will the trace file contain the actual SQL query ?
    The problem with me is that when I am executing this row -based OWB map, it is throwing me an error CursorFetchMapTerminationRTV20007 BUT ( plus taking a long time) when I am taking out the intermediate SQL insert query,it is working fine ( and also within a very short period of time)
    Execution status = COMPLETE
    message text = ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    message text = CursorFetchMapTerminationRTV20007
    No. task errors = 0
    No. task warnings = 2
    No. errors = 1
    Since this OWB map (Truncate Insert)  is row based hence I cannot cannot get the back end query from the OWB generated pl/sql package so wondering if I trace the session, check the trace file, may be I will able to see the exact SQL query generated. But wanted to confirm the same.

    Yes, the actual SQL run in the session will be in the trace file.

  • SQL query to see what the db/schema is doing

    My apologies in advance as I am sure this has been covered. However, my google foo is failing me. :(
    Oracle 11g on Centos 5
    I am running a script against the database from my local pc through command prompt. I am wanting to run a query against the db to see what part of the script it is running and if it's possible I would like to be able to see if it is doing read / writes. Similar to an onstat on informix.

    Welcome to the forum!
    >
    I am running a script against the database from my local pc through command prompt. I am wanting to run a query against the db to see what part of the script it is running and if it's possible I would like to be able to see if it is doing read / writes. Similar to an onstat on informix.
    >
    Oracle has no equivalent to onstat - http://www.oninit.com/onstat/
    Oracle also has no knowledge of your 'script' contents.
    As SB mentioned you can get a list of sessions and their identifiers. Then you can query the V$SESSION_LONGOPS system view to get information about long running operations.
    See V$SESSION_LONGOPS in the Database Reference. The same doc (see index) has information about V$SESSION and V$SQL
    http://docs.oracle.com/cd/B19306_01/server.102/b14237/dynviews_2092.htm#REFRN30227
    >
    V$SESSION_LONGOPS
    This view displays the status of various operations that run for longer than 6 seconds (in absolute time). These operations currently include many backup and recovery functions, statistics gathering, and query execution, and more operations are added for every Oracle release.
    To monitor query execution progress, you must be using the cost-based optimizer and you must:
    •Set the TIMED_STATISTICS or SQL_TRACE parameter to true
    •Gather statistics for your objects with the ANALYZE statement or the DBMS_STATS package
    You can add information to this view about application-specific long-running operations by using the DBMS_APPLICATION_INFO.SET_SESSION_LONGOPS procedure.
    >
    If you provide more information about what commands are in your script, what the script does and what information you are trying to obtain maybe we can be of more help.

  • Sql query extremely slow in the new linux environment , memory issues?

    We just migrated to a new dev environment in Linux REDHAT5, and now the query is very slow, and I used the TOAD to run the query, it took like 700 msecond to finish, however from any server connection, the sql query takes hours to finish.
    I checked toad monitor, it said need to increase db_buffer_cache and shared pool too small.
    Also three red alert from toad is:
    1. Library Cache get hit ratio: Dynamic or unsharable sql
    2. Chained fetch ratio: PCT free too low for a table
    3. parse to execute ratio: HIgh parse to execute ratio.
    App team said it ran real quick in the old AIX system, however I ran it in old system, and monitored in the toad, it gave me all same 5 red alerts in old system, and it did provide query results a lot quicker though.
    Here is the parameters in the old system (11gr1 on AIX):
    SQL> show parameter target
    NAME TYPE VALUE
    archive_lag_target integer 0
    db_flashback_retention_target integer 1440
    fast_start_io_target integer 0
    fast_start_mttr_target integer 0
    memory_max_target big integer 0
    memory_target big integer 0
    pga_aggregate_target big integer 278928K
    sga_target big integer 0
    SQL> show parameter shared
    NAME TYPE VALUE
    hi_shared_memory_address integer 0
    max_shared_servers integer
    shared_memory_address integer 0
    shared_pool_reserved_size big integer 31876710
    shared_pool_size big integer 608M
    shared_server_sessions integer
    shared_servers integer 0
    SQL> show parameter db_buffer
    SQL> show parameter buffer
    NAME TYPE VALUE
    buffer_pool_keep string
    buffer_pool_recycle string
    db_block_buffers integer 0
    log_buffer integer 2048000
    use_indirect_data_buffers boolean FALSE
    SQL>
    In new 11gr2 Linux REDHAT parameter:
    NAME TYPE VALUE
    archive_lag_target integer 0
    db_flashback_retention_target integer 1440
    fast_start_io_target integer 0
    fast_start_mttr_target integer 0
    memory_max_target big integer 2512M
    memory_target big integer 2512M
    parallel_servers_target integer 192
    pga_aggregate_target big integer 0
    sga_target big integer 1648M
    SQL> show parameter shared
    NAME TYPE VALUE
    hi_shared_memory_address integer 0
    max_shared_servers integer
    shared_memory_address integer 0
    shared_pool_reserved_size big integer 28M
    shared_pool_size big integer 0
    shared_server_sessions integer
    shared_servers integer 1
    SQL> show parameter buffer
    NAME TYPE VALUE
    buffer_pool_keep string
    buffer_pool_recycle string
    db_block_buffers integer 0
    log_buffer integer 18857984
    use_indirect_data_buffers boolean FALSE
    SQL>
    Please help. Thanks in advance.

    Duplicate question. Originally posted in sql query slow in new redhat enviornment
    Please post in just one forum.

  • How to use sql:query/ tag to retrive the system date?

    hi all,
    i want to know if i can use the <sql:query/> tag in jstl to get the database server time. please send me a code snippet to retrive n display the result. i'm new to jstl tags. please help.
    thank you,
    AM

    Check out the first hits: http://www.google.com/search?q=jstl+sql+tutorial+site:sun.com

  • Sql query to find out the space issues in not able to allocate next extent

    hi,
    i have oracel 11g on linux.
    my datafiles are autoextend off. i am looking for query to make sure the segments does not stop growing by reaching the maximum segment allocated or no free contigous space available in allocating new extent,.
    i need to know periodically the owner,object_name and object type (table or index) which are suffocating for space.
    any ad-hoc sql query exists?
    thanks in advance.

    Connect as sysdba and try..
    To list all objects >100M in size.
    SQL> select owner, segment_type, segment_name, sum(bytes)/(1024*1021) from dba_segments
    group by owner, segment_type, segment_name
    having sum(bytes)/(1024*1021) > 100
    For tablespaces ..
    select tablespace_name, sum(bytes) tablespace_size
    from dba_data_files
    group by tablespace_name
    union all
    select tablespace_name, sum(bytes) tablespace_size
    from dba_temp_files
    group by tablespace_name
    order by tablespace_name

  • Looking for a SQL query to get all the possible Alert Messages from the Rules in a Management Pack

    For reporting, I'm looking to get a SQL query of all the possible Alert Messages for Rules configured in a Management Pack (not necessarily the ones that have thrown alerts).  I can do this for Monitors, but not for Rules. 
    The configured alert messages for the Management Pack Monitors
    go like this:  ManagementPack > MonitorView> RuleModule > RuleModule.Alert Message > Localized Text
    The configured alert messages for the Management Pack Rules
    should go something like this, but there is a missing link:  ManagementPack > RuleView > RuleModule > ? Missing Link ? > Localized Text
    The Rules are tied to the Module, but I don't see a connection from the RulesModule to the Alert Message that I see in the LocalizedText. The Rule names do not always equal the Alert name. 
    Can someone provide the missing link?

    Hi,
    please try below powershell code to find the corresponding management pack for specific alert:
    $Alert = get-scomalert | where {$_.Name -like 'Agent Proxy Not Enabled*'} | select -first 1
    If ($alert.IsMonitorAlert -eq "True") {
    write-host "Ths is a monitor-generated alert"
    get-scommonitor -ID $Alert.MonitoringRuleID | select Enabled, DisplayName, ManagementPack
    else
    write-host "This is a rule-generated alert"
    get-scomrule -ID $Alert.MonitoringRuleID | select Enabled, DisplayName, ManagementPack
    In addition, please also refer to the below link:
    http://blogs.technet.com/b/mazenahmed/archive/2011/12/02/using-powershell-to-map-opsmgr-active-alert-to-its-corresponding-rule-monitor-and-management-pack-name.aspx
    Regards,
    Yan Li
    Regards, Yan Li

  • SQL query optimization by changinf the WHERE clause

    Hi all,
    I need to know about the SQL query performance improvement by changing the WHERE clause. Consider a query :
    select * from student where country ='India' and age = 20
    Say, country = 'India' filters 100000 records and age = 20 filters 2000 records if given one by one. Now can anyone tell if the performance of the query can be changed by changing the query like this :
    select * from student where age = 20 and country ='India'
    as first where clause will give 2000 results and next filter will be applicable on only 2000 rows. While in the former query first where clause would give 100000 rows and seconde filter, hence, would be applicable on 100000 rows???
    Kindly explain.
    Thanks in advance.
    Abhideep

    in general the order of the where condition should not be important. However there are a few exeptions where sometimes it might play a role. Sometimes this is called order of filter conditions. Among others it depends on RBO or CBO used, Oracle Version, Indexes on the columns, statistic information on the table and the columns, CPU statistics in place etc.
    If you want to make this query fast and you know that the age column has much better selectivity then you can simply put an index on the age column. An index on the country column is probably not useful at all, since to little different values are in this column. If you are already in 11g I would suggest to use a composite index on both columns with the more selective in first position.
    Edited by: Sven W. on Nov 17, 2008 2:23 PM
    Edited by: Sven W. on Nov 17, 2008 2:24 PM

  • SQL Query to return all the dependent objects

    Hi,
    I have a question.
    Suppose I am creating a table with a join on 10 other tables, views etc..
    And there are nested sub-queries in the CREATE statement.
    How can I get the list of all the dependent objects for that table without counting them manually.
    I know, we can right click the table/view name and check the dependent objects in Toad or SQL Developer.
    But, I want to know the SQL query for getting that information.
    Thanks
    Rajiv

    well there is no way oracle would know what query was used when the table was created.
    But here is one intuitive trick:
    Step 1: Create a procedure that will have a cursor declared on the query you want to know what tables/views are used.
    Step 2: Check USER_DEPENDENCIES to see what objects this procedure depends on
    Let say you want to create TEST_A table using the following statement:
    create table test_a
    as
    select *
    from scott.emp,
         scott.dept;
      1  create or replace procedure test_temp
      2  as
      3  cursor test_cur is
      4             select *
      5             from scott.emp,
      6                  scott.dept;
      7  begin
      8     null;
      9* end;
    SQL> /
    Procedure created.
    SQL> show errors
    No errors.
    SQL> desc user_dependencies
    Name                                      Null?    Type
    NAME                                      NOT NULL VARCHAR2(30)
    TYPE                                               VARCHAR2(17)
    REFERENCED_OWNER                                   VARCHAR2(30)
    REFERENCED_NAME                                    VARCHAR2(64)
    REFERENCED_TYPE                                    VARCHAR2(17)
    REFERENCED_LINK_NAME                               VARCHAR2(128)
    SCHEMAID                                           NUMBER
    DEPENDENCY_TYPE                                    VARCHAR2(4)
    SQL> select referenced_owner, referenced_name, referenced_type
      2  from user_dependencies
      3  where name='TEST_TEMP' and referenced_owner<>'SYS';
    REFERENCED_OWNER
    REFERENCED_NAME
    REFERENCED_TYPE
    SCOTT
    DEPT
    TABLE
    SCOTT
    EMP
    TABLE
    SQL>
    SQL> drop procedure test_temp;
    Procedure dropped.
    SQL>Message was edited by:
    tekicora
    Message was edited by:
    tekicora

  • Sql query hangs close to the end

    Hi:
    I am on 10.2.0.3.
    My rather simple query hangs for a few minutes close to the end. It's supposed to return 288 rows and it immediately returns 285, then hangs for 4-5 min, than returns the remaining 3 rows. Kind of similar behavior to using "First_rows" hint - which I'm not using...
    The table has about 100,000 rows.
    Some relevant info is below.
    Any ides appreciated.
    TIA
    PLAN_TABLE_OUTPUT
    Plan hash value: 2481764356
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 30 | 3 (0)| 00:00:01 |
    |* 1 | INDEX RANGE SCAN| PSACOMBO_DATA_TBL | 1 | 30 | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    1 - access("SETID"='GLOBL' AND "PROCESS_GROUP"='100ACDTPRJ' AND
    "COMBINATION"='100ACDTPRJ' AND "VALID_CODE"='V')
    optimizer_dynamic_sampling integer 6
    optimizer_features_enable string 10.2.0.3
    optimizer_index_caching integer 25
    optimizer_index_cost_adj integer 75
    optimizer_mode string ALL_ROWS
    optimizer_secure_view_merging boolean TRUE
    unnestsubquery boolean FALSE

    You said the query is supposed to return 288 rows, but from the explain plan, Oracle "see" only 1 row to be returned. Are the stats up-to-date ? What's the actual query ?
    Please, on the forum side, use tags before and after your code to keep it readable (preserve blanks and tabs).
    Nicolas.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Sql Query need to extract the Work Flow information from Hyperion Planning

    Can Any one give me the sql query to extract the Work flow from Hyperion Planning in 11.1.2.1.
    I can extract from the Hyperion Planning but it is not in required format again I need to do lot of formating. I need the information as per the flow structure is showing linke in one perticular planning unit in all coloumn format. Hence only sql query will help me to extract this kind of information. could any one provide the sql query to extract this kind of request.
    Thanks in Advance.
    Edited by: 987185 on Feb 9, 2013 10:57 PM

    If you have a look at the data models in - http://www.oracle.com/technetwork/middleware/bi-foundation/epm-data-models-11121-354684.zip
    There is the structure of the planning application tables, have a look at the HSP_PM_* tables
    Alternatively you can look at extracting the information using LCM.
    Cheers
    John
    http://john-goodwin.blogspot.com/

Maybe you are looking for

  • More on "maximum open cursors exceeded"

    It seems a lot of people have been seeing this error message, but reading through the posts on the topic hasn't given me any new insight on the problem. Here's an account of my particular situation: I am using the XSQL servlet, v.1.0.0.0 with the thi

  • Urgent.... Help Needed for Storing file in Application Server

    Hi All, I have a requirement where in I have to save a file in Application Server. File is of 141 Character Length, so there can be spaces left at the end. When I am downloading the file into Application Sever and then downloading the same file from

  • Flat file in bdc

    hi experts ? who will create the flat file in real time ? who ll run that bdc program in real time ? what is abaper role exactly involved in bdc ? only coding or some thing else ? or we have to run that program ?

  • Can i change color mode in keynote?

    Whenever I import pictures or logos to keynote, the colors turn out really skewed as from how they should look like. COuld someone please tell me what might be wrong and how I can fix that? I have tried several differnt options when I export files fr

  • How to show a Image (from shell, python or what ever)

    Hi guys An Application written in c#/mono takes up to 7 seconds to start. So i was asked to do a little splash screen for it. I coul'd not figure out how to do it from shell and i couldn't find the pygtk bindings installed, so i did it quick and dirt