connect-by

Fast way to generate concatenated strings in Oracle

时间秒杀一切 提交于 2019-11-28 11:44:19
Don't we hate when evil coding comes back to haunt? Some time ago I needed to generate a string concatenating some fields for some more processing later. I thought it would be a good idea to do if straight in the query, and used SO's help to get it. It worked. For a while... The table got to big and now that trick (which I know is super inefficient) is not exactly viable. This what I'm doing: with my_tabe as ( select 'user1' as usrid, '1' as prodcode from dual union select 'user1' as usrid, '2' as prodcode from dual union select 'user1' as usrid, '3' as prodcode from dual union select 'user2'

What is the equivalent PostgreSQL syntax to Oracle's CONNECT BY … START WITH?

北城余情 提交于 2019-11-28 09:08:17
In Oracle , if I have a table defined as … CREATE TABLE taxonomy ( key NUMBER(11) NOT NULL CONSTRAINT taxPkey PRIMARY KEY, value VARCHAR2(255), taxHier NUMBER(11) ); ALTER TABLE taxonomy ADD CONSTRAINT taxTaxFkey FOREIGN KEY (taxHier) REFERENCES tax(key); With these values … key value taxHier 0 zero null 1 one 0 2 two 0 3 three 0 4 four 1 5 five 2 6 six 2 This query syntax … SELECT value FROM taxonomy CONNECT BY PRIOR key = taxHier START WITH key = 0; Will yield … zero one four two five six three How is this done in PostgreSQL ? Erwin Brandstetter Use a RECURSIVE CTE in Postgres: WITH

SQL Server Equivalent of Oracle 'CONNECT BY PRIOR', and 'ORDER SIBLINGS BY'

强颜欢笑 提交于 2019-11-28 07:04:42
I've got this Oracle code structure I'm trying to convert to SQL Server 2008 ( Note: I have used generic names, enclosed column names and table names within square brackets '[]', and done some formatting to make the code more readable) : SELECT [col#1], [col#2], [col#3], ..., [col#n], [LEVEL] FROM (SELECT [col#1], [col#2], [col#3], ..., [col#n] FROM [TABLE_1] WHERE ... ) CONNECT BY PRIOR [col#1] = [col#2] START WITH [col#2] IS NULL ORDER SIBLINGS BY [col#3] What is the SQL Server equivalent template of the above code? Specifically, I'm struggling with the LEVEL , and 'ORDER SIBLINGS BY' Oracle

CONNECT BY or hierarchical queries in RDBMS other than Oracle

情到浓时终转凉″ 提交于 2019-11-28 03:56:07
问题 Oracle ships with a very handy feature. You can create hierarchical queries (recursive behaviour) using the following clause: CONNECT BY [NOCYCLE] {condition [AND condition...]} [START WITH condition] As documented here: http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/queries003.htm I'm wondering, are there any other established RDBMS that support an equivalent or similar syntax? Or can recursive behaviour like this be generically simulated using regular SQL? A good example

Recursive query in Oracle

删除回忆录丶 提交于 2019-11-27 07:15:10
问题 I am kind of new to the more advanced topics of PLSQL, so hopefully someone can help me out. The problem: I have a table with messages sent between an admin and users. The table has a message_parent with FK to the same table message_id field: in case the field is populated, then it means that message was sent as a reply to a previous message. I need to select all the messages that are part of the same conversation and display them. Can this be done with a single query or do I need a procedure

Fast way to generate concatenated strings in Oracle

与世无争的帅哥 提交于 2019-11-27 06:25:35
问题 Don't we hate when evil coding comes back to haunt? Some time ago I needed to generate a string concatenating some fields for some more processing later. I thought it would be a good idea to do if straight in the query, and used SO's help to get it. It worked. For a while... The table got to big and now that trick (which I know is super inefficient) is not exactly viable. This what I'm doing: with my_tabe as ( select 'user1' as usrid, '1' as prodcode from dual union select 'user1' as usrid,

What is the equivalent PostgreSQL syntax to Oracle's CONNECT BY … START WITH?

爷,独闯天下 提交于 2019-11-27 02:39:13
问题 In Oracle , if I have a table defined as … CREATE TABLE taxonomy ( key NUMBER(11) NOT NULL CONSTRAINT taxPkey PRIMARY KEY, value VARCHAR2(255), taxHier NUMBER(11) ); ALTER TABLE taxonomy ADD CONSTRAINT taxTaxFkey FOREIGN KEY (taxHier) REFERENCES tax(key); With these values … key value taxHier 0 zero null 1 one 0 2 two 0 3 three 0 4 four 1 5 five 2 6 six 2 This query syntax … SELECT value FROM taxonomy CONNECT BY PRIOR key = taxHier START WITH key = 0; Will yield … zero one four two five six