Generation SQL line with connection by level
Hello
I'm looking for generate lines based on a quantity of part numbers. I have looked all around several techniques for the generation of the line, but have failed to address this problem. The current method, it seems pulls a permutation of all possible combinations, and the result is rising quickly to millions / billions of documents... which is not the answer. Someone out there who could help writing a query to do this?
What I try to achieve if a quantity of part 5, I want to display 5 Qty 1 documents. If the Qty 12, then 12 Qty 1 documents. So on and so forth.
Out Oracle 10.2.0.4 operation
Sample data:
drop table test;
create table test (part varchar2 (20), number of quantity);
Insert test values ('WIDGET', 12);
Insert test values ('FOO', 5);
Insert test values ('THING', 3);
Insert test values ("WAD", 8);
commit;
-This query does not work... I think it's getting all the possible permutations
-Select a part, 1
-to test
-connect by level < = Qty
-what I want to see...
Part Qty.
------ ----
WIDGET 1
WIDGET 1
WIDGET 1
WIDGET 1
WIDGET 1
WIDGET 1
WIDGET 1
WIDGET 1
WIDGET 1
WIDGET 1
WIDGET 1
WIDGET 1
FOO 1
FOO 1
FOO 1
FOO 1
FOO 1
THING 1
THING 1
THING 1
BUNDLE 1
BUNDLE 1
BUNDLE 1
BUNDLE 1
BUNDLE 1
BUNDLE 1
BUNDLE 1
BUNDLE 1
Hello
You want something like this:
SELECT part
Qty. 1
OF the test
CONNECT NOCYCLE LEVEL<=>=>
AND an EARLIER part = part
AND PRIOR SYS_GUID () IS NOT NULL
;
You may have copied the request of something that just use the array of double. When you have more than 1 row of the table, then you need by using the PRIOR operator in the CONNECT BY clause.
Tags: Database
Similar Questions
-
ORA-01446 tabular with CONNECTION BY LEVEL <; = 2
I created a tabular presentation where I want the 2 last lines be empty so that the user can enter new lines immediately (for example, the first time that no data is found).
Here's the sql code of the form of tables:
I get the following error:select "ID", "REQ_ID", "QUANTITY", "FRAME_SIZE", "FRAME_TYPE", "PROTECTIVE_COVERING", "MATT", "MATT_COLOR" from "#OWNER#"."CREATIVE_SVC_DESIGN_FRAMING" union all select null id, null req_id, null quantity, null frame_size, null frame_type, null protective_covering, null matt, null matt_color from dual connect by level <= 2
Failed to parse the SQL query:
ORA-01446: cannot select ROWID, or sample, a view with DISTINCT, GROUP BY, etc.
The query is not access ROWID view at all. And, as you can see, it does not use a DISTINCT, GROUP BY, etc...
My APEX is Application Express 4.0.2.00.07
My database is 10g (10.2.0.5.0)
Help, please!
Robert
http://apexjscss.blogspot.comRobert,
I wish I had a better explanation for you, but I know something again with 4.1 broke this trick union for tabular forms. I had to do a dynamic action that runs when the page loads and calls the javascript function of the: AddRow(). I think it has something to do with the validation of the form in a table, but I'm not sure.
See you soon,.
Janet Tyson -
Problem with connection by level
Hello
My desired goes something like this: I would like to generate the dates of hiredate to systdate with an interval of one month. The code that I have to return works well for single empno. I want to generate the dates of hiredate to sysdate with a gap
one month for all employees (empno). Commenting on the code to find out where empno = 7369 does not work and the system a lot of the CPU usage.
Hiredate were suppose to be to_date('01-jan-10') for empno = 7369
examples of code goes something like this:
code for the emp tableselect ADD_MONTHS(trunc(to_date('01-jan-10')),LEVEL-1) from dual connect by level <= trunc((sysdate-to_Date('01-jan-10'))/30 )
Please adviceselect ADD_MONTHS(trunc(hiredate),LEVEL-1) from employee where empno = 7369 connect by level <= trunc((sysdate-trunc(hiredate))/30 )
You should stay with double to generate numbers. You can use the caluase WITH to create a table that contains only the relevant dates.
The min max values for the datatab ann might be emp Subselects.
example not tested
with datatab as (select ADD_MONTHS(trunc(to_date('01-jan-10')),LEVEL-1) mon from dual connect by level <= trunc((sysdate-to_Date('01-jan-10'))/30 ) ) select * from employee e join datatab d on e.hiredate <=d.mon where empno = 7369;
Well, there are other ways to do it. Maybe you can provide some examples of data and also some of the desired output.
-
Performance issue with connection of a level query
Hi I have a problem with connection by level in oracle.
My table is:
J_USER_CALENDAR
--------------------------
USER_NAME FROM_DATE TO TO_DATE COMMENTS
-------------------------------------------------------------------------------------------------
Comment1 5 November 09 uma Shankar 2 November 09
Veera 11 November 09 13 November 09 Comment2
Commnet3 17 December 09 uma Shankar 15 December 09
Vinod 20 October 09 21 October 09 Comments4
The table above is the calendar of user authorization.
Now I need to view the users who are on leave between November 1, 2009 to November 30, 2009
The output should look like:
USER_NAME FROM_DATE COMMENTS
---------------------------------------------------------------------------------
Comment1 2 November 09 uma Shankar
Comment1 3 November 09 uma Shankar
Comment1 4 November 09 uma Shankar
Comment1 5 November 09 uma Shankar
Comment2 Veera 11 November 09
Comment2 Veera 12 November 09
Comment2 Veera 13 November 09
For this, I tried with the following query, but it takes too long to run.
Select FROM_DATE, user_name, comments from (SELECT distinct FROM_DATE, user_name,
Comments FROM (SELECT (LEVEL) + FROM_DATE-1 FROM_DATE, TO_DATE, FIRST_NAME |) » '|| LAST_NAME
user_name, COMMENTS OF J_USER_CALENDAR
where
and J_USER_CALENDAR.IS_DELETED = 0
CONNECT BY LEVEL < = TO_DATE - FROM_DATE + 1) has) where ("FROM_DATE = 1st November 2009 ' or FROM_DATE = November 30, 2009")
or FROM_DATE between November 1, 2009 "-November 30, 2009") order of from_Date, lower (user_name)
Please help me.
Thanks in advance.
Kind regards
PhanikanthI have not tried to analyze the SQL statement.
Here is a test set in place:
CREATE TABLE T1( USERNAME VARCHAR2(30), FROM_DATE DATE, TO_DATE DATE, COMMENTS VARCHAR2(100)); INSERT INTO T1 VALUES ('Uma Shankar', '02-Nov-09','05-Nov-09','Comment1'); INSERT INTO T1 VALUES ('Veera','11-Nov-09','13-Nov-09','Comment2'); INSERT INTO T1 VALUES ('Uma Shankar','15-Dec-09','17-Dec-09','Commnet3'); INSERT INTO T1 VALUES ('Vinod','20-Oct-09','21-Oct-09','Comments4'); INSERT INTO T1 VALUES ('Mo','20-Oct-09','05-NOV-09','Comments4'); COMMIT;
Note that I have included an additional line, when the person starts their vacation in the previous month and ends in November.
You could approach the problem like this:
Assume that you want to appear every day in a given month:SELECT TO_DATE('01-NOV-2009','DD-MON-YYYY')+(ROWNUM-1) MONTH_DAY FROM DUAL CONNECT BY LEVEL<=ADD_MONTHS(TO_DATE('01-NOV-2009','DD-MON-YYYY'),1)-TO_DATE('01-NOV-2009','DD-MON-YYYY');
Note that the above attempts to calculate the number of days in the month of November - if we know that the month has a certain number of days, 30 for example, you can rewrite the CONNECT BY clause like this:
CONNECT BY LEVEL<=30
Now, he must pick up lines of interest to the table:
SELECT * FROM T1 T WHERE (T.FROM_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY') OR T.TO_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY')); USERNAME FROM_DATE TO_DATE COMMENTS --------------- --------- --------- ---------- Uma Shankar 02-NOV-09 05-NOV-09 Comment1 Veera 11-NOV-09 13-NOV-09 Comment2 Mo 20-OCT-09 05-NOV-09 Comments4
If join us then both sets of results, we have the following query:
SELECT * FROM T1 T, (SELECT TO_DATE('01-NOV-2009','DD-MON-YYYY')+(ROWNUM-1) MONTH_DAY FROM DUAL CONNECT BY LEVEL<=ADD_MONTHS(TO_DATE('01-NOV-2009','DD-MON-YYYY'),1)-TO_DATE('01-NOV-2009','DD-MON-YYYY')) V WHERE (T.FROM_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY') OR T.TO_DATE BETWEEN TO_DATE('01-NOV-2009','DD-MON-YYYY') AND TO_DATE('30-NOV-2009','DD-MON-YYYY')) AND V.MONTH_DAY BETWEEN T.FROM_DATE AND T.TO_DATE ORDER BY USERNAME, MONTH_DAY; USERNAME FROM_DATE TO_DATE COMMENTS MONTH_DAY --------------- --------- --------- ---------- --------- Mo 20-OCT-09 05-NOV-09 Comments4 01-NOV-09 Mo 20-OCT-09 05-NOV-09 Comments4 02-NOV-09 Mo 20-OCT-09 05-NOV-09 Comments4 03-NOV-09 Mo 20-OCT-09 05-NOV-09 Comments4 04-NOV-09 Mo 20-OCT-09 05-NOV-09 Comments4 05-NOV-09 Uma Shankar 02-NOV-09 05-NOV-09 Comment1 02-NOV-09 Uma Shankar 02-NOV-09 05-NOV-09 Comment1 03-NOV-09 Uma Shankar 02-NOV-09 05-NOV-09 Comment1 04-NOV-09 Uma Shankar 02-NOV-09 05-NOV-09 Comment1 05-NOV-09 Veera 11-NOV-09 13-NOV-09 Comment2 11-NOV-09 Veera 11-NOV-09 13-NOV-09 Comment2 12-NOV-09 Veera 11-NOV-09 13-NOV-09 Comment2 13-NOV-09
Charles Hooper
IT Manager/Oracle DBA
K & M-making Machine, Inc. -
Connect by level - with several lines of inpur
Very simplified, I have this table - it has a 'table' as a variable-length structure.
I need x line of output for each input line (do not use pipelining og PL/SQL function)
Wih a single line as input of the "log in"-it works of course.
How to achieve the same thing for several input lines?drop table test3; create table test3 (id number, tekst varchar2(20)); insert into test3 values (1, 'acbdef'); insert into test3 values (2, '123'); insert into test3 values (3, 'HUUGHFTT'); insert into test3 values (4, 'A'); insert into test3 values (5, 'AKAJKSHKJASHKAJSHJKJ'); commit; with tal as ( select * from (select a.*, rownum rn from test3 a) where rn < 2) ------ select tekst, level , substr(tekst,(level-1)*1+1, 1) content from tal connect by level < length(tekst) ;
I know I can do it in PL/SQL using plan either pl or just a function in the pipeline, but I prefer a clean if possible SQL.
I tried to do in a cross join test3 and (select different values of double the test3 table) and other versions, but all with syntax errors
Oracle version will be 10.2 and 11 +.with tal as ( select * from (select a.*, rownum rn from test3 a) where rn < 3) ------ select * from test3 cross join table ( select tekst, level , substr(tekst,(level-1)*1+1, 1) content from dual connect by level < length(tekst) ) ;
I think it's kind of what you're looking for:
with tal as ( select 1 id, 'acbdef' tekst from dual union select 2 , '123' from dual union select 3 , 'HUUGHFTT' from dual union select 4 , 'A' from dual ) ------ select id, tekst, level, substr(tekst,(level-1)*1+1, 1) content from tal connect by ( level <= length(tekst) and prior id = id and prior dbms_random.value is not null ) ; ID TEKST LEVEL CONTENT ---------- -------- ---------- ------- 1 acbdef 1 a 1 acbdef 2 c 1 acbdef 3 b 1 acbdef 4 d 1 acbdef 5 e 1 acbdef 6 f 2 123 1 1 2 123 2 2 2 123 3 3 3 HUUGHFTT 1 H 3 HUUGHFTT 2 U 3 HUUGHFTT 3 U 3 HUUGHFTT 4 G 3 HUUGHFTT 5 H 3 HUUGHFTT 6 F 3 HUUGHFTT 7 T 3 HUUGHFTT 8 T 4 A 1 A
-
Need help with a query of type "connect by level.
Hello, I recently met 'connect by level' and I think he can solve my problem, but maybe not. I would like to create rows of data where the number of rows created varies according to the data from the original table.
It works:
with times like
(select to_date (' 26/01/2014 01:00 ',' dd/mm/yyyy hh24:mi:ss') starttime,)
TO_DATE (' 27/01/2014 00:00:00 ',' dd/mm/yyyy hh24:mi:ss') stoptime
the double)
Select starttime, stoptime, starttime + rownum / 24
of the time
connect by level < =.
(Select trunc ((stoptime-starttime) * 24: 2) at the time)
I would like to do something similar for several lines (following does not work)
with times like
(select to_date (' 26/01/2014 01:00 ',' dd/mm/yyyy hh24:mi:ss') starttime,)
TO_DATE (' 27/01/2014 00:00:00 ',' dd/mm/yyyy hh24:mi:ss') stoptime
of the double
Union
Select to_date (' 25/01/2014 18:00 ',' dd/mm/yyyy hh24:mi:ss') starttime.
TO_DATE (' 27/01/2014 00:00:00 ',' dd/mm/yyyy hh24:mi:ss') stoptime
the double)
Select starttime, stoptime, starttime + rownum / 24
of the time
connect by level < =.
(Select trunc ((stoptime-starttime) * 24: 2) at the time)
I need to stay away from solutions of PL/SQL, this query will be wrapped in an application that can not handle the PL/SQL, going and coming from the database (I also suck in PL/SQL).
Any help would be greatly appreciated, I have no knowledge here, I tried to read some of the documentation on hierarchical queries, but it is not yet clicking.
Thank you!
Or also:
SQL > WITH times
2 ALSO (SELECT TO_DATE (' 01:00 26/01/2014 ', "hh24:mi:ss dd/mm/yyyy") Starttime)
3, TO_DATE (' 01/26/2014 03:00 ', 'hh24:mi:ss dd/mm/yyyy') Stoptime
4 FROM TWO
5 UNION
6 SELECT TO_DATE (' 25/01/2014 18:00 ', "hh24:mi:ss mm/dd/yyyy") Starttime
7, TO_DATE (' 25/01/2014 22:00 ', 'hh24:mi:ss dd/mm/yyyy') Stoptime
8 DOUBLE)
9. SELECT T.*, Starttime + Lvl / 24
10. OF time T
11, (SELECT LEVEL Lvl
THE DOUBLE 12
13 CONNECT BY LEVEL<>
14 (SELECT MAX (TRUNC ((Stoptime-Starttime) * 24)))
15 AT the time)):
16. WHERE the lvl<= trunc="" (="" (stoptime="" -="" starttime)="" *="">=>
17 ORDER 1, 3
18.
STARTTIME STOPTIME-STARTTIME + LVL/24
----------------------------- ----------------------------- -----------------------------
January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 19:00
January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 20:00
January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 21:00
January 25, 2014 18:00 January 25, 2014 22:00 January 25, 2014 22:00
26 January 2014 01:00 26 January 2014 03:00 January 26, 2014 02:00
26 January 2014 01:00 26 January 2014 03:00 January 26, 2014 03:00
6 selected lines.
-
Use of RegExp and connect by level in Oracle SQL
Hello
Can someone help me to know about the use of regular expressions and the concept connect by level in oracle SQL?
Thanks adavancePrakash wrote:
Helloselect regexp_substr(str, '[^,]+', 1, level) val from (select 'a,b,c,d' str from dual) connect by level <= length(str) - length(replace(str,','))+1 i tried my level to understand it but couldn't Please explain how it works
Please only put code in tags code, otherwise it's hard to see what you're asking.
In response to your question look at the query...
SQL> select regexp_substr(str, '[^,]+', 1, level) val 2 from (select 'a,b,c,d' str from dual) 3 connect by level <= length(str) - length(replace(str,','))+1 4 / VAL ------- a b c d
OK, so clearly it's split the string anywhere where there is a comma, then, how he does it.
Firsly we look at connect by clause it when we use it as a generator of line...
SQL> select level from dual connect by level <= 4; LEVEL ---------- 1 2 3 4
Now, look at how the number 4 is calculated from the string...
SQL> select length('a,b,c,d') - length(replace('a,b,c,d',','))+1 from dual; LENGTH('A,B,C,D')-LENGTH(REPLACE('A,B,C,D',','))+1 -------------------------------------------------- 4
... looking at the length of the string and the length of it without comma, we can determine how many commas are in the chain and the surmize that there must be 1 more value there are commas.
Now look at the regular expression...
SQL> select regexp_substr('a,b,c,d', '[^,]+', 1, 1) from dual; R - a SQL> select regexp_substr('a,b,c,d', '[^,]+', 1, 2) from dual; R - b SQL> select regexp_substr('a,b,c,d', '[^,]+', 1, 3) from dual; R - c SQL> select regexp_substr('a,b,c,d', '[^,]+', 1, 4) from dual; R - d
The 4th parameter of the regexp_substr function is the 'presence' of the search string to return.
The actual regular expression itself is looking for 1 or more characters (sign +) who are not (the ^ symbol) a comma.
Is that more clear?
-
SQL Loader - ignore the lines with "rejected - all null columns."
Hello
Please see the attached log file. Also joined the table creation script, data file and the bad and throw the files after execution.
Sqlldr customer in the version of Windows-
SQL * Loader: release 11.2.0.1.0 - Production
The CTL file has two clauses INTO TABLE due to the nature of the data. The data presented are a subset of data in the real world file. We are only interested in the lines with the word "Index" in the first column.
The problem we need to do face is, according to paragraph INTO TABLE appears first in the corresponding CTL lines file to the WHEN CLAUSE it would insert and the rest get discarded.
1. statement of Create table : create table dummy_load (varchar2 (30) name, number, date of effdate);
2. data file to simulate this issue contains the lines below 10. Save this as name.dat. The intention is to load all of the rows in a CTL file. The actual file would have additional lines before and after these lines that can be discarded.
H15T1Y Index | 2. 19/01/2016 |
H15T2Y Index | 2. 19/01/2016 |
H15T3Y Index | 2. 19/01/2016 |
H15T5Y Index | 2. 19/01/2016 |
H15T7Y Index | 2. 19/01/2016 |
H15T10Y Index | 2. 19/01/2016 |
CPDR9AAC Index | 2. 15/01/2016 |
MOODCAVG Index | 2. 15/01/2016 |
H15TXXX Index | 2. 15/01/2016 |
H15TXXX Index | 2. 15/01/2016 |
3. the CTL file - name.ctl
DOWNLOAD THE DATA
ADD
IN THE TABLE dummy_load
WHEN (09:13) = "Index".
TRAILING NULLCOLS
(
COMPLETED name BY ' | ',.
rate TERMINATED BY ' | '.
COMPLETED effdate BY ' | '. ' TO_DATE (: effdate, "MM/DD/YYYY").
)
IN THE TABLE dummy_load
WHEN (08:12) = "Index".
TRAILING NULLCOLS
(
COMPLETED name BY ' | ',.
rate TERMINATED BY ' | '.
COMPLETED effdate BY ' | '. ' TO_DATE (: effdate, "MM/DD/YYYY").
)
invoke SQL loader in a file-> beats
C:\Oracle\product\11.2.0\client\bin\sqlldr USERID = myid/[email protected] CONTROL=C:\temp\t\name.ctl BAD=C:\temp\t\name_bad.dat LOG=C:\temp\t\name_log.dat DISCARD=C:\temp\t\name_disc.dat DATA=C:\temp\t\name.dat
Once this is run, the following text appears in the log file (excerpt):
Table DUMMY_LOAD, charged when 09:13 = 0X496e646578 ('Index' character)
Insert the option in effect for this table: APPEND
TRAILING NULLCOLS option in effect
Column Position Len term Encl. Datatype name
------------------------------ ---------- ----- ---- ---- ---------------------
NAME FIRST * | CHARACTER
RATE NEXT * | CHARACTER
EFFDATE NEXT * | CHARACTER
SQL string for the column: ' TO_DATE (: effdate, "MM/DD/YYYY").
Table DUMMY_LOAD, charged when 08:12 = 0X496e646578 ('Index' character)
Insert the option in effect for this table: APPEND
TRAILING NULLCOLS option in effect
Column Position Len term Encl. Datatype name
------------------------------ ---------- ----- ---- ---- ---------------------
NAME NEXT * | CHARACTER
RATE NEXT * | CHARACTER
EFFDATE NEXT * | CHARACTER
SQL string for the column: ' TO_DATE (: effdate, "MM/DD/YYYY").
Record 1: Ignored - all null columns.
Sheet 2: Cast - all null columns.
Record 3: Ignored - all null columns.
Record 4: Ignored - all null columns.
Sheet 5: Cast - all null columns.
Sheet 7: Discarded - failed all WHEN clauses.
Sheet 8: Discarded - failed all WHEN clauses.
File 9: Discarded - failed all WHEN clauses.
Case 10: Discarded - failed all WHEN clauses.
Table DUMMY_LOAD:
1 row loaded successfully.
0 rows not loaded due to data errors.
9 lines not loading because all WHEN clauses were failed.
0 rows not populated because all fields are null.
Table DUMMY_LOAD:
0 rows successfully loaded.
0 rows not loaded due to data errors.
5 rows not loading because all WHEN clauses were failed.
5 rows not populated because all fields are null.
The bad file is empty. The discard file has the following
H15T1Y Index | 2. 19/01/2016 |
H15T2Y Index | 2. 19/01/2016 |
H15T3Y Index | 2. 19/01/2016 |
H15T5Y Index | 2. 19/01/2016 |
H15T7Y Index | 2. 19/01/2016 |
CPDR9AAC Index | 2. 15/01/2016 |
MOODCAVG Index | 2. 15/01/2016 |
H15TXXX Index | 2. 15/01/2016 |
H15TXXX Index | 2. 15/01/2016 |
Based on the understanding of the instructions in the CTL file, ideally the first 6 rows will have been inserted into the table. Instead the table comes from the line 6' th.
NAME RATE EFFDATE H15T10Y Index 2 January 19, 2016 If the INTO TABLE clauses were put in the CTL file, then the first 5 rows are inserted and the rest are in the discard file. The line 6' th would have a ""rejected - all columns null. "in the log file. "
Could someone please take a look and advise? My apologies that the files cannot be attached.
Unless you tell it otherwise, SQL * Loader assumes that each later in the table and what clause after the first back in the position where the previous left off. If you want to start at the beginning of the line every time, then you need to reset the position using position (1) with the first column, as shown below. Position on the first using is optional.
DOWNLOAD THE DATA
ADD
IN THE TABLE dummy_load
WHEN (09:13) = "Index".
TRAILING NULLCOLS
(
name POSITION (1) TERMINATED BY ' | '.
rate TERMINATED BY ' | '.
COMPLETED effdate BY ' | '. ' TO_DATE (: effdate, "MM/DD/YYYY").
)
IN THE TABLE dummy_load
WHEN (08:12) = "Index".
TRAILING NULLCOLS
(
name POSITION (1) TERMINATED BY ' | '.
rate TERMINATED BY ' | '.
COMPLETED effdate BY ' | '. ' TO_DATE (: effdate, "MM/DD/YYYY").
)
-
SQLDev 4.1 ai2 - problem with connection SSO to SQL Server (new)
I am trying to connect to SQL Server with the new version. I have the jtds 1.3 installed and get the configuration of SQL Server tab, but once more to get the infamous SSO error trying to connect:
Status: Failure-i/o Error: failure of the SSO: library Native SSPI has not loaded. Check the system java.library.path property.
I tried to copy ntlmauth.dll in several places:
C:\Oracle\sqldeveloper4.1\sqldeveloper\sqldeveloper\bin
C:\Oracle\sqldeveloper4.1\sqldeveloper\jdk\jre\bin
C:\Oracle\sqldeveloper4.1\sqldeveloper\jdk\jre\
C:\Oracle\sqldeveloper4.1\sqldeveloper\jdk\
Given SQLDev running, but still get the error of SSO.
Discovered this problem (thanks to Jeff Smith!). I had a 32-bit DLL in the path that are in conflict with the 64 bit one. Once I deleted all of the extra 32-bit versions, the SSO authentication works.
-
Write a SQL query with lines in columns
All the
I need help in writing a SQL query with lines in columns, let give u an example...
drop table activity;
CREATE TABLE 'ACTIVITY '.
(
"PROJECT_WID" NUMBER (22.0) NOT NULL,
VARCHAR2 (150 CHAR) "PROJECT_NO."
VARCHAR2 (800 CHAR) 'NAME '.
);
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1683691, '10007', 12-121');
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1684994, '10008', 12-122');
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (1686296, '10009', 12-123');
Insert in the ACTIVITY (PROJECT_WID, PROJECT_NO, NAME) values (2225222, '9040', 12-124');
drop table lonet;
CREATE TABLE 'LONET.
(
VARCHAR2 (150 CHAR) "NAME."
NUMBER OF THE "ROOT."
VARCHAR2 (150 CHAR) "ENTRYVALUE".
);
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1683691, "LDE");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1683691, 'LME');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1683691, 'ICE');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1683691, 'IKE');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('NAM', 1686291, "QTY");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1686291, 'MAX');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("GAC", 1684994, "MTE");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('PAP', 1684994, 'MAC');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMT', 1684994, 'NICE');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('FMR', 1684994, 'RAY');
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ('BAG', 1686296, "CAQ");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("PAP", 1686296, "QAQ");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("VANESSA", 1686296, "THEW");
INSERT INTO LONET (NAME, ROOT, ENTRYVALUE) VALUES ("ANDR", 1686296, "REYL");
commit;
Link: activity.project_wid = lonet.root
look like output
Project_wid Project_no NAME GAC NAM BAG RAC 1683691 10007 12-121 LDE LME LCE LKE 1684994 10008 12-122 MTE null null MAC 1686296 10009 12-123 null null CAQ QAQ 2225222 9040 12-124 null null null null two problems, in that I am running
1. I dono how simply we can convert rows to columns
2. for root = 1683691, there are double NAM and RAC in lonet table... ideally these data should not be there, but since its here, we can take a MAX so that it returns a value
3. There are undesirables who should be ignored
Once again my thought process is that we join the activity and 4 alias table lonet.
ask for your help in this
Thank you
Hello
This is called pivoting.
Here's a way to do it:
WITH relevant_data AS
(
SELECT a.project_wid, a.project_no, b.SID
, l.name AS lonet_name, l.entryvalue
Activity one
LEFT OUTER JOIN lonet l.root = a.project_wid l
)
SELECT *.
OF relevant_data
PIVOT (MAX (entryvalue)
FOR lonet_name IN ("GAC" IN the gac
"NAM" AS nam
'BAG' IN the bag
"RAC" AS cars
)
)
ORDER BY project_wid
;
Output:
PROJECT_WID PROJECT_NO GAC NAM BAG RAC NAME
----------- ---------- ---------- ---------- ---------- ---------- ----------
1683691 12 - 10007 121 LDE LME LCE LKE
1684994 MAC MTE 10008 12-122
1686296 12 - 10009 123 QAC QAQ
2225222 9040 12 - 124
To learn more about swivel, see the FAQ in the Forum: Re: 4. How can I convert rows to columns?
Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!
-
SQL - connect by level problem
Hello
Under query returns only first 50 records but his having 233 files.
SELECT TO_CHAR (INN. START_DATE + LEVEL-1, ' DD/MM/YYYY') GENERATION_DATE OF
(SELECT TO_DATE (3 JULY 2011 ', ' DD/MM/YYYY') START_DATE, TO_DATE (OCTOBER 25, 2011 ', ' DD/MM/YYYY') END_DATE DOUBLE) INN
CONNECTION OF LEVEL between 1 and INN. END_DATE-INN. START_DATE + 1;
What is the exact problem in the operator level. Please suggest me.
Concerning
Sudhakar P.What are you talking about?
SQL> select count(*) from( 2 SELECT TO_CHAR(INN.START_DATE+LEVEL-1, 'DD/MM/YYYY') GENERATION_DATE FROM 3 (SELECT TO_DATE( '07/03/2011' ,'DD/MM/YYYY') START_DATE, TO_DATE( '25/10/2011' ,'DD/MM/YYYY') E ND_DATE FROM DUAL) INN 4 CONNECT BY LEVEL between 1 and INN.END_DATE-INN.START_DATE+1); COUNT(*) ---------- 233 1 row selected. Elapsed: 00:00:00.00
He returns 233 records.
-
Report of update SQL query with line selector. Update process.
I have a report of update SQL query with the selectors in line.
How to identify line selector in a process update on the page.
I want to update some columns with a value of an area of selection on the page.
With the help of the base:
UPDATE table_name
SET Column1 = value
WHERE some_column = some_value
I would need to do:
UPDATE table_name
SET column1 =: P1_select
WHERE [line selector] =?
Now sure how to identify [line selector] and/or validate it is checked.
Thank you
BobIdentify the name of the checkbox of the source of the page element, it should be of the fxx format (f01, f02... f50).
Suppose that we f01.for i in 1 .. apex_application.g_f01.count loop UPDATE CONTRACTS SET SIP_LOAD_FLAG = :P16_STATUS where
= apex_application.g_f01(i); --i'th checked record' primary key end loop; -
Hello Experts
I need a script that fills my table with test data.
What are your views, this script could be solved?
CREATE TABLE TEST_TAB
(id_test NUMBER (10))
, x_domain VARCHAR2 (1)
, id_object NUMBER (10)
)
TABLESPACE ALL_DATA
/
id_test: this is the primary key. It should go from 1 to 10 000 000.
x_domain: it has 3 values and distribution should be the case:
M: 94% (M = hand)
(S): 4% (S = Sub)
O: 2% (O = other)
id_object: random number between 0 and 10 000 000
TERMOUT SET SERVEROUTPUT ON
DECLARE
v_start TIMESTAMP (6);
v_end TIMESTAMP (6);
BEGIN
RUN IMMEDIATELY 'TRUNCATE TABLE TEST_TAB;
v_start: = CURRENT_TIMESTAMP;
INSERT / * + APPEND PARALLEL (16) * /.
IN TEST_TAB (id_test, x_domain, id_object)
SELECT LEVEL AS ID_TEST
, CASE level WHEN < = 10000000/100 * 94 THEN'm '
"WHEN level > 10000000 / 100 * 94 AND level < = 10000000/100 * 98 THEN."
ELSE 'O'
END AS X_DOMAIN
TRUNC (dbms_random.value (0, 10000000)) AS ID_OBJECT
OF THE DOUBLE
CONNECT BY LEVEL < = 10000000
;
COMMIT;
v_end: = CURRENT_TIMESTAMP;
DBMS_OUTPUT. Put_line ('Insert is: ' |) To_char(v_end-v_start));
END;
/
SQL * more: Production of release 11.2.0.1.0 Thu Jan 16 11:21:43 2014
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production
With partitioning, OLAP, Data Mining and Real Application Testing options
Insert took: + 00:02:12.020934000 000000000
PL/SQL procedure successfully completed.
SQL >
I read of rp0428 first of all, he must use SQL and PL/SQL. But it seems to me that this sql took too long... Can be tuned?
Hello Randolf
Your solution is the best!
Your result is:
===========
SQL * more: Production of release 11.2.0.1.0 on Mon Jan 20 09:48:02 2014
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production
With partitioning, OLAP, Data Mining and Real Application Testing options
09:48:03 SQL >
09:48:03 SQL > alter session enable dml parallel;
Modified session.
Elapsed time: 00:00:00.00
09:48:03 SQL >
09:48:03 SQL > truncate table test_tab;
Table truncated.
Elapsed time: 00:00:00.15
09:48:03 SQL >
09:48:03 SQL > insert / * + append parallel (16) * /.
09:48:03 2 in (test_tab)
09:48:03 3 id_test, x_domain, id_object
09: 48:03 4)
09:48:03 5 with
09:48:03 6 generator1 as
09:48:03 () 7
09:48:03 8 select / * +.
09:48:03 9 cardinality (1e3)
09:48:03 10 materialize
09:48:03 11 * /.
09:48:03 12 rownum as id
09:48:03 13, rpad ('x', 100) as filler
09:48:03 14 from
09:48:03 15 double
09:48:03 16 connect by
09:48:03 level 17<=>=>
09: 48:03 18).
09:48:03 19 generator2 as
09:48:03 (20)
09:48:03 21 select / * +.
09:48:03 22 cardinality (1e4)
09:48:03 23 materialize
09:48:03 24 * /.
09:48:03 25 rownum as id
09:48:03 26, rpad ('x', 100) as filler
09:48:03 27 of
09:48:03 28 double
09:48:03 29 connect by
09:48:03 level 30<=>=>
09: 48:03 31)
09:48:03 32 select
09:48:03 33 id like id_test
09:48:03, 34 cases
09:48:03 35 when id<=>=>
09:48:03 36 then'm '
09:48:03 37 when id<=>=>
09:48:03 38 of then '
09:48:03 39 other 'o'
09:48:03 40 end as x_domain
09:48:03 41, trunc (dbms_random.value (0, 10000000)) as id_object
09:48:03 42)
09:48:03 43 select / * + leading(b a) * /.
09:48:03 44 (a.id - 1) * 1e4 + b.id as id
09:48:03 45 of
09:48:03 46 generator1 one
09:48:03 47 b, of generator2
09: 48:03 48)
09:48:03 49;
10000000 lines were created.
Total time: 00:00:10.64
09:48:13 SQL >
09:48:13 SQL > commit;
Validation complete.
Elapsed time: 00:00:00.08
09:48:14 SQL >
Thank you!
-
CONNECTION BY level/prior/root
Hi all
I'm trying to CONNECT BY level/prior/root. But I can barely decipher what it actually does. I think it is a very useful method provided by oracle and can have several uses. can someone help me on this please.
I googled on this topic but everywhere I could find only employee and manager problem that will be solved by query below.
But if we just query as below, we can get the employee and his manage without CONNECT BY.SELECT employee_id, last_name, manager_id FROM employees CONNECT BY PRIOR employee_id = manager_id;
Other queries is obtained to connect by is below, but he could not also include:SELECT employee_id, last_name, manager_id FROM employees;
Please help me.select SYSDATE-41 + level - 1 the_date from dual connect by level <= SYSDATE - SYSDATE-41 + 1
Published by: J2EE_Life on December 6, 2011 08:12J2EE_Life wrote:
Hi allI'm trying to CONNECT BY level/prior/root. But I can barely decipher what it actually does. I think it is a very useful method provided by oracle and can have several uses. can someone help me on this please.
I googled on this topic but everywhere I could find only employee and manager problem that will be solved by query below.
SELECT employe_id, last_name, manager_id
Employees
CONNECT BY PRIOR employee_id = manager_id;But if we just query as below, we can get the employee and his manage without CONNECT BY.
SELECT employe_id, last_name, manager_id
Employees;In fact, those who are not the same.
If you use the standard table of hr.employees, the CONNECT BY query above returns 315 lines, but the secoind query return lines only 107.CONNECTION is useful to show the recursive relationships. It can show you, for example, not only that reports directly to a data manager, but the whole hierarchy of persons under a given head. For example, the following shows the hierarchy starting with an employee named "Rooster":
SELECT employee_id, last_name, manager_id , LEVEL AS lvl , SYS_CONNECT_BY_PATH (last_name, '/') AS path FROM hr.employees START WITH last_name = 'De Haan' CONNECT BY PRIOR employee_id = manager_id; SELECT SYSDATE - SYSDATE-41 + 1 FROM DUAL;
Output:
EMPLOYEE_ID LAST_NAME MANAGER_ID LVL PATH ----------- ---------- ---------- --- -------------------------- 102 De Haan 100 1 /De Haan 103 Hunold 102 2 /De Haan/Hunold 104 Ernst 103 3 /De Haan/Hunold/Ernst 105 Austin 103 3 /De Haan/Hunold/Austin 106 Pataballa 103 3 /De Haan/Hunold/Pataballa 107 Lorentz 103 3 /De Haan/Hunold/Lorentz
Very briefly, here's how it works.
The result set of a query CONNECT BY is the UNION ALL of several queries, all sharing a common SELECT clause.
Any line that meets the conditions of the START WITH clause is supposed to be at LEVEL 1. So you can think of the first branch of the UNION of ALL being (in this case):SELECT employee_id, last_name, manager_id , LEVEL AS lvl , SYS_CONNECT_BY_PATH (last_name, '/') AS path FROM hr.employees WHERE last_name = 'De Haan' UNION ALL ...
Other rows in the result set will be LEVEL = N if the conditions of the CONNECT BY clause, where the PRIOR operator refers to any line level = N - 1.
For example, the line with name = "Hunold" satisfies the condition to connect BY when the FIRST line is the line where last_name = "Rooster", Hunold is in the game with the LEVEL of results = 2.
Another example: the line with name = 'Lorentz' meets the condition to connect BY when the FIRST line is the line where last_name = "Hunold", Hunold is in the result set with LEVEL = 3.
This is a classic example of a tree structure, where the rows in the table are connected to other lines in a parent-child relationship. In a tree, each row has 0 or 1 of the parents, but a line can have any humber children. Haan has 0 parent and 1 child (that is, Hunold). Hunold has 1 parent (De Haan) and 4 children. CONNECT BY queries are useful to deal with the trees like this, especially when the parent-child relationship may extend to a number any levels.Other queries is obtained to connect by is below, but he could not also include:
Select the level - 1 the_date + SYSDATE-41
of the double
connect by level<= sysdate="" -="" sysdate-41="" +="">=>I don't understand whether you.
SYSDATE-SYSDATE is just 0
0 - 41 + 1 is just-40, so you might as well say:select SYSDATE-41 + level - 1 the_date from dual connect by level <= -40;
In addition, LEVEL is always a positive integer, then the CONNECT BY State will never have the value TRUE, and if the CONNECT BY clause can never be TRUE, there is no reason to have a CONNECT BY clause.
A more reasonable request is:SELECT SYSDATE + LEVEL - 1 AS the_date FROM dual CONNECT BY LEVEL <= 4 -- or any positive number ;
which produces this output, the given number of days (4 in this example) from today:
THE_DATE -------------------- 06-Dec-2011 11:08:24 07-Dec-2011 11:08:24 08-Dec-2011 11:08:24 09-Dec-2011 11:08:24
This is a very common way to generate a Counter of Table (a table, or, as in this case, a result set, that matters). For example, if you need for the aggregates per day in a table and you want to show 0 for days that never exist in the table, then you outer join in a table of counter like the one shown above.
This is a common use of CONNECT BY, but this is an unusual exception to the rules that is prohibited govern CONNECT BY queries. I suggest you uderstand how the query on hr.employees, above, the work before you start trying to figure out how it works.Published by: Frank Kulash, December 6, 2011 11:15
The pages below are introductions to CONNECT BY:
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:489772591421
http://Philip.Greenspun.com/SQL/trees -
Extraction of several lines using CONNECT BY
Hello
It's the structure of the table:
CREATE TABLE XX_SHIFT_EXCEPTIONS ( PLANT_SHIFT_EXC_ID NUMBER(18) NOT NULL, START_DATE DATE NOT NULL , END_DATE DATE NOT NULL , EXC_START_TIME NUMBER(18) NOT NULL , EXC_DURATION NUMBER(18), EXC_END_TIME NUMBER(18) NOT NULL); INSERT INTO XX_SHIFT_EXCEPTIONS VALUES (1,'27-NOV-2015','30-NOV-2015',1200,480,2000); INSERT INTO XX_SHIFT_EXCEPTIONS VALUES (2,'28-NOV-2015','28-NOV-2015',1200,480,2000); INSERT INTO XX_SHIFT_EXCEPTIONS VALUES (3,'27-NOV-2015','28-NOV-2015',1200,480,2000);
I want my result to look like this:
START_DATE END_DATE EXC_START_TIME EXC_END_TIME PLANT_SHIFT_EXC_ID
1 27 NOVEMBER 2015 27 NOVEMBER 2015 1200 2000
1 NOVEMBER 28 NOVEMBER 28, 2015 2015 1200 2000
1 NOVEMBER 29 NOVEMBER 29, 2015 2015 1200 2000
1 NOVEMBER 30 NOVEMBER 30, 2015 2015 1200 2000
2 NOVEMBER 28 NOVEMBER 28, 2015 2015 1200 2000
3 27 NOVEMBER 2015 27 NOVEMBER 2015 1200 2000
3 NOVEMBER 28, 2015 28 NOVEMBER 2015 1200 2000
I tried the below:
SELECT PLANT_SHIFT_EXC_ID,START_DATE+LEVEL-1 START_DATE,START_DATE+LEVEL-1 END_DATE,EXC_START_TIME,EXC_END_TIME from (SELECT * FROM XX_SHIFT_EXCEPTIONS WHERE TRUNC(END_DATE)!=TRUNC(START_DATE)) SHIFT1 CONNECT BY LEVEL<=(END_DATE-START_DATE+1) UNION ALL SELECT PLANT_SHIFT_EXC_ID,START_DATE,END_DATE,EXC_START_TIME,EXC_END_TIME FROM XX_SHIFT_EXCEPTIONS WHERE END_DATE=START_DATE order by 1,2;
But the result set is not wait for him as for factory shift 1, I get 11 lines instead of 4 rows
Help, please. Thank you.
so, something like this:
WITH XX_SHIFT_EXCEPTIONS (plant_shift_exc_id, start_date, end_date, exc_start_time, exc_duration, exc_end_time)
AS (SELECT 1, to_date (27 November 2015 "," MON-DD-YYYY ""), to_date (November 30, 2015 "," MON-DD-YYYY'"), 1 200 480, 2000 FROM dual UNION ALL)
SELECT To_date 2 (November 28, 2015 "," MON-DD-YYYY ""), to_date (November 28, 2015 "," DD-MON-YYYY ' "), 1 200 480, 2000 FROM dual UNION ALL
SELECT 3, to_date (27 November 2015 "," MON-DD-YYYY ""), to_date (November 28, 2015 "," MON-DD-YYYY'"), 1 200 480, 2000 DOUBLE)
SELECT PLANT_SHIFT_EXC_ID, START_DATE + LEVEL 1 START_DATE, END_DATE START_DATE + LEVEL 1, EXC_START_TIME, EXC_END_TIME
OF XX_SHIFT_EXCEPTIONS
CONNECT BY LEVEL<= (end_date="" -="">=>
AND PRIOR plant_shift_exc_id = plant_shift_exc_id
and prior sys_guid() is not null
/
HTH
Maybe you are looking for
-
When I copy a url in the address bar in the clipborad and paste it elsewhere, it is truncated. This is particularly annoying when trying to someone send a link to a non-English wikipedia article (or other sites with the "descriptive" URLS.) is there
-
Hello!Does anyone know the module allows you to configure a full control over the actions of the users ' who does what' (WHO, and this file was accessed, who has created, deleted, or renamed a particular file or directory)? (RN104, latest firmware)
-
my computer has limited connectivity to my wireless network
I have windows 7 Home Basic 64 bit. I have the network wireless in my house, but would not have access to the internet on my laptop. It connects to the network but still warn me that your computer has limited connectivity to my wireless network. Plea
-
There is a yellow triangle on top of my computer icon in the printers and devices window, it says "Base system device driver in not installed". I tried all the fixes and nothing has worked. What is - this and I can remove it. Has it something to d
-
Photosmart C310 running 64 bit Windows 7 64 bit upgrade Windows 8 Pro. After the upgrade to Windows 8, the C310 has no function. You are looking for a solution I went to HP to see there was the software for Windows 8. Win 8 software has been download