oracle11g

Pass comma separated number to IN clause in Stored Procedure

梦想与她 提交于 2019-12-12 04:53:33
问题 I have a stored procedure which takes a varchar parameter called P_LOCATIONS in Oracle. This locations parameter has location id's that are comma separated. In database locationId is a number. Following sql query throws an Invalid number when there are more than one locations. I understand that because of comma its not able to convert a varchar into a number. How can I achieve this? create or replace PROCEDURE GET_RAW_DATA ( P_LOCATIONS IN VARCHAR2, Results OUT SYS_REFCURSOR )AS BEGIN select

Dynamic Query for PIVOT In Clause

依然范特西╮ 提交于 2019-12-12 04:51:47
问题 This is in continuation of this thread I have the below query to have the value as heading using SELECT * FROM (SELECT prod_id, start_date AS dt, start_date, hours FROM prod_timings t) PIVOT (SUM (hours) FOR start_date IN (TO_DATE ('18-SEP-17', 'DD-MON-YY') AS wed, TO_DATE ('19-SEP-17', 'DD-MON-YY') AS thu)) ORDER BY prod_id, dt Can I use the below query to use inside the IN clause of PIVOT to have the dates dynamic? The idea is to have a dynamic query inside the IN clause to avoid hard

Union results from subselect

此生再无相见时 提交于 2019-12-12 04:50:09
问题 I have an SQL statement with following structure: f(string parameter)=select * from table(parameter) ... => results in some table with rows. f(string parameter) is used as shortcut for more complex sql subquery. table parameters: |---params----| param1 param2 param3 .... how to combine f() with the table parameters where f() will be called for each param in this table. My question refers to SQL statement itself. As result I expect f(param1) union all f(param2) union all f(param3) ... If

Maintaining the order by in union of two ordered by queries

为君一笑 提交于 2019-12-12 04:46:44
问题 I am trying to run the below query but looks like I am doing something wrong. (Just modified the sample query for clear understanding) SELECT name,total,rate FROM business b WHERE rate > 100 ORDER BY total DESC UNION SELECT name,total,rate FROM business b WHERE rate <= 100 ORDER BY rate ASC Now I want to union of these two queries and in the resultant output in first row the output should come from first query and then output from second query in the same sorted order however the single

Oracle/SQL: Split two inter-related lists into independent cohorts

倾然丶 夕夏残阳落幕 提交于 2019-12-12 04:46:12
问题 Say I have a table TB1, for the conditions defined, the list below is unique. The products and emails is Many-to-Many relationship. I am going to do a survey for the products consumers purchased. Product Email TV a@server.com Fridge a@server.com Fridge b@server.com TV c@server.com Cooler c@server.com The requirements are: Each product couldn't be assigned to 2 surveys. Each survey could have multiple products. All customers who have purchased this product should be in the same survey. Each

Hibernate @OneToOne References an Unknown Entity Error

和自甴很熟 提交于 2019-12-12 04:29:45
问题 I'm having a hard time finding the root cause of an error where my @OneToOne mapping isn't working and is returning a "references an unknown entity" exception. To start with I ensured that both classes are properly annotated with the @Entity tag. Also it is worth noting my Product.java class (which you will see below) worked fine and only encounters a problem when I try to attach a foreign key to my Project.java class referencing the Product.java class. Java Code for Project.java and Product

Index on join and where

随声附和 提交于 2019-12-12 04:26:18
问题 Given the next SQL statement: Select * from A join B on A.id1=B.id1 and A.id2=B.id2 where A.year=2016 and B.year=2016 and knowing table A is much smaller than table B , so I need the database first to access A table by year, then join, then filter B table by year, my question is: does it make sense to create an index over B like (id1,id2,year) for improve performance? Many thanks! 回答1: For this query: Select * from A join B on A.id1 = B.id1 and A.id2 = B.id2 where A.year = 2016 and B.year =

Logging stored procedure access in Oracle

随声附和 提交于 2019-12-12 04:16:32
问题 Is there an convenient way to log access to stored procedures from withing Oracle? I am a web developer and presently we are required to pass a variety of user info to many stored procedures so that those procedures can in turn call another procedure that logs access to the original stored procedure in a table. For example if I want to call a procedure called get_movie(id) that will return a row from the movie table based on id, I would have to do something like this get_movie(username,

Finding missing dates in a sequence

房东的猫 提交于 2019-12-12 04:10:41
问题 I have following table with ID and DATE ID DATE 123 7/1/2015 123 6/1/2015 123 5/1/2015 123 4/1/2015 123 9/1/2014 123 8/1/2014 123 7/1/2014 123 6/1/2014 456 11/1/2014 456 10/1/2014 456 9/1/2014 456 8/1/2014 456 5/1/2014 456 4/1/2014 456 3/1/2014 789 9/1/2014 789 8/1/2014 789 7/1/2014 789 6/1/2014 789 5/1/2014 789 4/1/2014 789 3/1/2014 In this table, I have three customer ids, 123, 456, 789 and date column which shows which month they worked. I want to find out which of the customers have gap

Oracle SQL first and last day of quarter of any year

随声附和 提交于 2019-12-12 04:05:31
问题 Is there any way i can calculate the first and last day of the three quarters in any year . 2012 , 2013 or 2014 SELECT ADD_MONTHS(TRUNC(SYSDATE, 'Q'), -3) AS First, TRUNC(SYSDATE, 'Q') - 1 AS Last FROM DUAL calculates the first quarter of current year. i want to calculate the first quarter of any year ? 回答1: You could do the following: with q(qtr) as( select add_months( DATE '2013-01-01' , (level-1)*3 ) from dual connect by level <= 4 ) select qtr as first_day , last_day(add_months(qtr, 2))