Variable number of rows to 4 separate columns
I have data like this:
ID | value |
---|---|
224 | Apples |
123 | Oranges |
224 | Apples |
334 | Grapes |
224 | Cherries |
224 | Grapes |
123 | Grapes |
334 | Bananas |
224 | Bananas |
123 | Apples |
224 | Cherries |
224 | Blueberries |
And he must turn into this:
ID | value 1 | value 2 | value 3 | value 4 |
---|---|---|---|---|
224 | Apples | Cherries | Grapes | Bananas |
123 | Oranges | Grapes | Apples | -empty- |
334 | Grapes | Bananas | -empty- | -empty- |
You can see that the sort is not serious. However, made a distinction, and he must complete the 4 values, leaving the last values empty (or null) if not available. Everything beyond 4 values can be ignored.
I looked at several online solutions, but none seem to match what I want to accomplish.
Please let me know if you have any ideas. Thank you!
SQL > data
2 (
3. Select 224 id, 'Apples' c1 dual UNION ALL
4. select id 123, 'Oranges' c1 dual UNION ALL
5. Select 224 id, 'Apples' c1 dual UNION ALL
6. select id 334, "Grape" dual UNION ALL c1
7. Select 224 id, 'Cherries' c1 dual UNION ALL
8. select id 224, "Grapes" dual UNION ALL c1
9. select id 123, "Grape" dual UNION ALL c1
10. select id 334, "Banana" dual UNION ALL c1
11 select id 224, "Banana" dual UNION ALL c1
12. select id 123, 'Apples' c1 dual UNION ALL
13. Select 224 id, 'Cherries' c1 dual UNION ALL
14 select id 224, c1 'Blueberries' of the double
15)
16 select id, max (case when rn = 1 end then c1) as value1,
17 max (case when rn = 2 then end c1) as value2,.
18 max (case when rn = 3 c1 then end) as value3,
19 max (case when rn = 4 then end c1) as value4
20 of
(21)
22. select id, c1, dense_rank() over (partition by order of identification by c1): the nurse
23 data
24)
where the 25 rn<=>=>
26 group by id;
ID VALUE1 VALUE2 VALUE3 VALUE4
---------- -------------------- -------------------- -------------------- -----------------------
123 apples grapes Oranges
224 apples bananas blueberries cherries
334 banana grapes
Tags: Database
Similar Questions
-
[8i] way to add a specific number of rows based on a column value?
I know that the version of Oracle is old:
Oracle8i Enterprise Edition Release 8.1.7.2.0 - Production
PL/SQL Release 8.1.7.2.0 - Production
CORE 8.1.7.0.0-Production
AMT for HP - UX: 8.1.7.2.0 - Production Version
NLSRTL Version 3.4.1.0.0 - Production
I'm trying to get an old database data in a specific format, and this should be run several times during the next year, until we can phase out the old database. Unfortunately, it is not particularly useful for formatting the data after he is questioned, so if a SQL solution can be found, it would probably be best.
Some examples of data:
I want to get these results:CREATE TABLE testabc ( item CHAR(25) , qty NUMBER(13,4) ); INSERT INTO testabc VALUES ('Item1',1); INSERT INTO testabc VALUES ('Item2',3); INSERT INTO testabc VALUES ('Item3',1); INSERT INTO testabc VALUES ('Item4',2);
Either format would be acceptable. The key is to have the same number of rows for an article as its quantity.ITEM QTY ------------------------- --------------- Item1 1.000 Item2 3.000 --blank row --blank row Item3 1.000 Item4 2.000 --blank row OR ITEM QTY ------------------------- --------------- Item1 1.000 Item2 1.000 Item2 1.000 Item2 1.000 Item3 1.000 Item4 1.000 Item4 1.000
Any help on this would be appreciated. I wasn't sure if maybe that this would require a CONNECT BY statement. With my luck, it requires one of the functions which did not become available until 9i...
I tried this:
but he gave me a bunch of empty lines.SELECT CASE WHEN LAG(qty) OVER(PARTITION BY item ORDER BY item, qty DESC) = 1 THEN item END AS item , CASE WHEN LAG(qty) OVER(PARTITION BY item ORDER BY item, qty DESC) > 1 THEN LAG(qty) OVER(PARTITION BY item ORDER BY item, qty DESC) - 1 END AS qty FROM testabc ;
Thank you!Hello
Here's a way to do it in Oracle 8.1
SELECT CASE c.n WHEN 1 THEN t.item END AS item_col , CASE c.n WHEN 1 THEN t.qty END AS qty FROM testabc t , ( SELECT ROWNUM AS n FROM all_objects WHERE ROWNUM <= 10 -- If you know an upper bound ) c WHERE c.n <= t.qty ORDER BY t.item , c.n ;
This assumes that this quantity is never more than the number of lines in object (usually at least 5000). If you need more lines, you can cross join object to itself, with the result a limit of 25 million lines or more.
The WHERE clause in the subquery c is not absolutely necessary, but it will make things faster.Published by: Frank Kulash, December 19, 2011 15:33
The solution above is for the first set of results, with blank lines.
For the results of the second, with lines no NULL duplicate, just lose the CASE expressions in the FROM clause:SELECT t.item , t.qty FROM testabc t , ( SELECT ROWNUM AS n FROM all_objects WHERE ROWNUM <= 10 -- If you know an upper bound ) c WHERE c.n <= t.qty ORDER BY t.item , c.n ;
-
How to reset a number of rows based on a column value?
OracleBI Discoverer 10g (10.1.2.3)
Oracle Business Intelligence Discoverer Plus 10g (10.1.2.55.26)
I have a Scout more State showing point receipts, receipt of the dates, and if the reception has been inspected. I've got items that need to be inspected each 5th receipt. There must be a function of hand-dandy, that I can use to do that, right?
I'm looking to count receipts and reset the inspection counter = YItem Receipt Date Inspected Bracket 1/1/2009 Y Bracket 2/1/2009 N Bracket 3/1/2009 N Bracket 4/1/2009 Y <--let's assume someone didn't follow the instructions Bracket 5/1/2009 N Bracket 6/1/2009 N Bracket 7/1/2009 N Bracket 8/1/2009 N Bracket 9/1/2009
I'm open to other methods if the mine seems to be a failure.Item Receipt Date Inspected Inspect_Count Bracket 1/1/2009 Y 0 Bracket 2/1/2009 N 1 Bracket 3/1/2009 N 2 Bracket 4/1/2009 Y 0 Bracket 5/1/2009 N 1 Bracket 6/1/2009 N 2 Bracket 7/1/2009 N 3 Bracket 8/1/2009 N 4 Bracket 9/1/2009 5 <-- receiver should inspect on this receipt
-TracyHello
I don't think you can do it is Discoverer more only because you must divide twice once to get all inspected records and still counting the days between them.
What you can do is in Discoverer Admin add an element to the EUL calculated:
inspections = COUNT (DECODE (inspected, 'Y', 1)) OVER (ORDER BY reception Date)
In Discoverer, you can add a calculation:
Count (inspected) over (PARTITION BY ORDER BY Date of receipt) - 1
to produce the County to inspect.
Rod West
-
Display the option button if the number of rows in the table is equal to 1
I'm having issues there buy maybe a simple script out there.
I have a table which can have up to four lines. If the table contains only one row, an option button can be clicked to change the format/entry of cells in this row. I have to hide this box of a user option, if they added more of a line to the table and make it available again if they reduce the number of lines to one.
I have everything else works well (radio buttons change line format, add/delete rows in the table using buttons, number of rows in the first column)
Anyone have any ideas?
See you soon
Bobby
You can place it in the code that adds more lines when running... If you have questions send the fomr to [email protected] so I can check it out...
Thank you
Srini
-
How to determine the number of rows in the database and save the result to a local variable?
Hello
I'm a newbie in the use of TestStand, databases and SQL, and now I've met difficulties. I use TestStand 2014 (32 bit).
I have a need to know the number of rows in a database and save that number in a local variable. I tried to practice using the database of the Types of step provided with TS. I tried to use the following in a SQL statement:
Locals.NumberOfRows = ("SELECT COUNT (*) FROM TEST_TABLE")
It returns an error: specified value is not the expected type. My goal is possible in this way, or I'm doing this completely wrong?
-RautSa
Thank you for your response, Norbert. I have a database of who wins new values at random, and sometimes I need the exact number of rows in this table.
I managed to achieve my goal by using the SQL statement: "SELECT COUNT (*) as Rowcount OF TEST_TABLE", followed by a data GET operation, which records that number of lines in a local variable.
-RautSa
-
Insert in the table in separate columns
I did the vi in the attachments. This basically vi, calculate a value from the device, this is the channel dashboard. I need more so: when calculating terminate, I need to insert data into a table, but the problem is: the number of lines in the constant table is the number of columns, I need the Temp Org chart. And these values are variable. I need a method to do this automatically. Or, I need a vi to 'build' these columns according to the number of rows in the table of constants.
If the table of constants (number of lines) and the channel table (number of items) to match the size, where the other constants come when the size has to increase?
What intrigues me is your use of construction "array index... build array. It's the same as truncate the initial 3-element array, regardless of the number of items is originally in there.
Here's a quick rewrite that eliminates some of the questionable things. As I mentioned in the first sentence, I don't know really what you want.
-
Values of Colum as separate columns
I have a table that looks like this:
Company (varchar),
FieldName (varchar)
Valuex (varchar)
Data can look like this:
Company Fieldname valuex
------------- --------------- -----------
John 123 name
MiddleName 123 C
LastName 123 Smith
I would like to write a query that comes out like this:
MiddleName t first name last name company
------------- ------------ ---------------- ------------
Smith John 123 C
It can be? Thanks in advance.Hello
Column definitions must be hard-coded in the application.
You cannot hardcode anything today and make sure that it reflects accurately data next year.
but you can write soemthing today who, when it is executed next year, will make the hardcode then.
This is called dynamic SQL.
Here's a way to do it in SQL * Plus, with the command of the COIL:/* How to Pivot a Table with a Dynamic Number of Columns For example, you want to make a cross-tab output of the scott.emp table. Each row will represent a department. There will be a separate column for each job. Each cell will contain the number of employees in a specific department having a specific job. The exact same solution must work with any number of departments and columns. (Within reason: there's no guarantee this will work if you want 2000 columns.) */ PROMPT ========== 0. Basic Pivot ========== SELECT deptno , COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS analyst_cnt , COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS clerk_cnt , COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS manager_cnt FROM scott.emp WHERE job IN ('ANALYST', 'CLERK', 'MANAGER') GROUP BY deptno ORDER BY deptno ; PROMPT ========== 1. Dynamic Pivot ========== -- ***** Start of dynamic_pivot.sql ***** -- Suppress SQL*Plus features that interfere with raw output SET FEEDBACK OFF SET PAGESIZE 0 SPOOL p:\sql\cookbook\dynamic_pivot_subscript.sql SELECT DISTINCT ', COUNT (CASE WHEN job = ''' || job || ''' ' AS txt1 , 'THEN 1 END) AS ' || job || '_CNT' AS txt2 FROM scott.emp ORDER BY txt1; SPOOL OFF -- Restore SQL*Plus features suppressed earlier SET FEEDBACK ON SET PAGESIZE 50 SPOOL p:\sql\cookbook\dynamic_pivot.lst SELECT deptno @@dynamic_pivot_subscript FROM scott.emp GROUP BY deptno ORDER BY deptno ; SPOOL OFF -- ***** End of dynamic_pivot.sql ***** /* EXPLANATION: The basic pivot assumes you know the number of distinct jobs, and the name of each one. If you do, then writing a pivot query is simply a matter of writing the correct number of ", COUNT ... AS ..."\ lines, with the name entered in two places on each one. That is easily done by a preliminary query, which uses SPOOL to write a sub-script (called dynamic_pivot_subscript.sql in this example). The main script invokes this sub-script at the proper point. In practice, .SQL scripts usually contain one or more complete statements, but there's nothing that says they have to. This one contains just a fragment from the middle of a SELECT statement. Before creating the sub-script, remember to turn off SQL*Plus features that are designed to help humans read the output (such as headings and feedback messages like "7 rows selected.", since we do not want these to appear in the sub-script. Remember to turn these features on again before running the main query. */
The first HOLD file that it creates, dynaic_pivot_subscript.sql, looks like this
, COUNT (CASE WHEN job = 'ANALYST' THEN 1 END) AS ANALYST_CNT , COUNT (CASE WHEN job = 'CLERK' THEN 1 END) AS CLERK_CNT , COUNT (CASE WHEN job = 'MANAGER' THEN 1 END) AS MANAGER_CNT , COUNT (CASE WHEN job = 'PRESIDENT' THEN 1 END) AS PRESIDENT_CNT , COUNT (CASE WHEN job = 'SALESMAN' THEN 1 END) AS SALESMAN_CNT
-
number of rows affected by report
Hi all
I want to show the number of result rows to a query on a report page. my test query returns 52 sets of data (also when I execute the same statement with select count (*)) but the #TOTAL_ROWS variable # said that 11.
I think it's because I put the value in pagination of row 10...
is there a known issue with this? is #TOTAL_ROWS # only supposed to show the number of lines of recoveries?
Thanks in advance hendrikHendrik,
This will not work unless you paging system is set (with pagination). You can always count your rows in a separate process and get this value by using the same SQL as in your report.
Denes Kubicek
-------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Opal-consulting.de/training
http://Apex.Oracle.com/pls/OTN/f?p=31517:1
------------------------------------------------------------------- -
Export of DataPump API - number of rows exported using
Hello
I'm working on the procedure to export data in the table before deleting the partition. It will be run by the Scheduler of the data, that's why I want to run the datapump job using the API.
I wonder, if it is possible to get the number of rows exported. I would compare with the number of rows in a partition before you delete the partition.
Thank you
Krystian
Hello
Don't know exactly how you want the number of rows per partition that have been exported, but here are a few ideas:
1. create a log file by using 'add_file ':
-Add a log file
dbms_datapump.add_file (h, ' DEPTJOB.log ', a', NULL,)
dbms_datapump.Ku$ _file_type_log_file);
It is also in my example included below. Here is the content after the DEPTJOB.log workload (situated in Oracle Directory object would be "in my example):
$ cat /tmp/DEPTJOB.log
Departure 'SCOTT '. "" DEPTJOB ":
Object type TABLE_EXPORT/TABLE/TABLE processing
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . "exported"SCOTT" DEPT': 'SYS_P1581' 5,929 KB 2 lines
. . "exported"SCOTT" DEPT': 'SYS_P1582' 5,914 KB 1 lines
. . "exported"SCOTT" DEPT': 'SYS_P1583' 5,906 KB 1 lines
Table main 'SCOTT '. "' DEPTJOB ' properly load/unloaded
******************************************************************************
Empty the files together for SCOTT. DEPTJOB is:
/tmp/Dept.dmp
Job 'SCOTT '. "" DEPTJOB "managed to 00:00
You can then review or extract the information from the log file.
2. save the master table and the query for the busy lines.
Use the parameter "KEEP_MASTER":
-Keep the main table to be deleted after employment ends
dbms_datapump.set_parameter(h,'KEEP_MASTER',1);
Here's my example, the request to the main table is at the end.
$ sqlplus scott/tiger @deptapi
SQL * more: version 12.2.0.0.2 Beta on Fri Jan 22 12:55:52 2016
Copyright (c) 1982, 2015, Oracle. All rights reserved.
Last successful login time: Friday, January 22, 2016 12:55:05-08:00
Connected to:
Database Oracle 12 c Enterprise Edition Release 12.2.0.0.2 - 64-bit Beta
With the options of partitioning, OLAP, advanced analytics and Real Application Testing
Connected.
SQL > SET FEEDBACK 1
SQL > SET 10 NUMLARGEUR
SQL > SET LINESIZE 2000
SQL > SET TRIMSPOOL ON
SQL > SET TAB OFF
SQL > SET PAGESIZE 100
SQL > SET SERVEROUTPUT ON
SQL >
SQL > Rem save on the old table of scott.dept
SQL > dept and rename it dept_old.
Renamed table.
SQL >
SQL > Rem re-create it with partitions
SQL > CREATE TABLE dept (deptno NUMBER varchar (14) dname, loc varchar (13)) PARTITION INTO 3 PARTITIONS HASH (deptno)
2.
Table created.
SQL >
SQL > Rem fill the dept table
SQL > insert into dept select * from dept_old;
4 lines were created.
SQL >
SQL > Rem now create datapump job export SCOTT. DEPT. using the API
SQL > DECLARE
2: NUMBER; -Handle Datapump
3 jobState VARCHAR2 (30); -To keep track of job status
4 ind NUMBER; -Index of the loop
5 the ku$ _LogEntry; -For error messages and work in PROGRESS
6 js ku$ _JobStatus; -The State of the work of get_status
7 jd ku$ _JobDesc; -The get_status job description
8 m ku$ _Status; -The status returned by get_status object
9 sql_stmt VARCHAR2 (1024);
nom_partition 10-VARCHAR2 (50);
11 rows_completed NUMBER;
12
BEGIN 13
14-
15 run the Installer based on the operation to perform.
16-
17 h: = dbms_datapump.open ('EXPORT', 'TABLE', NULL, 'DEPTJOB', NULL);
18 dbms_datapump.add_file (h, 'dept.dmp', 'd', NULL,
dbms_datapump.Ku$ _file_type_dump_file 19, 1);
20
21 --- Add a logfile
22 dbms_datapump.add_file (h, ' DEPTJOB.log ', a', NULL,)
23 dbms_datapump.ku$ _file_type_log_file);
24
25 dbms_datapump.metadata_filter (h, 'SCHEMA_EXPR', ' IN ("SCOTT") ");
26 dbms_datapump.metadata_filter (h, 'NAME_LIST', "'DEPT"');
27
28
29-
30 start work.
31-
32 dbms_datapump.set_parameter (h, 'SILENT', 'banner');
33
34 -keep the main table to be deleted after employment ends
35 dbms_datapump.set_parameter(h,'KEEP_MASTER',1);
36
37 dbms_datapump.start_job (h);
38
39-
40 - run to grabbing the output of the job and write in the output log.
41-
42 jobState: = "UNDEFINED";
43 WHILE (jobState! = "COMPLETED") AND (jobState! = "STOPPED")
44 LOOP
45 dbms_datapump.get_status (h,
dbms_datapump.Ku$ _status_job_error 46.
dbms_datapump.Ku$ _status_wip 47, -1, jobState, m);
48
49 --
50. If we received messages WIP or error for the work, display them.
51 --
52 IF (BITAND(sts.mask,dbms_datapump.ku$_status_wip)! = 0)
53 THEN
54: = sts.wip;
55 ON THE OTHER
56 IF (bitand(sts.mask,dbms_datapump.ku$_status_job_error)! = 0)
57 THEN
58: = sts.error;
59 ON THE OTHER
the 60: = NULL;
61 END IF;
62 END IF;
63
64 the IS NOT NULL IF
65 THEN
66 ind: = the. FIRST;
67 then AS ind IS NOT NULL
68 LOOP
69 dbms_output.put_line ((ind). LogText);
70 ind: = the. Next (IND);
LOOP END 71;
72 END IF;
73 END LOOP;
74
75-
76 - release work.
77-
78 dbms_datapump.detach (h);
79
80-
81. all exceptions that spread at this point will be captured.
82 - the details are extracted from get_status and displayed.
83-
EXCEPTION OF 84
85, SO THAN OTHERS THEN
BEGIN 86
87 dbms_datapump.get_status (h,
dbms_datapump.Ku$ _status_job_error, 0-88,.
89 jobState, sts);
90 IF (BITAND(sts.mask,dbms_datapump.ku$_status_job_error)! = 0)
91 THEN
the 92: = sts.error;
93 the IS NOT NULL IF
94 THEN
95 ind: = the. FIRST;
96 although ind IS NOT NULL
LOOP OF 97
98 dbms_output.put_line ((ind). LogText);
99 ind: = the. Next (IND);
100 END LOOP;
101 END IF;
102 END IF;
103
BEGIN 104
105 DBMS_DATAPUMP. STOP_JOB (m, 1, 0, 0);
EXCEPTION OF 106
107. WHEN OTHER NULL THEN;
END 108;
109
110 EXCEPTION
111, SO THAN OTHERS THEN
112 dbms_output.put_line ('ORA-00000: an unexpected exception during ' |)
113 ' Manager of exceptions. ' ||
114 ' sqlcode = ' | TO_CHAR (SQLCODE));
END 115;
END 116;
117.
Departure 'SCOTT '. "" DEPTJOB ":
Object type TABLE_EXPORT/TABLE/TABLE processing
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . "exported"SCOTT" DEPT': 'SYS_P1581' 5,929 KB 2 lines
. . "exported"SCOTT" DEPT': 'SYS_P1582' 5,914 KB 1 lines
. . "exported"SCOTT" DEPT': 'SYS_P1583' 5,906 KB 1 lines
Table main 'SCOTT '. "' DEPTJOB ' properly load/unloaded
******************************************************************************
Empty the files together for SCOTT. DEPTJOB is:
/tmp/Dept.dmp
Job 'SCOTT '. "" DEPTJOB "managed to 00:00
PL/SQL procedure successfully completed.
SQL >
SQL > table main query Rem for number of lines completed
SQL > column nom_partition format a10
SQL > format 9999 column lines
SQL > SELECT nom_partition, COMPLETED_ROWS FROM SCOTT . DEPTJOB WHERE BASE_OBJECT_NAME = "DEPT";
PARTITION_ COMPLETED_ROWS
---------- --------------
SYS_P1581 2
SYS_P1583 1
SYS_P1582 1
3 selected lines.
SQL >
SQL > "EXIT";
3. you might even extract information of the call from the command line:
$ sqlplus scott/tiger @deptapi.sql | grep 'exported ' | AWK ' {print "Table:" $4, 'charge' $7, $8} '
Table: 'SCOTT '. "" DEPT ":"SYS_P1581"loaded 2 rows
Table: 'SCOTT '. "' DEPT ': 'SYS_P1583' loaded 1 lines
Table: 'SCOTT '. "' DEPT ': 'SYS_P1582' loaded 1 lines
-
Invalid reference to the variable 'NUMBER '.
Hi gurus
I understand that if someone helps me, I have the following code example.
Code example
SET SERVEROUTPUT ON
DECLARE
List_of_numbers_t TYPE TABLE IS NUMBER;
l_numbers list_of_numbers_t: =.
list_of_numbers_t (1,2,3);
BEGIN
DBMS_OUTPUT. Put_line (l_numbers (1).) (COUNT);
END;
Error
Error report:
ORA-06550: line 7, column 38:
PLS-00487: Invalid reference to the variable 'NUMBER '.
ORA-06550: line 7, column 3:
PL/SQL: Statement ignored
06550 00000 - "line %s, column % s:\n%s".
* Cause: Usually a PL/SQL compilation error.
* Action:
I want to check the index 1 of my collection, but I get the above error. Can someone help me to remove this error. Thank you
Concerning
Matt
Hi, Matt,
Matt. wrote:
Hi gurus
I understand that if someone helps me, I have the following code example.
Code example
SET SERVEROUTPUT ON
DECLARE
List_of_numbers_t TYPE TABLE IS NUMBER;
l_numbers list_of_numbers_t: =.
list_of_numbers_t (1,2,3);
BEGIN
DBMS_OUTPUT. Put_line (l_numbers (1).) (COUNT);
END;
Error
Error report:
ORA-06550: line 7, column 38:
PLS-00487: Invalid reference to the variable 'NUMBER '.
ORA-06550: line 7, column 3:
PL/SQL: Statement ignored
06550 00000 - "line %s, column % s:\n%s".
* Cause: Usually a PL/SQL compilation error.
* Action:
I want to check the index 1 of my collection, but I get the above error. Can someone help me to remove this error. Thank you
Concerning
Matt
The collections have some counts; scalars don't.
l_numbers is a collection, so you can see the number of items contained in it like this:
DECLARE
List_of_numbers_t TYPE TABLE IS NUMBER;
l_numbers list_of_numbers_t: =.
list_of_numbers_t (1,2,3);
BEGIN
DBMS_OUTPUT. Put_line (l_numbers. (COUNT);
END;
/
l_numbers (1) , however, is just a scalar NUMBER, you can't use COUNT on it
In other words, l_numbers (1) is the number 1, so we can not say
DBMS_OUTPUT. Put_line (l_numbers. (COUNT);
for exactly the same reason that you can't say
DBMS_OUTPUT. Put_line (1. (COUNT);
-
I created a table and partitioned on the date of the entry and added a local partitioned index.
Now, I use a query to extract "num_rows" of user_tab_partitions to know the number of rows in each partition.
Getting this value as null num_rows, wonder why?
After looking to explain the Plan after interrogation ("select * from my_table1 where entry_date = 1 January 2015" ;))
to find out if she actually partitioned table and its data in different partitions, I interpreted in effect because the query plan had a line like Partition_range (Single).
My Question is:
(a) is actually partitioned data (have I misinterpreted the Explain plan)
(b) why is the num_rows null column in the query (Pasted below)
(c) also in addition what difference it would have been if I had created a Global Index instead of the Local Index in my case?
The following code Snippet:
----------------------------------------------------------------------------------------------
create the table my_table1
(
roll_no number constraint my_table1_pk primary key,
date of entry_date
)
partition of range (entry_date)
(
PARTITION data_p1 VALUES LESS THAN (TO_DATE (December 31, 2014 ',' DD-MM-YYYY ""));
PARTITION data_p2 VALUES LESS THAN (MAXVALUE)
);
create an index only my_table1_indx on my_table1 (entry_date) local;----------------------------------------------------------------------------------------------
I now insert two lines:
insert into my_table1 values (1, to_date ('01-01-2015', ' dd-mm-yyyy'));
insert into my_table1 values (2, to_date('01-02-2015','dd-mm-yyyy'));----------------------------------------------------------------------------------------------
These have been inserted successfully, now using the query below shows num_rows column as null. I don't know why?
SELECT table_name, num_rows, high_value, nom_partition
Of user_tab_partitions
where table_name = 'MY_TABLE1 '.
ORDER BY table_name, nom_partition;----------------------------------------------------------------------------------------------
(a) is actually partitioned data (have I misinterpreted the Explain plan)
Yes, it is partitioned. You can query this particular partition SELECT * FROM my_table1 (data_p1) PARTITION to check that.
(b) why is the num_rows null column in the query (Pasted below)
As already mentioned that you have not collected statistics.
(c) also in addition what difference it would have been if I had created a Global Index instead of the Local Index in my case?
In fact, you have created two types of indexes without knowing (can be)! One is not partitioned (although this column is not partition key) and another is partitioned (LOCAL). They are MY_TABLE1_PK and MY_TABLE1_INDX. You can check that USER_INDEXES.
You can read this article to get an early jump on the partitioning of decision. Partition: Partition decisions
-
number of rows fetch are not even
Hi all
I'm new to sql/plsql
Oracle version 11R2
RHL 5.0 OS
I'm deleting all rows in the parent table as well as children tables based on some criteria to date.
the parent BE_STATUS table contains a column OOC_DT. based on the OOC_DT I get BE_STATUSin the parent Table rows.
other children tables DOES NOT have OOCDT column but meet BENo. and BEDT WHO are also in PARENT TABLE BESTATUS.
So I get all the be_no, * be_dt * of BE_STATUS based on the OOC_DT column as below
and I create a temporary table based on the above query asselect distinct(count(*)) from be_status where ooc_dt between '31-mar-10' AND '24-dec-10'; (COUNT(*)) ---------- 65074
and then I count the number of rows in the temporary tablecreate table temp as select be_no, be_dt from be_status where ooc_dt between '31-mar-10' AND '24-dec-10'; table created.
so there are around 51 children tables that have the BE_NO AND BE_DTcolumn.select distinct(count(*)) from temp; (COUNT(*)) ---------- 65074
If the total number of lines in the temp must be equal to the total of all the lines in each column according to the above criteria.
It's
so, as you can see the TEMP TABLE contains only * 65074 *. Therefore the sum of the numbers of all of the above tables should be * 65074 * but only item_det containsselect distinct(count(*)) from be_penal where (be_no,be_dt) in (select be_no,be_dt from temp); (COUNT(*)) ---------- 64 select distinct(count(*)) from be_fine where (be_no,be_dt) in (select be_no,be_dt from temp); (COUNT(*)) ---------- 62 select distinct(count(*)) from be_cash_lic where (be_no,be_dt) in (select be_no,be_dt from temp); (COUNT(*)) ---------- 23 select distinct(count(*)) from c_cl_be where (be_no,be_dt) in (select be_no,be_dt from temp); (COUNT(*)) ---------- 2 select distinct(count(*)) from chex where (be_no,be_dt) in (select be_no,be_dt from temp); (COUNT(*)) ---------- 0 select distinct(count(*)) from amend_q where (be_no,be_dt) in (select be_no,be_dt from temp); (COUNT(*)) ---------- 0 select distinct(count(*)) from be_perm where (be_no,be_dt) in (select be_no,be_dt from temp); (COUNT(*)) ---------- 889 select distinct(count(*)) from exam_instr where (be_no,be_dt) in (select be_no,be_dt from temp); (COUNT(*)) ---------- 690 select distinct(count(*)) from c_rms_mesg where (be_no,be_dt) in (select be_no,be_dt from temp); (COUNT(*)) ---------- 64982 select distinct(count(*)) from item_duty_fg where (be_no,be_dt) in (select be_no,be_dt from temp); (COUNT(*)) ---------- 398129 select distinct(count(*)) from a_item_det where (be_no,be_dt) in (select be_no,be_dt from temp); (COUNT(*)) ---------- 31453 select distinct(count(*)) from item_det where (be_no,be_dt) in (select be_no,be_dt FROM temp); (COUNT(*)) ---------- 622271
* 622271 * lines.
I have made a mistake in counting the records individually?
waiting for your helpful answer
Thanks and greetingsNot quite sure, I followed your question, but a glaring fault in your codes...
between '31-mar-10' AND '24-dec-10';
dates should be treated as dates, not the chains and left us 2 years of numbers of programming standards waaay back in the 90's when everyone fixed these issues in the context of the challenges of the Millennium bug.
between to_date('31-mar-2010','DD-MON-YYYY') AND to_date('24-dec-2010','DD-MON-YYYY');
-
How can I get the number of rows in the table using Sunopsis API target in ODI 10 g?
Hi guys,.
In fact, I want to send an alert message as soon as the interface is run from a package. I've included alert OdiSendMail that sends an email once the interface is running.
Could someone please tell how to get the number of rows inserted into the table the Sunopsis API target.
I tried to use < % = odiRef.getNbRows () % >, but this has not worked for me. Since I am a beginner, could you please help out me
This is my mail to send ODI format
"The population of data managed to < % = odiRef.getSysDate () % >
Total of lines in the target table is: < - need an API code-> "
Kind regards
Clinton
Published by: LawrenceClinton on February 25, 2013 20:53Hello
Create the project with details below variable
Nom_de_variable: Total_Row_Count
Type of variable: Variable discount
Definition tab:
Data type: digital
Action: No persistentRefresh the tab:
Schema: provide the schema of your repository to work and beSELECT log.nb_row
THE journal of snp_step_log, snp_scen_step step
WHERE log.nno = step.nno
AND step.scen_no = (SELECT scen_no FROM snp_scen_step WHERE step_name='<%=odiRef.getPrevStepLog ('STEP_NAME") % > ')
AND log.sess_no = '< % = odiRef.getSession ("SESS_NO") % >' code at low
AND step.step_name = ' < % = odiRef.getPrevStepLog ("STEP_NAME") % > 'Note: add this variable after the stage of interface in your package (after the interface anywhere you can place), you can add this variable before ODISendEmailNotification in your package
call this varciable * #Total_Row_Count * in the Notification of ODISendEmail
for example :
Data has been fulfilled successfully in < % = odiRef.getSysDate () % >
Total no of lines filled are: * #Total_Row_Count *it will work
cordially,
Phanikanthedited by: Phanikanth on February 28, 2013 01:13
edited by: Phanikanth on February 28, 2013 01:14
-
Count the number of rows returned from each view in USER_VIEWS
For each USER_VIEWS view, I would return the name, creation date, last modified dateand the number of rows returned by this view.
Here's what I have so far:
Returns:col object_name format a20 select object_name, created, last_ddl_time from user_objects where object_type = 'VIEW'
How can I add a last column that counts the number of rows returned by this view?OBJECT_NAME CREATED LAST_DDL_TIME -------------------- --------- ------------- AISLE_AVG 11-FEB-12 11-FEB-12 COURSE_AVG 11-FEB-12 20-FEB-12 EXE_12_VIEW 11-FEB-12 21-FEB-12 L1_P2 17-FEB-12 17-FEB-12 L1_P3 17-FEB-12 17-FEB-12 L1_P4 17-FEB-12 17-FEB-12 L1_P5A 17-FEB-12 17-FEB-12 L1_P5B 17-FEB-12 17-FEB-12 LAB3_1A 12-FEB-12 20-FEB-12 LAB3_1B 12-FEB-12 20-FEB-12 LAB3_2A 12-FEB-12 20-FEB-12 LAB3_2B 12-FEB-12 20-FEB-12 LAB5_1 19-FEB-12 19-FEB-12 LAB5_2 19-FEB-12 19-FEB-12 LAB5_3 19-FEB-12 19-FEB-12 LAB5_4 19-FEB-12 19-FEB-12 LAB5_5 19-FEB-12 19-FEB-12 LAB5_TIMES 19-FEB-12 19-FEB-12 LAB6_1 19-FEB-12 19-FEB-12 LAB7_VIEW 20-FEB-12 20-FEB-12 PROGRAMS 11-FEB-12 21-FEB-12 STUDENT_GPA 11-FEB-12 21-FEB-12 22 rows selected
EDIT - here is a dump of my paintings, and here are my views.
Edit2 - this is possible by using the DECODE function, by chance?The function...
CREATE OR REPLACE FUNCTION view_row_count (view_name VARCHAR2) RETURN NUMBER AS retval NUMBER; BEGIN EXECUTE IMMEDIATE 'select count(*) from '||view_name INTO retval; RETURN retval; END view_row_count; /
And now the query...
select object_name, created, last_ddl_time, view_row_count(object_name) as view_row_count from user_objects where object_type = 'VIEW'
-
Download sql % number of rows on a table
We have
REMOVE from X WHERE Y = "aaa";
Dbms_output.put_line (number of rows sql %);
The above shows the number of deleted rows.
You want to load the value of rowcount % sql on a table. Using the below
INSERT IN the AUDIT (COUNTY) VALUES (number of rows sql %);
-error.
Please let me know how to load this value in an audit table. Thank youStore it in a variable after remove it and insert the contents of the variable by using the insert statement later.
HTH
Maybe you are looking for
-
Elite 7500 MT series: Audio
After you have reinstalled windows 10 I have I have no sound and I rceive message "Expensive voor geluidsweergave geinstalleerd Geen" (no audio installed) I can't find the driver and do not know the name of the audio app thank you for your help Ronni
-
BearShare was downloaded on this computer. It has been removed, however when I try to access my employer employee Web site, it appears in Bearshare and wont let me you on my account how to remove? original title: removal of bearshare
-
Hi guysI just decided to install updates for my inspiron 1521, downloading updates to date very well, but when it comes to install them while going through the files that it froze with the message!! 0xc01a001d! 28333/89662 (register/Machine/COMPONENT
-
Changed the domain to a different workgroup name cannot entry windows more.
My colleague from the Spain has a laptop and set a domain name, that is using at the office before Spain. Now, he came to the office of HK and changed the domain to another name of working group, after reboot, cannot entry the windows even more put t
-
deleteLater vs destroy QML dynamic objects
this thread I know its safe in C++ to use deleteLater(). even if the user creates a new before that was really destroyed the use of components that were created dynamically in QML I am always using. destroy() to remove in the most recent samples I no