Query to get the data of the column and the metadata in the same set of results.
Is it possible to build a query to get the values of the columns in a table and also be able to get some metadata (data type, data_length, data_precision, data_scale) for columns in the same set of results.If I use a join, have a common value to join on the two tables?
you use a cross join, not requiring common values.
create table T (n number, d date, v varchar2(30));
insert into T values (1,sysdate,'ABC');
commit;
select C.column_name, c.data_type, c.data_length,
case c.column_id
when 1 then to_char(T.N)
when 2 then to_char(T.D)
when 3 then T.V
end VALUE
from USER_TAB_COLUMNS C, T
where C.table_name='T'
order by c.column_id;
Tags: Database
Similar Questions
-
Total amount and are rotating back in the same set of results
I want to return a set of results in the following format:
where the total amount is the sum of the hours for all types of models grouped by yearmonth and columns of each model are the sum of hours per type of model grouped by yearmonth. I can get the correct results with the following query selects nested:YEARMONTH Total ModelA ModelB ModelC 200101 0 0 0 0 200102 10 5 5 0 200103 8 2 2 4
I was curious to try use the pivot function in Oracle 11 to get the same results and I am able to get all the results, EXCEPT the total number of hours by using the following query:select distinct yearmonth, sum(a.hours) as Total, (select sum(b.hours) from model_hours b where model = 'ModelA' and a.yearmonth = b.yearmonth) as ModelA, (select sum(b.hours) from model_hours b where model = 'ModelB' and a.yearmonth = b.yearmonth) as ModelB, (select sum(b.hours) from model_hours b where model = 'ModelC' and a.yearmonth = b.yearmonth) as ModelC from model_hours a group by yearmonth order by yearmonth
which returns this result:select * from ( select yearmonth, hours, model from model_hours a ) pivot ( sum(hours) for model in ('ModelA', 'ModelB', 'ModelC') ) order by yearmonth
I was not able to understand how to get the sum of hours for all models, grouped by yearmonth, in this result set also. Is this possible? And if yes, isn't - that's likely to be more effective than selects it nested? This particular table has some 200K lines right now.YEARMONTH ModelA ModelB ModelC 200101 0 0 0 200102 5 5 0 200103 2 2 4
Hello
As far as I know, the Oracle 11 SELECT... PIVOT function only works on mutually exclusive groups.
You can derive the total revolving data, like this:WITH pivoted_data AS ( select * from ( select yearmonth, hours, model from model_hours a ) pivot ( sum(hours) for model in ( 'ModelA' AS modela , 'ModelB' AS modelb , 'ModelC' AS modelc ) ) ) SELECT yearmonth , modela + modelb + modelc AS totla -- may need chnaging if values can be NULL , modela, modelb, modec FROM pivoted_data ORDER BY yearmonth ;
Published by: Frank Kulash, 26 March 2012 15:01
-
Can do us a query to get the same results of 3 tables
CREATE TABLE TABLE1 (NODEID VARCHAR2 (4));
CREATE TABLE TABLE2 (NODEID VARCHAR2 (4));
CREATE TABLE TABLE3 (NODEID VARCHAR2 (4));
INSERT INTO TABLE1 VALUE('1004');
INSERT INTO TABLE1 VALUE('1004');
INSERT INTO TABLE1 VALUE('1002');
INSERT INTO TABLE1 VALUE('1002');
INSERT INTO TABLE1 VALUE('1001');
INSERT INTO TABLE1 VALUE('1001');
INSERT INTO TABLE1 VALUE('1006');
INSERT INTO TABLE1 VALUE('1006');
INSERT INTO TABLE1 VALUE('1005');
INSERT INTO TABLE1 VALUE('1005');
INSERT INTO TABLE2 VALUE('1004');
INSERT INTO TABLE2 VALUE('1004');
INSERT INTO TABLE2 VALUE('1004');
INSERT INTO TABLE2 VALUE('1002');
INSERT INTO TABLE2 VALUE('1002');
INSERT INTO TABLE2 VALUE('1002');
INSERT INTO TABLE2 VALUE('1002');
INSERT INTO TABLE 3 VALUE('1001');
INSERT INTO TABLE 3 VALUE('1001');
INSERT INTO TABLE 3 VALUE('1006');
INSERT INTO TABLE 3 VALUE('1006');
INSERT INTO TABLE 3 VALUE('1005');
INSERT INTO TABLE 3 VALUE('1005');
INSERT INTO TABLE 3 VALUE('1004');
INSERT INTO TABLE 3 VALUE('1004');
INSERT INTO TABLE 3 VALUE('1004');
INSERT INTO TABLE 3 VALUE('1002');
INSERT INTO TABLE 3 VALUE('1002');
INSERT INTO TABLE 3 VALUE('1002');
INSERT INTO TABLE 3 VALUE('1002');
SELECT count (*), count (distinct nodeid)
of table1, table2, table3
where table1.nodeid = table2.nodeid and table1.nodeid = table3.nodeid;
SELECT count (*), count (distinct nodeid)
FROM table1, table3
where table1.nodeid = table2.nodeid;
SELECT count (*), count (distinct nodeid)
from table2, table3
where table2.nodeid = table3.nodeid;SQL> SELECT MAX (CASE WHEN row_ind = 1 THEN ct END) ct_1, 2 MAX (CASE WHEN row_ind = 1 THEN distinct_ct END) distinct_ct_1, 3 MAX (CASE WHEN row_ind = 2 THEN ct END) ct_2, 4 MAX (CASE WHEN row_ind = 2 THEN distinct_ct END) distinct_ct_2, 5 MAX (CASE WHEN row_ind = 3 THEN ct END) ct_3, 6 MAX (CASE WHEN row_ind = 3 THEN distinct_ct END) distinct_ct_3 7 FROM (SELECT 1 AS row_ind, 8 COUNT (*) ct, 9 COUNT (DISTINCT table1.nodeid) distinct_ct 10 FROM table1, table2, table3 11 WHERE table1.nodeid = table2.nodeid 12 AND table1.nodeid = table3.nodeid 13 UNION ALL 14 SELECT 2 AS row_ind, COUNT (*), COUNT (DISTINCT table1.nodeid) 15 FROM table1, table3 16 WHERE table1.nodeid = table3.nodeid 17 UNION ALL 18 SELECT 3 AS row_ind, COUNT (*), COUNT (DISTINCT table2.nodeid) 19 FROM table2, table3 20 WHERE table2.nodeid = table3.nodeid) 21 / CT_1 DISTINCT_CT_1 CT_2 DISTINCT_CT_2 CT_3 DISTINCT_CT_3 ---------- ------------- ---------- ------------- ---------- ------------- 50 2 26 5 25 2
There may be an easier way...
-
I need assistance of query SQL, a query to get the same without union clause
EmpNo, ename sum (sal) sum (deptno)
200-2000-10 Tom
201 3000 10 smith
Alfred 202 20 3000
40 8000 totalselect NVL(TO_CHAR(employee_id), 'Total'), max(last_name), sum(salary), sum(department_id) from employees group by rollup(employee_id), ()
-
How to write a simple select query to get the data of the table as an XML.
How to write a simple select query to get the data of the table as an XML. In the query, I'm just adding items below which i need be there in the XML document
I have need to add the root tag as well in the beginning and the end of < root > < / root > this xml file. Please advice if this is possible with the select queryselect '<test_tag>'||EMP_NAME||'</test_tag>','<date>'||sysdate||'</date>' from temp_table where id_num BETWEEN 1 AND 10;
without using XMLGEN, XMLQUERY or any other packages built and function?I need to URL escapes with the UTF-8 code points that we have already achieved using the utl_http package. Please help how to do that without using the utl_http package.
What is wrong with him?
At present, the only way I can think of to avoid a call to UTL_HTTP. SET_BODY_CHARSET is to write your own little wrapper.
In this way, you can specify the Boolean parameter or omit it if you choose to use named parameters:SQL> create or replace function my_url_escape (url in varchar2) 2 return varchar2 3 deterministic 4 is 5 begin 6 return utl_url.escape(url, false, 'AL32UTF8'); 7 end; 8 / Function created SQL> select my_url_escape('http://some.uri.com/param?lang=fr&text=contrôle') from dual; MY_URL_ESCAPE('HTTP://SOME.URI -------------------------------------------------------------------------------- http://some.uri.com/param?lang=fr&text=contr%C3%B4le
-
SQL query to get the NULL records after the last matching flag
I have a xx1 table with id and flag columns. So I want the data in this table, after the last flag matched. I want that data to id 7 in the rooms. Even if the id 2,3,5 are null flag 'Y' was at 6. ID so I need a query to get the data of the xx1 table after the last correspondence flag (from 7 to 9 id).
SQL > create table xx1
2 (identification number,
3 flag varchar2 (10));
Table created.
SQL > insert into xx1 values (1, 'Y');
1 line of creation.
SQL > insert into values xx1 (2, null);
1 line of creation.
SQL > insert into values xx1 (3, null);
1 line of creation.
SQL > insert into xx1 values (4, 'Y');
1 line of creation.
SQL > insert into values xx1 (5, null);
1 line of creation.
SQL > insert into xx1 values (6, 'Y');
1 line of creation.
SQL > insert into values xx1 (7, null);
1 line of creation.
SQL > insert into values xx1 (8, null);
1 line of creation.
SQL > insert into values xx1 (9, null);
1 line of creation.
SQL > select * from xx1.
FLAG OF THE ID
---------- ----------
1. IS
2
3
4. IS
5
6. IS
7
8
9
9 selected lines.
SQL >
Hello
user11164339 wrote:
Hi Frank - when I run the query, I don't see the results data.
I get
FLAG OF THE ID
----- ----------
7
8
9
What you do differently?
-
Query to get the total counts in the given scenario
Hello
I use Oracle 10 g
I have a table with the following data
AgId Trm CD S
-------------------------------------------------
A 1000 100010, 12 - JAN
A 1000 100019, 20 - MAR
1000 100019 D 20-JUL
-------------------------------------------------
1001 100011 25-JAN HAS
1001 100011 D 20 - FEB
A 1001 100011, 23 - MAR
1001 100012 A 31 - JAN
-------------------------------------------------
1002 100013 A 14 - FEB
D 1002 100013 05 - APR
1002 100015 02-MAY HAS
-------------------------------------------------
A 1003 100014, 03 - MAR
1003 100014 D 25 - MAR
-------------------------------------------------
1004 100016 HAS 22 - MAY
1004 100017 21 - JUN HAS
A 1004 100018, 01 - JULY
-------------------------------------------------
1005 100020 D 21-MAY
1005 100020 HAS 21-JUL
1005 100020 D 11 - AUG
Here the overall status of AgId '1000' is A as it is to have at least 1 active Trm
Similarly, the status of AgId '1001' is A
status of AgId '1002' is A
But, the AgId '1003' is D its CRT is disconnected after activation (according to the date column 'CD')
Then, the status of AgId '1004' is A
and finally AgId '1005' is new D as its CRT disabled, active and disabled finally
Therefore, taking into account these criteria can someone give me a query to get (not AgId, who are 'Assets') and similarly 'disabled '.
-
IOM sql Query to get the status of the failed task
Hello world
We have an obligation as we need to get the status of a particular task (say Create User in OID - Completed\Rejected status resource) for the particular user. We are able to get the status of the provisioed of resources to the user but not the status of the special mission which is trigerred for the user.can someone put some light on it. We must have the SQL query to do this.
Thanks in advance.
Kind regards
MKNHello
Use this query to get the status of the task, also check the coomentsSELECT USR. USR_LOGIN, OSI. SCH_KEY, ANN. SCH_STATUS, STA. STA_BUCKET OF
OSI, CHS, STA, MIL, TOS, PKG, OUEDRAOGO, USR, OBJ, OST
WHERE OSI.MIL_KEY = MIL.MIL_KEY
AND ANN. SCH_KEY = OSI. SCH_KEY
AND STA. STA_STATUS = SCH. SCH_STATUS
AND TOS. PKG_KEY = PKG. PKG_KEY
AND MIL. TOS_KEY = TOS. TOS_KEY
AND OUÉDRAOGO. USR_KEY = USR. USR_KEY
AND OUÉDRAOGO. OST_KEY = OST. OST_KEY
AND OST. OBJ_KEY = OBJ. OBJ_KEY
AND OSI. ORC_KEY = OUEDRAOGO. ORC_KEY
AND OBJ. OBJ_NAME = "User AD".
AND OST. OST_STATUS = "Provisioning" - filter accordinglly
AND STA. STA_BUCKET = 'pending' - filter accordinglly
AND PKG. PKG_NAME = "AD User" - filter accordinglly
AND MIL.MIL_NAME = 'System' - filter accordinglly Validation
;
Thank you
Kuldeep -
Need a sql query to get several dates in rows
Hi all
I need a query to get the dates of the last 7 days and each dates must be in a line...
but select sysdate double... gives a line...
Output of expexcted
Dates:
October 1, 2013
30 sep-2013
29 sep-2013
28 sep-2013
27 sep-2013
26 sep-2013
Try:
SQL > SELECT sysdate-7 + LEVEL FROM DUAL
2. CONNECT BY LEVEL<=>=>
3 * ORDER BY 1 DESC
SQL > /.
SYSDATE-LEVEL 7 +.
-----------------------------
October 1, 2013 13:04:52
30 - Sep - 2013 13:04:52
29 - Sep - 2013 13:04:52
28 - Sep - 2013 13:04:52
27 - Sep - 2013 13:04:52
26 - Sep - 2013 13:04:52
25 - Sep - 2013 13:04:52
7 selected lines.
-
Since a couple of days I get the same error message: "a script on this page may be busy, or it may have stopped responding." You can stop the script now, open the script in the debugger, or let the script continue. »
I'm not a COMPUTER expert, however, I have read similar online messages and tried many steps such as:
--deleting history navigation and cookies
-Mozilla resetting to the factory settings
-Uninstall and reinstall MozillaUnfortunately, the problem is always the same. What can I do? I work from home and need internet to work 100%.
Moreover, the navigation works fine in other browsers, but not Mozilla.
Thank you
This script is the culprit in the following message?
A script on this page may be busy, or it may have stopped responding. You can stop the script now, open the script in the debugger or let the script.
Script: resource://gre/modules/addons/XPIProvider.jsm-> jar:file:///C:/Program%20Files/Mozilla%20Firefox/browser/extensions/%7B82AF8DCA-6DE9-405D-BD5E-43525BDAD38A%7D.xpi!/bootstrap.js-> resource://gre/modules/commonjs/toolkit/loader.js-> resource://gre/modules/commonjs/sdk/loader/sandbox.js-> resource://skype_ff_extension-at-jetpack/skype_ff_extension/data/jquery-2.1.0.min.js:28
-
Old version of Firefox running. Tried to update and get the message that a previous version has not finished installing and computer needs to reboot to finish. I restart, then try to install the new version, but just get the same error. I also tried to uninstall and start again, but got the same exact message he needed to finish the update before it could be installed.
Suggestions?
Thank you!Do a cleaning (re) install and delete the folder of the program Firefox (C:\Program Files\Mozilla Firefox\).
Download a new copy of Firefox and save the file to the desktop.
- Firefox 8.0.x: http://www.mozilla.com/en-US/firefox/all.html
Uninstall your current version of Firefox if possible.
- Do NOT remove the data of a personal nature when you uninstall the current version or you lose your bookmarks and other data in the profile folder.
Delete the program folder Firefox before installing newly downloaded copy of the Firefox installer.
- It is important to remove the Firefox program folder to delete all the files and make sure that there is no problem with the files that were the remains after uninstallation.
Your bookmarks and other profile data stored in the Firefox profile folder and will not be affected by a relocation, but make sure that you do not select delete data of a personal nature if you uninstall Firefox.
-
When my DVD drive would not work, I bought an external. I get the same message when I go into properties. Pilots have been disabled.
Hello
Check with the manufacturer of the system, their online documentation and drivers, diagnostics, and
Ask problems known in their forums. You may also check those similar
resources on the site of the manufacturer of the actual device (for the original drive).=================================================================
It is not surprising that the same issue affects the old and the new drive.
This problem may be caused by the presence of too many CD/DVD programs competing for resources,
especially by these programs that run at startup.Even if the error is not Code 22 check these:
Code 22
http://TechNet.Microsoft.com/en-us/library/cc731267 (v = ws.10) .aspxHow to fix the Code 22 errors
http://pcsupport.about.com/od/errorc/a/code-22-error.htmHow to enable a device in Device Manager in Windows Vista
http://pcsupport.about.com/od/windowsvista/HT/enabledevvista.htmIf necessary:
Step 1: Please do all the same underneath if you did some before as is often total
a process that solves the problem.Try this - Panel - Device Manager - CD/DVD - double click on the device - driver tab.
Click on update drivers (this will probably do nothing) - RIGHT click ON the drive - uninstall.
RESTART this will refresh the default driver stack. Even if the reader does not appear to continue
below.
Then, work your way through these - don't forget the drive might be bad, could be a coward
cable or slight corrosion on the contacts (usually for a laptop) and other issues.Your CD or DVD drive is missing or is not recognized by Windows or other programs
http://support.microsoft.com/kb/314060 - a Mr FixitTry this fix manually if the Fixit 314060 does not work
http://www.pchell.com/hardware/cd_drive_error_code_39.shtmlYour CD or DVD drive is missing or is not recognized by Windows or other programs-
a Mr Fixit
http://support.Microsoft.com/kb/982116The CD drive or the DVD drive does not work as expected on a computer that you upgraded to
for Windows Vista
http://support.Microsoft.com/kb/929461When you insert a CD or a DVD, Windows Vista may not recognize the disc
http://support.Microsoft.com/kb/939052Your CD or DVD drive cannot read or write media - A Mr Fixit
http://support.Microsoft.com/GP/cd_dvd_drive_problemsCD/DVD drive does not appear in Windows Vista, or you receive this error in Windows
Vista installation after booting from the DVD (AHCI)
http://support.Microsoft.com/kb/952951
Drive CD - R or CD - RW Drive is not recognized as a recordable device
http://support.Microsoft.com/kb/316529/Hardware devices not detected or not working - A Mr Fixit
http://support.Microsoft.com/GP/hardware_device_problemsAnother possibility is that the cables are loose. Remove ALL power, then make sure that the cables in both
ends. Remove and replace, do not just tight. For laptops, you can often clean power and
contacts data with a pencil eraser.Some DVD players do not use the Windows default drivers so check with the manufacturer of system and
manufacturer of device to see if there is a firmware or drivers for your drive if necessary.===============================
Step 2: You have disc problems as the CD/DVD is actually 4 discs in 1 case (CD & DVD
Burn and CD and DVD read). So it is not unusual for 1 or 2 operational so that other parts
do it right.Did you follow the Troubleshooting Guide for the reader who still does not work? There are
the entries in registry that the troubleshooter does not solve and those who "might" be the cause.Check with your Maker system and a device for the two possible firmware updates and
the correct registry entries for your car.Here are the keys that I of course are those in question - for the subkeys of the CD/DVD drive
as there will be other subkeys in these keys. Do not forget to ask specific keys involved as well as
the parameters.HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\IDE
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Hardware Profiles\0001\System\CurrentControlSet\Enum\IDE
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\ {4D36E965-E325-11CE-BFC1-08002BE10318}
-----------------------------------------------------------------------
You can probably find more info here and maybe even the exact registry for your CD/DVD settings
drive from someone with the same model.Forums - a lot of expert real help
http://Club.myce.com/CD/DVD units
http://www.myce.com/storage/Use DevManView to locate the CD/DVD in the registry (be careful and do a prior Restore Point)
nothing change) - find the DevManView device and then make a right click on it free in RegEdit.DevManView - free - an alternative to the standard Windows Device Manager, which displays all the
devices and their properties in flat table, instead of the tree viewer
http://www.NirSoft.NET/utils/device_manager_view.htmlI hope this helps.
Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle="" -="" mark="" twain="" said="" it="">->
-
Query with almost the same query as a subquery, can it be optimized?
I have a query using almost a duplicate of itself (table 1) as a subquery, and I wonder if it can be rewritten better, like she just doesn't seem the right way to do it, but everything I try I can't get the same number of lines back.
If anyone can see a better way, it would be a great help.
Thank you very much
Surely it is not the best way to write it as you use the same table twice and restrictions?SELECT t.pol_number||t.check_digit FROM transactions t, policies p, funds f WHERE f.fnd_code = t.trn_fnd_code AND t.trn_pol_number = p.pol_number AND p.pol_status IN (1,2) AND t.trn_status = 'NEW' AND t.trn_trn_number IN (SELECT t2.trn_trn_number FROM transactions t2, policies p2 WHERE t2.trn_pol_number = p2.pol_number AND p2.pol_status IN (1,2) AND t2.trn_status = 'NEW' AND t2.trn_fnd_code = :PARAMETER)
Published by: Scott Hillier on March 16, 2010 15:11It looks like you want all the lines of the siblings who do not personally meet the restriction on trn_fnd_code. You can use analytical functions;
not tested
select * from (select pol_number || check_digit col1, max(case when t.trn_fnd_code = :parameter then 1 else 0 end) over(partition by trn_trn_number) max_trn_number from transactions t, policies p, funds f where f.fnd_code = t.trn_fnd_code and p.pol_status in (1, 2) and t.trn_status = 'NEW') where max_trn_number = 1;
-
why I can not get the same apps I have on my iPad?
why I can not get the same apps I have on my iPad?
Because they are different versions for different operating systems.
-
Why I get the same messages even after compaction?
I read my mail in the AM and remove most but will get the same messages still sometimes two or three times. I'm doing a click right and hit compact several times a day. There has been talk for a month or two?
To diagnose problems with Thunderbird, try one of the following:
- Restart Thunderbird with disabled modules (Thunderbird Safe Mode). On the Help menu, click "restart with disabled modules. If Thunderbird works as usual, there is an add-on or theme interfere with normal operations. You will need to reactivate the modules one at a time until you locate the offender.
- Restart the operating system in safe mode with network. This loads only the basics needed to start your computer while allowing Internet access. Click on your operating system for instructions on how to start in safe mode: Windows 8, Windows 7, Windows Vista, Windows XP, OSX
- If the safe mode for the operating system to resolve the problem, there are other software on your computer that is causing problems. The possibilities include but not limited to: AV scanning, virus/malware, background downloads such as updates of the program.
Maybe you are looking for
-
Since the update of my MacBook Pro to El Capitan, the sleep function has stopped working. The screensaver comes into play as it always has, but he just continues to run unless the laptop is closed. Energy saving: sleep display is set for 10 minutes.
-
Updated video/graphics in the computer 6910p hp laptop?
Hi all Is it still possible? I really like the computer and wants to improve the graphics if possible!
-
part of Windows server 2003 none. X 09-45627
I lost my cd key for windows server 2003: part No. X 09-45627 how I can get it can mail me on * address email is removed from the privacy *
-
KB2742597 will not be installed
KB2742597 does not install and will not stop trying. I have windows XP service pack 3
-
This laptop is not equipped with an optical drive, however remove the bezel reveals a Sata connector. Someone knows what optical drive can be compatible? It is in the family of E1-572/570/532/510, so I was wondering if these drives might work. Apprec