Oracle

Oracle sql: filtering repeated rows that only differ by a tiny amount of time

做~自己de王妃 提交于 2021-01-28 02:41:34
问题 I have an Oracle table with event alarms, and due to a weird and unknown -to me- condition alarms get repeated sometimes so I was asked to create a service that will remove repeated alarms from that Oracle table. The condition to consider an alarm (a row in the table) as repeated is that there is another one with the same exact PKN_EVENTNAME and RECEIVEDDATE only differs from the previous one by a tiny amount of time (let's say 10 seconds for example -up or down-). What I'm trying to do first

Creating a spatial index on oracle

二次信任 提交于 2021-01-28 02:27:39
问题 I have a table 'floating_options', and I want to create a spatial index on a column 'area_geo' (which is a sdo_geometry column, with two rows of data that appear as expected when I select * from floating_options). I have used the following code but I am receiving the error below. I would be very grateful for any help! Thanks! CREATE INDEX area_idx ON floating_options(area_geo) INDEXTYPE IS MDSYS.SPATIAL_INDEX; Error report - SQL Error: ORA-29855: error occurred in the execution of

Java ResultSet.getString() for Date field displaying 00:00:00.0

走远了吗. 提交于 2021-01-28 00:00:45
问题 I am using a generic method to loop through and convert a ResultSet to a String array. I am wondering why does the Date column in Oracle db value come print out as 2015-01-09 00:00:00.0 while the date in the database shows 2015-01-09 ? Here is the code, the col type in Oracle is Date while(rs.next()) { String[] arr = new String[colCount]; for(int i = 1; i <= colCount; i++) { arr[i-1] = rs.getString(i); }//end for list.add(arr); }//end while So that is part 1 of the question, part 2 of the

How to generate rows for date range by key

你。 提交于 2021-01-27 23:12:50
问题 I'm having trouble with the following query: SELECT B.EMPLOYEE_NAME, A.START_DATE+(LEVEL-1) AS INDIVIDUAL_DAY, TO_CHAR(A.START_DATE,'MM/DD/YYYY') START_DATE, TO_CHAR(A.END_DATE,'MM/DD/YYYY') END_DATE FROM table1 A INNER JOIN table2 B ON A.EMPLOYEE_NAME = B.EMPLOYEE_NAME CONNECT BY LEVEL-1 <= (A.END_DATE-A.START_DATE); If there is only one record in table A then I get exactly what I'm looking for. However if there is more than one record then I get an excess amount of results. What I'm looking

Alternative to UNION clause

谁说胖子不能爱 提交于 2021-01-27 22:50:54
问题 I'm trying to teach myself and better understand alternative methods to a UNION and discover when I can use joins. As I'm playing with this I can't seem to get what I want without a UNION. Is it possible to write this in a single query? SELECT DISTINCT a.id FROM table1 a, table2 b WHERE a.id = b.id AND a.ind IS NULL AND b.year >= '2017' AND b.code IN ('01','02','03') AND b.flag NOT IN ('F','L') UNION SELECT DISTINCT a.id FROM table1 a, table3 c WHERE a.id = c.id AND a.ind IS NULL AND c.area =

How to implement Oracle count(distinct) over partition in Postgres

大兔子大兔子 提交于 2021-01-27 22:38:27
问题 Here is my sql sample in a select statement. Converting from oracle to postgres, need a simple way to re implement oracle count distinct over partition in postgres. , count(distinct on pm.mobseg_state) over (partition by pm.trans_id) as mob_segments_count , count(distinct on pm.country_reg_region_cd) over (partition by pm.trans_id) as countries_count 回答1: Postgres doesn't support count(distinct) directly. But you can implement it with a subquery: select . . ., sum( (seqnum_tm = 1)::int) as

Formatting INTERVAL DAY(0) TO SECOND(0)

蹲街弑〆低调 提交于 2021-01-27 21:46:06
问题 I have a few time fields that are INTERVAL DAY(0) TO SECOND(0) Datatypes to store various times of the day. Currently on normal retrieval, my fields display as such: +00 19:00:00.000000 How am I able to format this such that it displays as 19:00? 回答1: You want hours and minutes from an interval. If that interval cannot exceed 24 hours, then you can add the interval to a date without time part and then use TO_CHAR to get the formatted hours and minutes: select to_char(trunc(sysdate) +

Hierarchical Query - Counting records that belongs to Parent and Child Places

故事扮演 提交于 2021-01-27 19:33:39
问题 I have two tables PLACE and ADRESS. PLACE includes places like parent-child hierarcy. ADRESS includes adresses with PLACE_ID column. These tables as shown below; PLACE ID PARENT_ID NAME CONTINENT 11 null USA America 22 11 New York America 33 22 Manhattan America 44 null Brasil America 55 44 Rio America 66 null France Europe 77 66 Paris Europe 88 66 Nice Europe MEMBER ID PLACE_ID NAME ADRESS 1 22 .. .. 2 77 .. .. 3 33 .. .. 4 22 .. .. 5 55 .. .. 6 55 .. .. 7 88 .. .. 8 88 .. .. 9 88 .. .. 10

'Multi' method is not allowed when loading data to Oracle database with sqlalchemy

China☆狼群 提交于 2021-01-27 19:26:59
问题 I am using sqlalchemy and pandas to load dataframe to Oracle database. Since 'multi'method allows to upload in bulk, I choose that method. My pandas version is 1.0.1. However I got the error as following: The 'oracle' dialect with current database version settings does not support in-place multirow inserts. from sqlalchemy import create_engine oracle_connection_string = ( 'oracle+cx_oracle://{username}:{password}@' + cx_Oracle.makedsn('{hostname}', '{port}', service_name='{service_name}'))

Does an insert trigger need a commit statement

半腔热情 提交于 2021-01-27 19:11:30
问题 This is an simplification of actual scenario; where is see missing records on Table B. Say there are two db tables A ; B. There is an on insert trigger on Table A;which do an insert to Table B (but it doesn't have COMMIT;). If we open a db connection through JDBC connector; and do an insert on Table A; and commit it; What is the behavior of Trigger? Will it be automatically committed the insert statement on table B ? 回答1: Not only do triggers not need a COMMIT you can't put one in: a trigger