Oracle

Plsql best way to split string

心已入冬 提交于 2021-02-08 10:09:54
问题 What is the best way to extract words from a string? I already made something up because I found many ways and none of them looked 'simple'. Let's assume there is a procedure called 'change_opening_hours'. This procedure has a time-range string input called 'v_perioden'. This string looks like: '10:00-12:00' OR '10:00-12:00 14:00-16:00' OR '10:00-12:00 14:00-16:00 18:00-22:00' etc Now I already made something up myself to exstract every period of time from this input. v_perioden VARCHAR2(50)

Create all months list from a date column in ORACLE SQL

≡放荡痞女 提交于 2021-02-08 10:08:14
问题 CREATE TABLE dates( alldates date); INSERT INTO dates (alldates) VALUES ('1-May-2017'); INSERT INTO dates (alldates) VALUES ('1-Mar-2018'); I want to generate all months beginning between these two dates. I am very new to Oracle SQL. My solution is below, but it is not working properly. WITH t1(test) AS ( SELECT MIN(alldates) as test FROM dates UNION ALL SELECT ADD_MONTHS(test,1) as test FROM t1 WHERE t1.test<= (SELECT MAX(alldates) FROM date) ) SELECT * FROM t1 The result I want should look

Migrating trigger from Oracle 11g to Postgresql 8.4

我是研究僧i 提交于 2021-02-08 09:27:11
问题 My trigger in Oracle looks like this… CREATE OR REPLACE TRIGGER example$example BEFORE UPDATE OR DELETE ON example FOR EACH ROW BEGIN INSERT INTO example$ VALUES ( :old.key, :old.name, :old.describe seq.nextVal ); END; I thought I could simply translate to Postgresql with this… CREATE OR REPLACE TRIGGER example$example BEFORE UPDATE OR DELETE ON example FOR EACH ROW BEGIN INSERT INTO example$ VALUES ( OLD.key, OLD.name, OLD.describe, NEXTVAL('seq') ); END; I'm getting an error at the end of

Practical life examples of oracle explicit cursor use

心不动则不痛 提交于 2021-02-08 09:23:10
问题 I couldn't think of a practical situation to use explicit cursors in PL/SQL code. Can anybody please share some scenarios? Thanks! 回答1: If a cursor is used more than once in a program unit, an explicit cursor allows you to code the SQL once, which is good for maintenance. 回答2: There are two clear use cases for explicit cursors. The first is when we want to probe for the existence of a record and handle the outcome in the main flow of our code: open emp_cur (p_empno); fetch emp_cur into l_emp

timezone-dependant systimestamp and timestamp comparison on Oracle

爷,独闯天下 提交于 2021-02-08 08:34:20
问题 I've run into a weird situation. Could someone explain why comparison between timestamp and timestamp behaves as below (it depends on session timezone...). In addition outputed values are identical in all cases. It looks like timestamp inherits timezone from the session for comparison purposes, but for printing it does not? Queries: alter session set time_zone = '-6:0'; select cast(systimestamp as timestamp), systimestamp, case when cast(systimestamp as timestamp) < systimestamp then

Oracle SQL lead lag across different group

这一生的挚爱 提交于 2021-02-08 08:30:31
问题 Suppose I have the below table. They key is just concat P1, P2, P3. I want to compare between key for each day. for example, from day 1 to day2, abc is removed and abe, aby is added. P1 P2 P3 DAY KEY a b c 1 abc a b e 2 abe a b y 2 aby a b x 3 abx a b c 3 abc Expected result set: KEY OPERATION DAY abc ADD 1 abe ADD 2 aby ADD 2 abc REMOVE 2 abx ADD 3 abc ADD 3 abe REMOVE 3 aby REMOVE 3 And what if the day is not sequential. For example: P1 P2 P3 DAY KEY a b c 1 abc a b e 2 abe a b y 2 aby a b

Is the executeBatch() performed on Oracle is done in order?

懵懂的女人 提交于 2021-02-08 08:30:30
问题 This is more of a kind of theory question to understand how the executeBatch() request is handled by Oracle. Consider there are three insert statements (PreparedStatement) ,say statement 1, statement2 and statement 3 are added to execute as a batch using executeBatch() method and over Oracle. Will there be a chance that the execution of statement 2 to complete even before statement 1 completes? In other words, can the insert operation by statement 2 succeed before the insert performed by

ORA-00904: “from$_subquery$_014”.“column_name”: invalid identifier

别来无恙 提交于 2021-02-08 08:18:53
问题 After the migration of my oracle db im getting below error: ORA-00904: "from$_subquery$_014"."TRN_TERMINAL_SOFTWARE_VERSION": invalid identifier below is my query: SELECT * FROM ( SELECT SUM(trn_amt) AS amount, SUM(trn_count) AS COUNT , timetype AS period , seq , ROW_NUMBER() OVER (ORDER BY vw.seq DESC) AS RowNumber FROM YSD_STORE_FORWARD_V vw INNER JOIN store_dimension std ON vw.stm_id=std.std_id INNER JOIN card_type_dimension ctd ON vw.CTD_CARD_ABBV=ctd.CTD_CARD_ABBV INNER JOIN STPLDBTEMP

ORA-00904: “from$_subquery$_014”.“column_name”: invalid identifier

落爺英雄遲暮 提交于 2021-02-08 08:14:12
问题 After the migration of my oracle db im getting below error: ORA-00904: "from$_subquery$_014"."TRN_TERMINAL_SOFTWARE_VERSION": invalid identifier below is my query: SELECT * FROM ( SELECT SUM(trn_amt) AS amount, SUM(trn_count) AS COUNT , timetype AS period , seq , ROW_NUMBER() OVER (ORDER BY vw.seq DESC) AS RowNumber FROM YSD_STORE_FORWARD_V vw INNER JOIN store_dimension std ON vw.stm_id=std.std_id INNER JOIN card_type_dimension ctd ON vw.CTD_CARD_ABBV=ctd.CTD_CARD_ABBV INNER JOIN STPLDBTEMP

dynamic table name without using cursors

本秂侑毒 提交于 2021-02-08 07:41:05
问题 I want to use dynamic table name within a for loop. I understand that there are solutions to this problems by using cursors. But I was wondering if there is a solution without cursor as my current code has generic for loop (implicit cursors) and I wanted to know if I can retain it the same way without going for explicit cursors. What works for me right now is: BEGIN for itr in (select var1,var2,var3,var4 from schedule_table) loop --work using itr.var1, itr.var2, itr.var3, itr.var4 end loop