Unexpected line breaks in output of a sql query
Hi,
I have a query which looks like:
set pages 0
set feed off
set newp 0
set lines 350
select LPAD(SUBSTR(COLUMN1,1,23),23),LPAD(SUBSTR(COLUMN2,1,42),42), SUBSTR(TO_CHAR(START_TIME,'HH24:MI:SS'),1,8),SUBSTR(TO_CHAR(END_TIME,'HH24:MI:SS'),1,8)
FROM TABLE1;
When executed using SQL*Plus this query puts a line break after each column and hence I get a record on several rows on the screen.
But the last two columns are printed on the same line. I suspect the LPAD is causing some problem.
I have two databases. It works perfectly on one and not on the other.
Is there a oracle parameter due to which the result is affected?
T&R,
BRK
Try this:
set pages 0 feed off newp 0 lines 350 trims on
select LPAD(SUBSTR(COLUMN1,1,23),23)
, LPAD(SUBSTR(COLUMN2,1,42),42)
, TO_CHAR(START_TIME,'HH24:MI:SS')
, TO_CHAR(END_TIME,'HH24:MI:SS')
FROM TABLE1;
Similar Messages
-
How to get tax break up of TDS using SQL query ?
Hi all,
We are developing a TDS report using SQL query
Report will contain VendorCode,Date(ap inv date),Vendor name,
Bill value,TDS Amount,
Bill Value 100.000,
TDS (2%) - 2.000,
TDS Surcharge(10% on TDS) - 0.2,
TDS Cess(2%(TDS+TDS Surcharge)) - 0.044,
TDS HeCess(1%(TDS+TDS Surcharge)) - 0.022.
We have developed this report which displays upto
VendorCode,Date(ap inv date),Vendor name,
Bill value,TDS Amount.
How to show tax break up of TDS in SQL query ?
Thanks,
With regards,
Jeyakanthan.Hi gauraw,
Thank for your reply.
I modified the query , pasted the query
as below in query generator,
Select T0.DocNum,T0.DocDate,T0.CardCode as 'Ledger',T1.TaxbleAmnt As 'Bill value',T1.WTAmnt as 'TDSAmt',(TDSAmt * 0.1) as 'TDS_Surch',
(((TDSAmt0.1) + TDSAmt)0.02) as 'TDSCess',
(((TDSAmt0.1) + TDSAmt)0.01) as 'TDSHCess'
FROM OPCH T0 INNER JOIN PCH5 T1 ON T0.DocEntry = T1.AbsEntry
WHERE (T0.DocDate >= '[%0]' and T0.DocDate <= '[%1]')
on clicking execute its showing error message invalid column
name 'TDSAmt'.
With regards,
Jeyakanthan -
Convert rows to columns and put line break in between using t-sql
Hi,
I have a table with 5 columns..and my source data looks like this..
RecordID ID Display AddressType EmailAddress
1 1 GeneratedBy From
[email protected]
1 1 ReceivedBy To
[email protected]
1 1 ReceivedBy To
[email protected]
2 1
3 1 GeneratedBy From
[email protected]
3 1 GeneratedBy From [email protected]
3 1 ReceivedBy To
[email protected]
I need t-sql to show output as..
RecordID ID FullDisplay
1 1 GeneratedBy From -
[email protected] < CHAR(13) - Need Line Break here so that it goes to 2nd line>
ReceivedBy To -
[email protected] ; To -
[email protected]
2 1 Null
3 1 GeneratedBy From -
[email protected] ; From -
[email protected] < CHAR(13) - Need Line Break here so that it goes to 2nd line>
ReceivedBy To -
[email protected]
Display field will have 3 values - "GeneratedBy" , "ReceivedBy" or Null
AddresType field will have 3 values - "From" , "To" and Null.
In the above example, Those 7 records belongs to ID=1.
Whenever RecordID is same I want to show everything in one line with line breaks in between.
In the above example RecordID=1 has 3 rows, display it as 1 row. But Whenever 'ReceivedBy' is there for same recordID put a line break before "ReceivedBy"
create Statement:
Create Table SampleTest
(RecordID int null, ID int null , Dispplay varchar(20) null, AddressType varchar(6) null , EmailAddress Varchar(25) null)
Insert Statement:
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'ReceivedBy','To','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'ReceivedBy','To','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (2,1, Null,Null,Null)
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'ReceivedBy','To','[email protected]')
Thanks!
sqlTry below
drop table SampleTest
GO
Create Table SampleTest
(RecordID int null, ID int null , Display varchar(20) null, AddressType varchar(6) null , EmailAddress Varchar(25) null)
--Insert Statement:
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'ReceivedBy','To','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (1,1,'ReceivedBy','To','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (2,1, Null,Null,Null)
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'GeneratedBy','From','[email protected]')
Insert into SampleTest (RecordID ,ID,Display,AddressType,EmailAddress) values (3,1,'ReceivedBy','To','[email protected]')
with CTE1 as
select ROW_NUMBER() over(PARTITION by RecordID ,ID,Display order by EmailAddress)rno,* From SampleTest
), CTE2 as (
select RecordID ,ID,'GeneratedBy '+ STUFF(( SELECT '; From - ' + EmailAddress AS [text()]
FROM CTE1 b
WHERE
a.RecordID=b.RecordID and a.ID=b.ID and b.Display = 'GeneratedBy'
FOR XML PATH('')
), 1, 2, '' ) GeneratedBy,
'ReceivedBy '+ STUFF(( SELECT '; To - ' + EmailAddress AS [text()]
FROM CTE1 b
WHERE
a.RecordID=b.RecordID and a.ID=b.ID and b.Display = 'ReceivedBy'
FOR XML PATH('')
), 1, 2, '' ) ReceivedBy
From CTE1 a
group by RecordID ,ID
select RecordID ,ID,GeneratedBy +CHAR(13)+ ReceivedBy as FullDisplay from CTE2
Thanks
Saravana Kumar C -
[solved] How to have line breaks in output of journalctl log
Hello,
How can I have line breaks in the journalctl log output?
At the moment I cannot read most of the log output because it does not fit into my terminal.
See this screenshot: http://i.imgur.com/nUR6Fae.png
Thanks!
Last edited by orschiro (2013-09-20 08:08:04)You can run
journalctl -b --no-pager | less
Edit: If you hit 'h' you get help screen
SUMMARY OF LESS COMMANDS
<snip>
ESC-) RightArrow * Left one half screen width (or N positions).
ESC-( LeftArrow * Right one half screen width (or N positions).
<snip>
It may be possible to configure the way the journal uses the pager so it wraps the lines by default.
Edit 2: Or maybe it can't be configured.
man journalctl wrote:The output is paged through less by default, and long lines are "truncated" to screen width. The hidden part can be viewed by using the left-arrow and right-arrow keys. Paging can be disabled, see --no-pager and section Environment below.
Last edited by karol (2013-09-20 08:02:13) -
How to Suppress The Output of a SQL Query In Oracle 11gR2
Hi Friends,
I am using oracle version 11.2.0.1, I have set a cronjob which will run on every 15 minutes and give us a log file mentioning the execution time taken for that SQL query:-
For example:
SQL> set timing on;
SQL> SELECT objProp FROM aradmin.arschema WHERE (schemaId = 175);
OBJPROP+
--------------------------------------------------------------------------------+
*6\60006\4\0\\60008\40\0\60009\4\0\\60010\4\0\\60018\4\0\\600*
*22\4\68\1\63\AR:jRL#*
Elapsed: 00:00:00.00
The above query will return the output as well as the time taken for execution of the query. I want to suppress the output of the query and only want the time taken to be printed. Is it possible by set commands. I have marked the output as bold and made it Italic.
Please help me at the earliest.
Regards,
Arijit>
I am using oracle version 11.2.0.1, I have set a cronjob which will run on every 15 minutes and give us a log file mentioning the execution time taken for that SQL query:-
The above query will return the output as well as the time taken for execution of the query. I want to suppress the output of the query and only want the time taken to be printed. Is it possible by set commands. I have marked the output as bold and made it Italic.
>
How would that even be useful?
A query from a tool such as sql*plus is STILL going to send the output to the client and the client. You can keep sql*plus from actually displaying the data by setting autotrace to trace only.
But that TIME TAKEN is still going to include the network time it takes to send ALL rows that the query returns across the network.
That time is NOT the same as the actual execution time of the query. So unless you are trying to determine how long it takes to send the data over the network your 'timing' method is rather flawed.
Why don't you tell us WHAT PROBLEM you are trying to solve so we can help you solve it? -
How to add line breaks to output fixed width flat file
0
I need to create a Flat file without column headers, no comma separated values but each column will have a fixed starting position and a fixed length in the text file. For example, below is the text file to be created with six columns
Column1 Column2 Column3 Column4 Column5 Column6
abc 1 New emp xxxx xxxx
xxx
Fixed starting position and a fixed lenth values for these columns as are below;
Column1 : Starting Position -1, Fixed Length -4
Column2 : Starting Position - 8, Fixed Length - 2
Column3 : Starting Postion - 11, Fixed Length - 10
Column4 : Starting Position -1, Fixed Length -5
Column5 : Starting Position - 10, Fixed Length - 2
Column6 : Starting Postion - 15, Fixed Length - 5
The out put file each line have only 20 characters length.First 3 columns comes in first line and 4-6 columns comes in 2nd line.
OUTPUT FILE:
1234 89 11121314151617181920
12345 1011 151617181920BOL says that:
The Fixed width with row delimiters option is not available in the Flat File Connection Manager Editor.
If necessary, you can emulate this option in the editor. To emulate this option, on the General page of the Flat File Connection Manager
Editor, for Format, select Ragged right. Then on the Advanced page
of the editor, add a new dummy column as the final column of data.
More details steps:
http://www.coderewind.com/2012/08/ssis-how-to-include-rowdelimiter-with-destination-flat-files/
Below blog should make things clear:
SSIS Flat File Export - "Fixed Width" vs "Ragged Right"
-Vaibhav Chaudhari -
Hello All,
I have a table named as 'product' having two columns prod_name and prod_status.
Table Name: product
prod_name prod_status
bag A
Pen A
Pencil B
Eraser C
Paper A
Now if I will write a query
select prod_name from product where prod_status='A';
Then it will return me output as:
prod_name
bag
Pen
Paper
But I want output as:
prod_name
bag,Pen,Paper
I have checked solution for this problem on many thread but havent found any good solution. I want it for 10G.
Thanks in advance
Edited by: Tushky on Aug 4, 2010 2:04 AMIt looks quite amazing that you did not found any solution for this porbs on forum. Anyways try the below query, it works in 10g.
To write in CSV file, spool a CSV file and copy the contents....
with c as
(select 'bag' str from dual union all
select 'pen' str from dual union all
select 'paper' str from dual )
select rtrim(xmlagg(xmlelement(e,str||',').extract('//text()')),',') op
from c
SQL> /
OP
bag,pen,paper -
How to write the output of an SQL query to a text file?
I am using Oracle 11g and SQL plus.
I have a large table called rating.
Whenever I do
SQL> select * from rating;
The output goes much beyond what the SQL Plus screen can show. I want to therefore store the output of this query into a text file.
How can this be done? Please help. Thanks.SQL> SPOOL results.txt
SQL> select * from rating;
SQL> SPOOL OFF -
Script task to convert output from a sql query into send mail task body formatting
SSIS 2008R2 Version
Code from script task
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
namespace ST_29dd6843bd6c4aee9b1656c1bbf55ba8.csproj
[System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
#region VSTA generated code
enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
#endregion
public void Main()
Variables varCollection = null;
string header = string.Empty;
string message = string.Empty;
Dts.VariableDispenser.LockForWrite("User::gsEmailMessage");
Dts.VariableDispenser.LockForWrite("User::gsWebserviceName");
Dts.VariableDispenser.LockForWrite("User::gsNoOfCallsInADay");
Dts.VariableDispenser.LockForWrite("User::gsCalledBySystem");
Dts.VariableDispenser.GetVariables(ref varCollection);
//Set the header message for the query result
if (varCollection["User::gsEmailMessage"].Value == string.Empty)
header = "Hi, Count is greater then 50 :\n\n";
//header = "Execute SQL task output sent using Send Email Task in SSIS:\n\n\n";
header += "----------------------------------------------------------------------------------------------------------------------" + "\n";
header += string.Format("{0}\t\t\t\t{1}\t\t{2}\n", "WebService Name", "No Of Calls In A Day", "Called By System");
header += "----------------------------------------------------------------------------------------------------------------------" + "\n";
varCollection["User::gsEmailMessage"].Value = header;
//Format the query result with tab delimiters
message = String.Format("<HTML><BODY><P>{0}</P><P>{1}</P><P>{2}</P></BODY></HTML>",
varCollection["User::gsWebserviceName"].Value,
varCollection["User::gsNoOfCallsInADay"].Value,
varCollection["User::gsCalledBySystem"].Value);
varCollection["User::gsEmailMessage"].Value = varCollection["User::gsEmailMessage"].Value + message + "\n";
Dts.TaskResult = (int)ScriptResults.Success;
Above code will return data in below format and then i send this output in aemail using send mail task.
Hi, count is greater then 50 :
WebService Name
No Of Calls In A Day Called By System
WebServiceone 1
Internetbutiken
WebServiceGetdetailstwo 1
Internetbutiken
Servicenamethree 2
MOB
As you can see above code is not in align as if we service name is shorter then 2nd column get disallign and its not look good.I need output should be like below.
Hi, count is greater then 50 :
WebService Name
No Of Calls In A Day Called By System
WebServiceone 1
Internetbutiken
WebServiceGetdetailstwo 1
Internetbutiken
Servicenamethree 2
MOB
Please suggest something...
Thanks
SR_MCTSSee code explained here
http://microsoft-ssis.blogspot.in/2013/08/sending-mail-within-ssis-part-2-script.html
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
This will not help.As I am not creating smtp connectin ,send from ,send to in script task.I am just creating email body from sql output. -
Expected output for my sql query
Hi can you please tell me how to get the my expected output from the table work_invoice_hold_t
where i need to compare company code , tot_cust_no,sto_no,sales_date and trans_type='HOLD'
for example below i am comparing comp_code 1801 ,tot_cust_no,sto_no and sales_date.... when i compare them i need to get sales date record like
1801 1504522002 601 120618 1 142 HOLD Y
COMP_CODE TOT_CUST_NO STO_NO SALES_DATE CASH_NO RECEIPT_NO TRANS_TYPE PROCESSED
2300 0062090790 121 120306 3 132 HOLD Y
1801 1504522002 601 120306 1 142 HOLD Y
1801 1504522002 601 120306 1 142 UNHOLD 3
1801 1504522002 601 120618 1 142 HOLD Y
EXPECTED OUTPUT:
2300 0062090790 121 120306 3 132 HOLD Y
1801 1504522002 601 120618 1 142 HOLD YHi Thank you for providing the necessary help.
Here is another requirement for my query.
First query should be merged into second query. In the second query we are using one more table like "I_INVOICE_INFO_T_LOG_V"
that is when we put both first and second queries together i need to get the output like below:
601 STO 1504522002 120618 142 1 1801 HOLD
121 STO 0062090790 120306 132 3 2300 HOLD
table structure is:
CREATE TABLE RIMS.I_INVOICE_INFO_T_LOG_V
REG_DATE VARCHAR2(6 BYTE),
STO_NO VARCHAR2(3 BYTE),
SALES_DATE VARCHAR2(6 BYTE),
CASH_NO NUMBER(5),
RECEIPT_NO NUMBER(10),
ORDER_NO NUMBER(10),
TOT_CUST_NO VARCHAR2(13 BYTE),
CONTROL_NO NUMBER(10),
INV_ADM_COST_FR VARCHAR2(1 BYTE),
VAT_OBLIGED VARCHAR2(1 BYTE),
ART_NO VARCHAR2(8 BYTE),
SOLD_QTY NUMBER(10),
SOLD_AMOUNT NUMBER(10),
CUR_CODE VARCHAR2(3 BYTE),
ORIG_INVO VARCHAR2(10 BYTE),
CUSDEL_NO NUMBER(2),
SEQ_NO_SORT NUMBER(10),
GROUP_ID_PROD NUMBER(10),
GROUP_ID_TXT NUMBER(10),
CUSDEL_TYPE VARCHAR2(2 BYTE),
VAT_CODE VARCHAR2(10 BYTE),
VAT_RATE NUMBER(6,2),
TIMESTAMP DATE,
INV_TYPE VARCHAR2(1 BYTE),
INS_USER VARCHAR2(30 BYTE),
MACHINE VARCHAR2(64 BYTE),
SEQ NUMBER(22) NOT NULL
sample data :
SET DEFINE OFF;
Insert into RIMS.I_INVOICE_INFO_T_LOG_V
(REG_DATE, STO_NO, SALES_DATE, CASH_NO, RECEIPT_NO, ORDER_NO, TOT_CUST_NO, CONTROL_NO, INV_ADM_COST_FR, VAT_OBLIGED, ART_NO, SOLD_QTY, SOLD_AMOUNT, CUR_CODE, CUSDEL_NO, SEQ_NO_SORT, GROUP_ID_PROD, CUSDEL_TYPE, VAT_CODE, VAT_RATE, TIMESTAMP, SEQ)
Values
('120306', '121', '120306', 3, 132,
0, ' 0062090790', 0, '0', '1',
'40043234', 8, 20800, 'DKK',
0, 0, 0, '01',
'0', 2500, TO_DATE('10/21/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 916052);
Insert into RIMS.I_INVOICE_INFO_T_LOG_V
(REG_DATE, STO_NO, SALES_DATE, CASH_NO, RECEIPT_NO, ORDER_NO, TOT_CUST_NO, CONTROL_NO, INV_ADM_COST_FR, VAT_OBLIGED, ART_NO, SOLD_QTY, SOLD_AMOUNT, CUR_CODE, CUSDEL_NO, SEQ_NO_SORT, GROUP_ID_PROD, CUSDEL_TYPE, VAT_CODE, VAT_RATE, TIMESTAMP, SEQ)
Values
('120306', '601', '120306', 1, 142,
0, ' 1504522002', 0, '0', '1',
'40047760', 2, 200, 'GBP',
0, 0, 0, '01',
'0', 1750, TO_DATE('10/21/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 916053);
Insert into RIMS.I_INVOICE_INFO_T_LOG_V
(REG_DATE, STO_NO, SALES_DATE, CASH_NO, RECEIPT_NO, ORDER_NO, TOT_CUST_NO, CONTROL_NO, INV_ADM_COST_FR, VAT_OBLIGED, ART_NO, SOLD_QTY, SOLD_AMOUNT, CUR_CODE, CUSDEL_NO, SEQ_NO_SORT, GROUP_ID_PROD, CUSDEL_TYPE, VAT_CODE, VAT_RATE, TIMESTAMP, SEQ)
Values
('120618', '601', '120618', 1, 142,
0, ' 1504522002', 0, '0', '1',
'20057057', 2, 400, 'GBP',
0, 0, 0, '01',
'0', 1500, TO_DATE('10/21/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 916054);
Insert into RIMS.I_INVOICE_INFO_T_LOG_V
(REG_DATE, STO_NO, SALES_DATE, CASH_NO, RECEIPT_NO, ORDER_NO, TOT_CUST_NO, CONTROL_NO, INV_ADM_COST_FR, VAT_OBLIGED, ART_NO, SOLD_QTY, SOLD_AMOUNT, CUR_CODE, CUSDEL_NO, SEQ_NO_SORT, GROUP_ID_PROD, VAT_CODE, VAT_RATE, TIMESTAMP, SEQ)
Values
('051020', '262', '051020', 11, 16,
0, ' 1555792009', 0, '0', '1',
'50043993', 3, 4800, 'GBP',
0, 0, 0,
'0', 1750, TO_DATE('10/21/2005 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 916055);
for example:
Second query
SELECT DISTINCT workhold.sto_no AS bu_code,
'STO' AS Bu_Type,
AND workhold.processed='Y'...
and ( first query condition)
First query.
WITH got_cnt AS
SELECT w.* -- or list columns you want
, COUNT (CASE WHEN trans_type = 'HOLD' THEN 1 END)
OVER (PARTITION BY comp_code, tot_cust_no, sales_date)
AS hold_cnt
, COUNT (CASE WHEN trans_type = 'UNHOLD' THEN 1 END)
OVER (PARTITION BY comp_code, tot_cust_no, sales_date)
AS unhold_cnt
FROM work_invoice_hold_t w
SELECT sto_no as bu_code,'STO' as bu_type,tot_cust_no as cust_no,sales_date,receipt_no,cash_no as till_no,comp_code,trans_type-- or list columns you want
FROM got_cnt
WHERE hold_cnt = 0
OR unhold_cnt = 0
First query output:
601 STO 1504522002 120618 142 1 1801 HOLD
121 STO 0062090790 120306 132 3 2300 HOLD
Second Query:
SELECT DISTINCT workhold.sto_no AS bu_code,
'STO' AS Bu_Type,
workhold.Tot_Cust_No AS Cust_No,
workhold.Sales_Date AS Sales_Date,
workhold.Receipt_No,
workHOLD.Cash_No AS Till_No,
workhold.Comp_Code,
workhold.Trans_Type AS on_hold_flag
FROM WORK_INVOICE_HOLD_V workhold,
I_INVOICE_INFO_T_LOG_V invlog
WHERE
TRIM (workhold.Tot_Cust_No) = TRIM (invlog.Tot_Cust_No)
AND TRIM (workhold.Cash_No) = TRIM (invlog.Cash_No)
AND TRIM (workhold.sales_date) = TRIM (invlog.sales_date)
AND TRIM (workhold.Receipt_No) = TRIM (invlog.Receipt_No)
AND TRIM (workhold.Sto_No) = TRIM (invlog.Sto_No)
AND workhold.processed='Y'
output for second query:
601 STO 1504522002 120618 142 1 1801 HOLD
601 STO 1504522002 120306 142 1 1801 HOLD
121 STO 0062090790 120306 132 3 2300 HOLD
expected output:
after checking the conditions for both 1 and 2 queries i need to get the output like below.
601 STO 1504522002 120618 142 1 1801 HOLD
121 STO 0062090790 120306 132 3 2300 HOLDEdited by: 891933 on Oct 2, 2012 1:18 AM -
Can we generate the output of SQL Query in XML format ..
Hi Team,
Can we generate an XML doc for an SQL Query.
I've seen in SQL Server 2000.It is generating the output of an SQL Query in xml format.
select * from emp for xml auto
The output looks like
<emp EMPNO="7369" ENAME="SMITH" JOB="CLERK" MGR="7902" HIREDATE="1980-12-17T00:00:00" SAL="2800" DEPTNO="20"/><emp EMPNO="7370" ENAME="SMITH" JOB="CLERK" MGR="7902" HIREDATE="1980-12-17T00:00:00" SAL="2800" DEPTNO="10"/>Just a little bit of short hand.
Get the XML out of your database, via HTTP
Of course the easiest method is just to return an XMLType from a stored procedure and let the calling routine figure out what to do with it. Instead
of that way though, I'll show you how to do it via HTTP. It's all completely built into 10g and is super easy to use.
CREATE OR REPLACE VIEW emps_and_depts AS
SELECT e.employee_id AS "EmployeeId",
e.last_name AS "Name",
e.job_id AS "Job",
e.manager_id AS "Manager",
e.hire_date AS "HireDate",
e.salary AS "Salary",
e.commission_pct AS "Commission",
XMLFOREST (
d.department_id AS "DeptNo",
d.department_name AS "DeptName",
d.location_id AS "Location"
) AS "Dept"
FROM employees e, departments d
WHERE e.department_id = d.department_id
Some people hear web and immediately start salivating about security issues. Let me address that quickly. Just because you have the HTTP and/or
FTP servers running in the database, that does not mean you have a security problem. For one, I would hope your databases are behind a firewall.
Second, with the correct architecture (DMZ, app servers, etc) you can make this data available outside the firewall fairly transparently and third,
just because it's on the web does not mean the data MUST be available on the internet. This is a good way to make your data available on your
intranet. If you are worried about people INSIDE your firewall, that still doesn't preclude web based access. Follow Oracle security guidelines.
Before I show you how to get to your data, let's talk about URLs and URIs. A URL is a Uniform Resource Locater and URI is a Uniform Resource
Identifier. A URL is the way you would identify a document on the net, i.e. http://www.oracle.com is a URL. A URI is a more generic form of a URL.
Oracle supports three types of URI: HTTPURIType - basically a URL (which would be like the URL above), XDURIType - a pointer to an XDB resource
(usually an XML document but can be other objects), and DBURIType - a pointer to database objects.
It's the DBURIType that we're going to concentrate on here. The DBURIType let's us reference database objects using a file/folder paradigm. The
format for a DBURI is /oradb/<schema>/<table>. Oradb is shorthand for the database; it is not the database name or SID. My database is named XE
but I still use oradb in the DBURI. For example, the view we created above is in my XE database, is owned by HR (at least in my case) and is called
EMPS_AND_DEPTS. This can be referenced as /oradb/HR/EMPS_AND_DEPTS.
If the view had many rows and you wanted only one of them, you can restrict it by including a predicate. The documentation for XDB has a great
write up on Using DBURIs.In our case, we are going to write out the entire document. Now that you understand that the DBURI is a pointer to
objects in our instance, we can use that to access the data as a URL.
The format for the URL call is http://<machinename>:<port>/<DBURI>
In my case, my XE database is running on a machine called mach1 and is listening on port 8080. So to see the view we created above, I open my
browser and navigate to: http//mach1:8080/oradb/HR/EMPS_AND_DEPTS
The created URL will be as http//mach1:8080/oradb/PUBLIC/EMPS_AND_DEPTS
If your database is set up correctly and listening on port 8080 (the default), your browser should ask you to login. Login as the user who created the
view (in my case HR). You should now get an XML document displayed in your browser.
And that's it. It doesn't get much simpler than that. If you get rid of the descriptive text above, it basically comes down to:
Create a table or view
Open your web browser
Enter a URL
Enter a user ID and password
View your XML
If you notice, Oracle formatted the data as XML for us. Our view returns scalar columns and an XML fragment called Dept. Oracle formatted the
return results into an XML format.
And as a side note, if you look closely, you'll see that my URL has PUBLIC where I said to put HR. PUBLIC is a synonym for all objects that your
logged in user can see. That way, if your user has been granted select access on many schemas, you can use PUBLIC and see any of them. -
Line break symbol in WAD Chart
Hi,
We have WAD 3.5 but Query Designer 7.0. And Internet Explorer 7.
We have a query where the column description has been split in two lines in the Query Designer.
When this query is put as chart in WAD a strange symbol is shown where the text is supposed to be split (and the line is not split, but that is less of an issue.)
However when the same query is put as table in WAD, everything is fine.
Any suggestions on getting rid of this symbol?
Thanks in advance for your feedback.
ReynirHi Reynir,
I too have encountered the enter symbol in the Chart Legend. I think the only way to get rid of the same is to avoid using a line break in the Char desc in Query Designer, use a separator ( ) or so to denote what you wish to on the 2nd line - but that would make the col width too wide in the table view.
--Priya -
Substitution strings in chart sql query
Hi Guys,
I am creating line charts and bar charts based on a query in HTML DB 1.5. I am using substitution strings in the query. Though I can use substitution strings in the line chart, I cannot do it in the bar chart. I am using almost the same sql query in both line and bar charts.
The sql query in line chart is
SELECT null, TO_CHAR(t1.extract_date, 'W-MON-YYYY') extractdate,
MIN_OF_AVERAGES(AVG(&P40_METRICS.),:P40_REGION_LIST,:P40_SUBREGION_LIST,NULL,:P40_METRICS,'ind') orgid
FROM ind t1,geography t2
WHERE t1.country_id = t2.country_id(+)
AND t2.region_name like
DECODE(:P40_REGION_LIST,'ALL REGIONS','%',:P40_REGION_LIST)
AND t2.subregion_name like
NVL(:P40_SUBREGION_LIST,'%')
GROUP BY TO_CHAR(extract_date, 'W-MON-YYYY')
order by to_date(extractdate,'DD-MON-YY')
The sql query in bar chart is
SELECT null, TO_CHAR(t1.extract_date, 'W-MON-YYYY') extractdate,AVG(&P40_METRICS.) orgid
FROM ind t1,geography t2
WHERE t1.country_id = t2.country_id(+)
AND t2.region_name like
DECODE(:P40_REGION_LIST,'ALL REGIONS','%',:P40_REGION_LIST)
AND t2.subregion_name like
NVL(:P40_SUBREGION_LIST,'%')
GROUP BY TO_CHAR(extract_date, 'W-MON-YYYY')
order by to_date(extractdate,'DD-MON-YY')
The min_of_averages function in the line chart query is some function I am calling. Even if I cut-paste the line chart query in the bar chart I get the error.
The substitution string which is giving the problem is "&P40_METRICS."
The error I am getting is
Query cannot be parsed, please check the syntax of your query. (ORA-00909: invalid number of arguments)
The only difference I see is that line chart query is inside a series and bar chart is not, does this make a difference??? Or is it because I am using the substitution string in choosing the column??? Please help!!!!
Thanks,
SwaroopSwaroop,
You might be using an HTML bar chart and an SVG line chart, I can't tell, but their implementations differ. You won't be able to use a substitution string to replace a column name in the query in the situation you found, you'd have to figure out a way to construct the query string before it gets executed and I'm not sure the chart pages will let you do that.
Scott -
Need sql query to convert rows to columns
Im using oracle 11g.
I have data in a table as below: Column names are type,month,percentage
TYPE MONTH PERCENTAGE
A1 JAN-2013 100
A2 JAN-2013 100
A3 JAN-2013 95
A4 JAN-2013 98
A5 JAN-2013 99
A6 JAN-2013 90
A7 JAN-2013 92
A1 FEB-2013 100
A2 FEB-2013 99
A3 FEB-2013 88
A4 FEB-2013 67
A5 FEB-2013 98
A6 FEB-2013 95
A7 FEB-2013 84
The desired output using a sql query is as below
TYPE JAN-2013 FEB-2013
A1 100 100
A2 100 99
A3 95 88
A4 98 67
A5 99 98
A6 90 95
A7 92 84Try this:
select * from table_name
PIVOT( max(Percentage)
for MONTH
in ('JAN-2013','FEB-2013')
) ;with data
with t(TYPE,MONTH,PERCENTAGE) as
SELECT 'A1', 'JAN-2013', 100
FROM DUAL
UNION ALL
SELECT 'A2', 'JAN-2013', 100
FROM DUAL
UNION ALL
SELECT 'A3', 'JAN-2013', 95
FROM DUAL
UNION ALL
SELECT 'A4', 'JAN-2013', 98
FROM DUAL
UNION ALL
SELECT 'A1', 'FEB-2013', 100
FROM DUAL
UNION ALL
SELECT 'A2', 'FEB-2013', 99
FROM DUAL
UNION ALL
SELECT 'A3', 'FEB-2013', 88
FROM DUAL
UNION ALL
SELECT 'A4', 'FEB-2013', 67
FROM DUAL
select * from t PIVOT( max(Percentage)
for MONTH
in ('JAN-2013','FEB-2013')
) ; -
AD: Extracting to Shapefile based on SQL query
We have written a command-line tool, SpatialExtractor, that takes an SQL query and produces an ESRI Shapefile.
If this is valuable to you, please download an evaluation version from our website, www.geometry.com.au. The full version is (approx) US$570.
We welcome any feedback or comments.
regards,
Andrew Betlehem
Geometry
www.geometry.com.auHi,
just non click able graph in ADF 10g using BI Graph: http://www.freewebalbum.com/blogs/faces/bjanko/blogs.jsp?blog=bjanko20070629162305
regards,
Branislav
Maybe you are looking for
-
How to tranfert application data from a ipod to another
how can i easely transfert my game data from an ipod touch to an ipad mini. I want to play on one and next day play with the other one and continue my game without loosing my work. I don't want to restore all the configuration each time i change devi
-
Hp Pavilion elite will not boot
My pavilion wont boot after an electrical storm. I think there's something wrong with the power button. There is a green light on the back that isn't flashing, but staying solid green. Nothing's happening when I press the power button, no fan, no res
-
Packagemaker not truly replacing App bundle
I have a Packagemaker problem. It relates to the contents of the Frameworks folder. I have an app, and it has a certain amount of files in the Frameworks folder in the bundle. I have a installer built with Packagemaker that is intended to update the
-
Change the amout a scroll bar moves when user uses the mouse wheel?
hi, i have a JScrollPane, and when a user uses the "wheel" on the mouse, it seems to move up/down 1 line at a time...i would like it to scroll faster basically...so that when the "wheel", the scroll bars move up/down like 5 lines at a time....is ther
-
How to transform response xml according to user defined xsd?
Hi all, In my use case I should invoke a webservcie which gives the employee details. For that I have a business service which returns the response in an xml which format is some thing like given below: *<output>* *<Name>Sample<Name>* *<Id>231231<Id>