Adding a dummy field to an oracle sql query
Hi, I'm trying to build a select statement that incorporates two dummy fields of text in the output so I can load this output to another system.
The first two fields of text I want to be the "dummy" text fields and each record should have "Budget, Final" as the first two fields of text for each row.
here's what I currently have and I'm having problems with:
select
'Budget' as "Scenario",'Final' as "Version",pa_id as "NewWells8",budget_status as "Wedge",year as "Year",month as "Months",ac_gross_gas_vol as "AC_Gross_Gas_Vol",ac_gross_oil_vol as "AC_Gross_Oil_Vol",ac_net_gas_vol as "AC_Net_Gas_Vol",ac_net_oil_vol as "AC_Net_Oil_Vol",ac_gross_condensate_vol,ac_net_condensate_vol,ac_total_capital_investment,nri_percent_oil,nri_percent_gas,gwi_percent,bpo_wi,bpo_nri,apo_wi,apo_nri
from
xxx_tablename;
this query sort of works but what I get is just a header row that says 'Scenarioo' and 'Final' but below that header row each of those two fields is blank. All other fields display data correctly.
/* Formatted on 5/24/2011 1:30:55 PM (QP5 v5.149.1003.31008) */
WITH my_table AS (SELECT NULL col1, NULL col2 FROM DUAL
UNION /**/ ALL
SELECT NULL, NULL FROM DUAL
UNION /**/ ALL
SELECT '1', ' 2' FROM DUAL
UNION /**/ ALL
SELECT '3', ' 4' FROM DUAL)
SELECT NVL (col1, 'dummy data1') column1_alias,
NVL (col2, 'dummy data2') column2_alias,
'dummy data3' pseudo_column
FROM my_table
COLUMN1_ALIAS COLUMN2_ALIAS PSEUDO_COLUMN
dummy data1 dummy data2 dummy data3
dummy data1 dummy data2 dummy data3
1 2 dummy data3
3 4 dummy data3Edited by: pollywog on May 24, 2011 1:33 PM
Edited by: pollywog on May 24, 2011 1:35 PM
Similar Messages
-
Field value retrieve from sql query
Hi,
Is there any way to code sql query into form field in rtf template ?.
I have converted an oracle report to BI publisher (e-business suite R12) but I have a form field that contain a sql query that retrieve a value from database. I don't know how to code sql query in form field in rtf template.
Thanks for help,http://winrichman.blogspot.com/search/label/cross%20tab
http://winrichman.blogspot.com/search/label/Cross-tab
http://winrichman.blogspot.com/search/label/Dynamic%20column -
Why does Oracle SQL query returning a date field without the time component
Hi,
I'm a novice SQL user & hv just installed Oracle SQL developer (Version 3.0.04, Build MAIN-04.34).
I made the same SQL query using "Oracle SQL developer" & "TOAD for Oracle 9.0.1" but I got 2 different format on the same date field:
On TOAD, I get the date field extracted as *04/26/2011 23:12:58*
On Oracle, I get the date field extracted as *26/APR/11*
Why is the Oracle result in a different format & missing the time component?
Is there any option/preference that I need to set in Oracle SQL developer to get the full date/time format displayed?
I've tried to set my the date format to DD/MON/RR HH12:MI:SSXFF AM under the preference -> database NLS but I still get the same format!
Plse help!hokim wrote:
Hi,
I'm a novice SQL user & hv just installed Oracle SQL developer (Version 3.0.04, Build MAIN-04.34).
I made the same SQL query using "Oracle SQL developer" & "TOAD for Oracle 9.0.1" but I got 2 different format on the same date field:
On TOAD, I get the date field extracted as *04/26/2011 23:12:58*
On Oracle, I get the date field extracted as *26/APR/11*
Why is the Oracle result in a different format & missing the time component?
Is there any option/preference that I need to set in Oracle SQL developer to get the full date/time format displayed?
I've tried to set my the date format to DD/MON/RR HH12:MI:SSXFF AM under the preference -> database NLS but I still get the same format!
Plse help!http://edstevensdba.wordpress.com/category/nls_date_format/ -
Problem using alias field names in a sql query
Hello,
I have a question regarding a simple Oracle database SQL query writeup:
In the following (badly written but properly working) SQL query:
Query 1:
select
soe.field1,
(soe.field2 + soe.field3) as field4,
(soe.field5 - (soe.field2 + soe.field3)) as field6,
(select comp.parValue*soe.field7
from
CompTable comp) as parValue,
(select soe.field8 - (comp.parValue*soe.field7+ soe.field9)
from
CompTable comp) as field10
from
SomeTable soe
PROBLEM 1:
I am re writing the code (soe.field2 + soe.field3) to get the alias field4 or column name field4 that I have created on the fly in the previously for use with the following fields. Can't I rewrite the query as follows. There is something simple missing!
Query 2:
select
soe.field1,
(soe.field2 + soe.field3) as field4,
soe.field5 - field4 as field6, <<< field4 does not work here
(select
comp.parValue*soe.field7
from
CompTable comp) as parValue,
(select
soe.field8 - (comp.parValue*soe.field7+ soe.field9)
from
CompTable comp) as field10
from
SomeTable soe
PROBLEM 2:
Similar to the above problem, I was thinking to get a field parValue out of the CompTable table and re-use many times rather than the code shown in Query 1:
Query 3:
select
soe.field1,
(soe.field2 + soe.field3) as field4,
soe.field5 - field4 as field6,
soe.field7* (select comp.parValue from CompTable comp) as parValue1,
soe.field8 - (parValue1*soe.field7+ soe.field9) as field10 <<<< parvalue1 does not work here
parValue1*soe.field9 as TaxCondition <<<< parvalue1 does not work here
from
SomeTable soe
See that the query becomes so simple, but the above query does not work. There is something fundamentally wrong in my usage of the alias field names in creating other fields. The Query1 seems to be the only working option but its very slow as I am redoing and re-writing the whole code again and again to get the parValue field out of the CompTable table for use to create many other fields.
I will appreciate if you can guide me in the right direction on this issue.
Thanks and Regards
RamaSELECT tmp.contract_no, tmp.Actual, tmp.Actual - tmp.NbHours
FROM ( SELECT t.contract_no, sum(l.hrs) AS Actual, (c.labour_hours * c.labour_progress_per) / 100 AS NbHours
FROM TASK_DELEGATION t
INNER JOIN COST_CODE c
ON t.cost_code = c.cost_code AND t.contract_no = c.contract_no AND t.is_inactive=0
INNER JOIN Labour.dbo.LABOURALLOT l
ON l.contractNo = c.contract_no AND l.costcode = c.cost_code AND l.pm = 'N'
GROUP BY t.contract_no, c.labour_hours, c.labour_progress_per
) tmp -
Clarification on using function in where clause of oracle sql query
I have an issue in regarding function using where clause of sql query..
We are facing performance issue while executing query, so in what ways to improve the performance of the query which i have posted below.
select col ,case when my_function(parameter)
from tab1 a ,tab2 b,tabl3 c
where a.column1=b.column2
and b.column3 =c.column6
and my_function(parameter)>0
Regards
Dinesh
Edited by: wild fire on May 18, 2012 4:15 PMDinesh,
remind that when you use a function in the where clause it normally will get started for each record in the table.
So your answer is two-fold:
1. make the function only start when needed by adding a function based index on the table (this will make inserts and updates slower)
2. make the function faster by adding the DETERMINISTIC clause if possible. this will make Oracle "cache" the result of the function.
Regards,
Richard
blog: http://blog.warp11.nl
twitter: @rhjmartens
If this question is answered, please mark the thread as closed and assign points where earned.. -
Oracle Sql Query issue Running on Different DB Version
Hello All,
I have come into situation where we are pruning sql queries on different DB version of Oracle and have performance issue. Let me tell you in brief and i really appreciate for your prompt response as its very imperative stuff.
I have a query which is running on a DB of version 7.3.4 and it takes around 30 mins where as the same query when run on 8i it takes 15sec., its a huge difference. I have run the statistics to analyze on 7.3 and its comparatively very high. Question here is, the sql query trys to select data from same schema table and 2 tables from another DB using DB link and 2 other tables from another DB using DB link.So,how can we optimize this stuff and achieve this run as same time as 8i DB in 7.3. Hope i am clear about my question, Eagerly waiting for your replies.
Thanks in Advance.
Message was edited by:
Ram8Difficult to be sure without any more detailed information, but I suspect that O7 is in effect copying the remote tables to local temp space, then joining; 8i is factoring out a better query to send to the remote DBs, which does as much work as possible on the remote DB before shipping remaining rows back to local.
You should be able to use EXPLAIN PLAN to identify what SQL is being shipped to the remote DB, If you can't (and it's been quite a while since I tried DB links or O7) then get the remote DBs to yourself, and set SQL_TRACE on for the remote instances. Execute the query and then examine the remote trace files, And don't forget to turn off the tracing when you're done.
Of course it could just be that the CBO got better,,,
HTH - if not, post your query and plans for the local db, and the remote queries.
Regards Nigel -
Oracle SQL Query from EXCEL 2007 with prompt
Hello,
I have many excel reports where I am pulling information from our Oracle 9 db through Excel using the following method:
http://blog.mclaughlinsoftware.com/microsoft-excel/how-to-query-oracle-from-excel-2007/
http://blog.mclaughlinsoftware.com/2009/11/30/sql-query-in-excel-2007/
However, I am having trouble when I try the following query due to the prompt:
SELECT
IM.ITEM_GROUP,
IM.ITEM,
IM.DESCRIPTION
FROM
LAWSON.ITEMMAST IM
WHERE
IM.ITEM = '&ITEM';
Does any one know how I can connect a prompt to an excel cell and then pass the query on to Oracle, or have a PL SQL prompt work from Excel?
Thanks,
BenThe 'prompt' as you call it is a sqlplus feature, so does not belong to the SQL language
You would need to write a stored procedure returning a resultset.
create or replace procedure foo(rc in out sys_refcursor, p_item) as
begin
open rc for
'SELECT
IM.ITEM_GROUP,
IM.ITEM,
IM.DESCRIPTION
FROM
LAWSON.ITEMMAST IM
WHERE
IM.ITEM = '||p_item;
end;
and call that using ODBC or asp.net
Obviously this is profusely documented.
Sybrand Bakker
Senior Oracle DBA -
Oracle SQL query for getting specific special characters from a table
Hi all,
This is my table
Table Name- Table1
S.no Name
1 aaaaaaaa
2 a1234sgjghb
3 a@3$%jkhkjn
4 abcd-dfghjik
5 bbvxzckvbzxcv&^%#
6 ashgweqfg/gfjwgefj////
7 sdsaf$([]:'
8 <-fdsjgbdfsg
9 dfgfdgfd"uodf
10 aaaa bbbbz#$
11 cccc dddd-/mnm
The output has to be
S.no Name
3 a@3$%jkhkjn
5 bbvxzckvbzxcv&^%#
7 sdsaf$([]:'
8 <-fdsjgbdfsg
10 aaaa bbbbz#$
It has to return "Name" column which is having special characters,whereas some special chars like -, / ," and space are acceptable.
The Oracle query has to print columns having special characters excluding -,/," and space
Can anyone help me to get a SQL query for the above.
Thanks in advance.You can achieve it in multiple ways. Here are few.
SQL> with t
2 as
3 (
4 select 1 id, 'aaaaaaaa' name from dual union all
5 select 2 id, 'a1234sgjghb' name from dual union all
6 select 3 id, 'a@3$%jkhkjn' name from dual union all
7 select 4 id, 'abcd-dfghjik' name from dual union all
8 select 5 id, 'bbvxzckvbzxcv&^%#' name from dual union all
9 select 6 id, 'ashgweqfg/gfjwgefj////' name from dual union all
10 select 7 id, 'sdsaf$([]:''' name from dual union all
11 select 8 id, '<-fdsjgbdfsg' name from dual union all
12 select 9 id, 'dfgfdgfd"uodf' name from dual union all
13 select 10 id, 'aaaa bbbbz#$' name from dual union all
14 select 11 id, 'cccc dddd-/mnm' name from dual
15 )
16 select *
17 from t
18 where regexp_like(translate(name,'a-/" ','a'), '[^[:alnum:]]');
ID NAME
3 a@3$%jkhkjn
5 bbvxzckvbzxcv&^%#
7 sdsaf$([]:'
8 <-fdsjgbdfsg
10 aaaa bbbbz#$
SQL> with t
2 as
3 (
4 select 1 id, 'aaaaaaaa' name from dual union all
5 select 2 id, 'a1234sgjghb' name from dual union all
6 select 3 id, 'a@3$%jkhkjn' name from dual union all
7 select 4 id, 'abcd-dfghjik' name from dual union all
8 select 5 id, 'bbvxzckvbzxcv&^%#' name from dual union all
9 select 6 id, 'ashgweqfg/gfjwgefj////' name from dual union all
10 select 7 id, 'sdsaf$([]:''' name from dual union all
11 select 8 id, '<-fdsjgbdfsg' name from dual union all
12 select 9 id, 'dfgfdgfd"uodf' name from dual union all
13 select 10 id, 'aaaa bbbbz#$' name from dual union all
14 select 11 id, 'cccc dddd-/mnm' name from dual
15 )
16 select *
17 from t
18 where translate
19 (
20 lower(translate(name,'a-/" ','a'))
21 , '.0123456789abcdefghijklmnopqrstuvwxyz'
22 , '.'
23 ) is not null;
ID NAME
3 a@3$%jkhkjn
5 bbvxzckvbzxcv&^%#
7 sdsaf$([]:'
8 <-fdsjgbdfsg
10 aaaa bbbbz#$
SQL> -
Convert Oracle SQL Query to SQLite Query
Hi,
I am new to SQLite and have requirement to write quries in SQLite format. As table structure is same in both the Oracle and SQLite database i have created queries in Oracle SQL. Now wanted to know is there any tool or package available which will convert my simple Oracle queries into SQLite format???
Please guide..
Regards,
Priyankawith tree as (
select
level lev
,id
,parent_id
,sys_connect_by_path(id, '-') p
from test_temp
connect by
parent_id = prior id
start with parent_id is null
select
from tree t1
where exists (
select 1
from tree t2
where substr(t2.p, 1, length(t1.p)) = t1.p
and regexp_count(t2.p, '-') = regexp_count(t1.p, '-') + 2
-- if regexp_count is not available in your version or performs not well, below is an alternative
-- and length(t2.p) - length(replace(t2.p, '-')) = length(t1.p) - length(replace(t1.p, '-')) + 2
LEV
ID
PARENT_ID
P
1
1
-1
2
3
1
-1-3
2
5
1
-1-5
1
2
-2
2
6
2
-2-6
3
14
6
-2-6-14 -
Adding some new fields for display in SAP Query
I need to add some fields for display in SAP query 01 of infoset /SAPQUERY/AM01. So I have changed the infoset by checking the additional fields which is already in LDB. Then I created the query by copying the 01 of infoset /SAPQUERY/AM01 to Zusergroup with reference to the same infoset. In the newly created query, I am just checking the newly added field in Basic list. If I generate the program for this query, I get a error.
Pls let me know how should I rectify this.
Regards,
JeyananthHi,
Before generating the query, adjust the query from the menu of SQ01
Thanks
Shiva -
Width of field in Report From SQL Query
I have created a report from SQL query with 15 columns being selected. However, no matter what column width and column type (pixel, char, percent) I enter in the column formatting tab of the report, I cannot get the report to format the column to the width I desire. It is always a fixed width. Does anyone have any suggestions?
Thanks,
MartinHi,
Char (used for ASCII format)
Displays the output in the specified number of
characters per line. For example, if you enter 20
in Width, the report displays 20 characters of the
column data in each line. If the number of
characters per line exceeds the specified
number, the remaining characters are wrapped
to the next line.
Pixel
Displays the output in the specified number of
pixels per row. For example, if you enter 10 in
Width, the column data displays 10 pixels of
data per line of the displayed table.
Percent
Displays the output in the specified percentage
of the table. For example, if you enter 25 in
Width, the column data displays in 25% of the
displayed table.
Thanks,
Sharmila -
Oracle sql query execute in the apex
hi:
my requirement is, in region i have one text area item and query button.
in this text area i am typing the any sql query and when i am pressing the query button it should display the query output report..
pls give solution fast as soon as possible....
Message was edited by:
anbarasanHi anbarasan,
Maybe you can create a report of type "SQL query (PL/SQL Function returning query". Then in the region source, something like:
DECLARE
v_sql VARCHAR2 (4000);
BEGIN
v_sql := :PX_YOUR_ITEM;
RETURN v_sql;
END;
Paulo Vale
http://apex-notes.blogspot.com -
Mysql equivalent oracle sql query is required
Hi all,
please help me convert mysql quyery into sql query.
select u.username, t.name as fullname, p.id as project_id, p.name as project,
(select count(a.resource_id) from pd_resource_task_alloc as a left OUTER JOIN pd_resource_task as b on a.task_id=b.task_id where a.task_id=t.id ) as allocatedTask,
(select count(a.resource_id) from pd_resource_task_alloc as a left OUTER JOIN pd_resource_task as b on a.task_id=b.task_id where a.task_id=t.id and b.task_status_id='2') as completedTask,
(select count(a.resource_id) from pd_resource_task_alloc as a left OUTER JOIN pd_resource_task as b on a.task_id=b.task_id where a.task_id=t.id and b.task_status_id!='2') as pendingTask,
c.name as category, sub.task_id, t.name, sub.bucket_date, sum(sub.alloc_time) as s
from (select rt.task_id, rt.resource_id, rt.project_id, rta.sequence, rta.alloc_time,DATE(th.creation_date) as creation_date,rt.start_date,th.task_status_id,rt.start_date as bucket_date from resource_task rt, resource_task_alloc rta ,task_history th
where rt.task_id = rta.task_id and rt.task_id = th.task_id and th.task_status_id >=2
and rt.resource_id = rta.resource_id and rt.project_id = rta.project_id
and rta.alloc_time > 0 and rt.start_date is not null ) as sub,
pd_tool_user u, pd_task t, pd_project p, pd_category c where sub.resource_id = u.id
and sub.start_date >='2011-11-01' and sub.creation_date <= '2011-11-31'
and sub.task_id = t.id and sub.project_id = p.id and
t.category_id = c.id
and sub.project_id='355'
group by p.project, u.username, p.id , u.name, sub.task_id, t.name, c.name,
sub.bucket_date order by u.username, sub.bucket_date, p.name, c.nameThanks,
P PrakashNot sure as we don't have any tables and data to work with, but firstly...
a) format your code to make it easier to see what's going on
b) don't mix ansi joins with regular joins
c) treat DATEs as DATEs
d) Table alias names don't use the "AS" keyword
First guess (obviously unteseted)...
select u.username
,t.name as fullname
,p.id as project_id
,p.name as project
,(select count(a.resource_id)
from pd_resource_task_alloc a
left OUTER JOIN pd_resource_task b on (a.task_id=b.task_id)
where a.task_id=t.id
) as allocatedTask
,(select count(a.resource_id)
from pd_resource_task_alloc a
left OUTER JOIN pd_resource_task b on (a.task_id=b.task_id)
where a.task_id=t.id
and b.task_status_id='2'
) as completedTask
,(select count(a.resource_id)
from pd_resource_task_alloc a
left OUTER JOIN pd_resource_task b on (a.task_id=b.task_id)
where a.task_id=t.id
and b.task_status_id!='2'
) as pendingTask
,c.name as category
,sub.task_id
,t.name
,sub.bucket_date
,sum(sub.alloc_time) as s
from (select rt.task_id
,rt.resource_id
,rt.project_id
,rta.sequence
,rta.alloc_time
,th.creation_date -- assuming creation_date is a DATE datatype?
,rt.start_date
,th.task_status_id
,rt.start_date as bucket_date
from resource_task rt
join resource_task_alloc rta on (rt.task_id = rta.task_id
and rt.resource_id = rta.resource_id
and rt.project_id = rta.project_id)
join task_history th on (rt.task_id = th.task_id)
where th.task_status_id >=2
and rta.alloc_time > 0
and rt.start_date is not null
) sub
join pd_tool_user u on (sub.resource_id = u.id)
join pd_task t on (sub.task_id = t.id)
join pd_project p on (sub.project_id = p.id)
join pd_category c on (t.category_id = c.id)
where sub.start_date >= to_date('2011-11-01','YYYY-MM-DD') -- assuming start_date is a DATE datatype
and sub.creation_date <= to_date('2011-11-31','YYYY-MM-DD') -- assuming creation_date is a DATE datatype
and sub.project_id='355'
group by p.project
,u.username
,p.id
,u.name
,sub.task_id
,t.name
,c.name
,sub.bucket_date
order by u.username
,sub.bucket_date
,p.name
,c.name -
Handling hierarchy in oracle sql query
I have two tables:
The first contains COMPANY_ID and CATEGORY_ID
The second contains CATEGORY_ID and PARENT_CATEGORY_ID
I need to return a list containing COMPANY_ID and CATEGORY_ID. The entries, however, must come not only from the first table, but also include all the descendants listed in the second table.
So for example (and please read the example carefully) - let’s say in the first table I have one row:
COMPANY_ID | CATEGORY_ID
1000 | 1
In the second table, I have three rows:
CATEGORY_ID | PARENT_CATEGORY_ID
1 | null
2 | 1
3 | 2
4 | null
I want to have the following rows as a result:
COMPANY_ID | CATEGORY_ID
1000 | 1
1000 | 2
1000 | 3
How can I do this in oracle 10 in a single SQL statement ?Hi,
Welcome to the forum!
Whenver you have a question, post your sample data in a form that people can use.
CREATE TABLE and INSERT statements are great:
CREATE TABLE first
( company_id NUMBER (4)
, category_id NUMBER (4)
INSERT INTO first (company_id, category_id) VALUES (1000, 1);CREATE TABLE AS is good, too:
CREATE TABLE second
AS
SELECT 1 AS category_id, NULL AS parent_category_id FROM dual UNION ALL
SELECT 2, 1 FROM dual UNION ALL
SELECT 3, 2 FROM dual UNION ALL
SELECT 4, NULL FROM dual;Without that, people can't test their ideas, and are often unsure about your data.
You should also say what version of Oracle you're using. That's especially important with CONNECT BY queries. Every version since Oracle 7 has had significant improvements in how to do CONNECT BY queries. The query below works in Oracle 10 (and up).
For hierarchies and trees, use CONNECT BY
When you have to join tables and use CONNECT BY, it's usually more efficient to do one in a sub-query, and the other in another query.
In the example below, we're doing the CONNECT BY in sub-query cbq, and the join in the main query.
WITH cbq AS
SELECT category_id
, CONNECT_BY_ROOT category_id AS root_category_id
FROM second
START WITH parent_category_id IS NULL
AND category_id IN ( SELECT category_id -- Maybe; see note below
FROM first
CONNECT BY parent_category_id = PRIOR category_id
SELECT first.company_id
, cbq.category_id
FROM first
JOIN cbq ON first.category_id = cbq.root_category_id
;The 2nd condition in the START WITH clause won't change the results any; any rows that are excluded by that condition would also be excluded by the join condition. There can be a big differenece in performance, however. Try the query both ways, and use the 2nd condition if it helps.
Edited by: Frank Kulash on Feb 3, 2010 3:46 PM -
How to tune a oracle sql query to make it run faster ...
Hi Guys,
I am very new to this tuning of sql queries. It is taking a lot of time to run a query and give the output. I have a tool called TOAD[ Tool for oracle application development ] and i ran a query in that tool. Its showing that the query is taking 7sec to get its output. I donno the exact procedure what to follow in order to tune that query. What are these actually like : explain plan, sqltrace, tkprof and how to use these to tune the query. I want my query to run faster like in msec.
Help Appreciated.
Thankshttp://download-east.oracle.com/docs/cd/B10501_01/server.920/a96533/toc.htm
http://download-east.oracle.com/docs/cd/B10501_01/server.920/a96533/sqltrace.htm#1018
Maybe you are looking for
-
I can manually manage content from my personal computer, but I cannot do that on other computers. why is that?
-
HI. Anyone know how to eject a new IPod Nano without getting an error message? Even after I took off all the music I had put on it, I still got the message, "The iPod cannot be ejected because it contains files that are in use by another application.
-
Which of the standard colour profiles is the most colour accurate?
I'm using a late 2013 MacBook Pro (see specs under my message). I don't want to go as far as to professionally calibrate my screen, but I'd like to select the most colour accurate default sRGB profile possible. Since movies, games, and my amateur Pho
-
Is it safe to assume any Universal Binary flavor of CS3 will always be Snow Leopard Compatible or must it say so explicitly on the packaging? Many thanks in advance for your kind help!
-
Find SAPGui patch level from Appl Server
Hi, I have requirement to write a program to find what will be patch level applied in the each presentation server that login into server. This will be my requirement. We have around 6000 terminals, some of terminals giving short dump in server due