Reg: sql query output
hi All,
select substr(16878575,1, (length(16878575)-length(substr(16878575, -2,2)))) ||'.' || substr(16878575, -2,2) from dual;
output - 168785.75. getting correct output.
Can you please let me know is there any other way to do that?
thanks in advance.
This way, if you need to get a number with Two Decimal places.
with data as
select 16878575 col from dual
select col/100 col from data;
COL
168785.75
Similar Messages
-
Writing a function to find whether a value is present in a sql query output
Hi gurus,
I would like to write a function to which i will pass a value and a sql query as parameters.
Now the function needs to execute that sql query and find whether the given value is present in the output list
when the query is executed. If it is present it should return 'T' otherwise 'F'
My function will look like
CREATE FUNCTION CHECK_VALUE(VALUE VARCHAR2,V_SQL VARCHAR2) RETURN VARCHAR2
SELECT CHECK_VALUE('Dallas','SELECT LOCATION_CODE FROM HR_LOCATIONS')
It should check whether the value 'Dallas' is present in the output list returned by the sql query.
Any help will be appreciated.
Thank you.CREATE OR REPLACE
FUNCTION CHECK_VALUE(
VALUE VARCHAR2,
V_SQL VARCHAR2
RETURN VARCHAR2
IS
RETVAL VARCHAR2(4000);
REFCUR SYS_REFCURSOR;
BEGIN
OPEN REFCUR FOR V_SQL;
LOOP
FETCH REFCUR INTO RETVAL;
EXIT WHEN REFCUR%NOTFOUND;
IF RETVAL = VALUE
THEN
CLOSE REFCUR;
RETURN 'T';
END IF;
END LOOP;
CLOSE REFCUR;
RETURN 'F';
END;
Function created.
SQL> SET SERVEROUTPUT ON
SQL> EXEC DBMS_OUTPUT.PUT_LINE(CHECK_VALUE('DALLAS','select loc from dept'));
T
PL/SQL procedure successfully completed.
SQL> EXEC DBMS_OUTPUT.PUT_LINE(CHECK_VALUE('PARIS','select loc from dept'));
F
PL/SQL procedure successfully completed.
SQL> SY. -
Reg: sql query that prints all sundays in the year
Hi all,
Please give me sql query that prints all sundays in year. And when ever we execute that query then that will prints the sysdate(that is execution date).
Thanks in Advance,
-prasad.
Edited by: prasad_orcl on Jun 5, 2009 9:13 PMHi,
Plz try this and let me know this works or not...
SELECT DATE DATES,TO_CHAR(DATE,'DAY') DAYS FROM FISCAL_CALENDAR
WHERE DATE_YEAR = 2009 AND
DATE BETWEEN TRUNC(SYSDATE,'YEAR') AND
ADD_MONTHS(TRUNC(SYSDATE,'YEAR'),12) -1 AND
TRIM(TO_CHAR(DATE,'DAY')) = 'SUNDAY'
ORDER BY DATE
OUTPUT:
DATES DAYS
1/4/2009 SUNDAY
1/11/2009 SUNDAY
1/18/2009 SUNDAY
1/25/2009 SUNDAY
2/1/2009 SUNDAY
2/8/2009 SUNDAY
2/15/2009 SUNDAY
2/22/2009 SUNDAY
3/1/2009 SUNDAY
3/8/2009 SUNDAY
3/15/2009 SUNDAY
3/22/2009 SUNDAY
3/29/2009 SUNDAY
4/5/2009 SUNDAY
4/12/2009 SUNDAY
4/19/2009 SUNDAY
4/26/2009 SUNDAY
5/3/2009 SUNDAY
5/10/2009 SUNDAY
5/17/2009 SUNDAY
5/24/2009 SUNDAY
5/31/2009 SUNDAY
6/7/2009 SUNDAY
6/14/2009 SUNDAY
6/21/2009 SUNDAY
6/28/2009 SUNDAY
7/5/2009 SUNDAY
7/12/2009 SUNDAY
7/19/2009 SUNDAY
7/26/2009 SUNDAY
8/2/2009 SUNDAY
8/9/2009 SUNDAY
8/16/2009 SUNDAY
8/23/2009 SUNDAY
8/30/2009 SUNDAY
9/6/2009 SUNDAY
9/13/2009 SUNDAY
9/20/2009 SUNDAY
9/27/2009 SUNDAY
10/4/2009 SUNDAY
10/11/2009SUNDAY
10/18/2009SUNDAY
10/25/2009SUNDAY
11/1/2009 SUNDAY
11/8/2009 SUNDAY
11/15/2009SUNDAY
11/22/2009SUNDAY
11/29/2009SUNDAY
12/6/2009 SUNDAY
12/13/2009SUNDAY
12/20/2009SUNDAY
12/27/2009SUNDAY
Regards
Thiyag -
Formatting SQL Query output in HTMLDB
Guys, I would like to show the result in report of SQL Query to be formatted in such way:
I got a table USERS with columns:FIrst_name, second_name, team_name, team_leader.
So in a report in HTMLDB I would like to format the result to show all employees , 500 of them, on 1 page, and show in a header for each team, team leader and team name with the rest of team underneath,so only two columns, break on team_leader or team_name, then next team, and then, NOT all this in one long display, but in three sets of result, spread in wide of report, cause the screen dimensions are quite wide.I tried few things but they do not work. I can break on tem leader or team name, but all this is still in one long set of result, not in 3 or 4 tables sets.
help
JozefHi Kamal,
I am using Oracle Applications 11.5.7 iProcurement. Database is 9i. I need to place a link in iProcurement homepage using AK Developer and when clicked it should run a query and output the result in a browser.
help appreciated
thanks -
SQL query Output exceeds 65000 rows in excel
Hi,
I have a SQL file attached to my concurrent program. The query in the SQL file returns tab separated output that i need to email as a csv through the same SQL file.
The issue I am facing is that the query returns about 157000 records but only 65536 are being displayed in the excel worksheet.
How can I get all the records by accommodating them in multiple worksheets of the same excel file?
Please help!
I am using EBS 11i.
Code I am using in SQL file:
set pages 3000
set lines 300
set heading off
set term off
set feedback off
set verify off
set echo off
set serverout off
spool /tmp/TEST.csv
select 'Header'
from dual
SELECT column1||CHR(9)||column2
FROM staging_table
spool off
set lines 1000 pages 40 head off echo off veri off
select 'cd /tmp; cat $XX_TOP/install/sql/disclaimer.txt > x.dat; cat '||'/tmp/TEST.csv'||' | uuencode '||'/tmp/TEST.csv'
||' > '||substr('/tmp/TEST.csv',1,length('/tmp/TEST.csv')-4)||'.dat >> x.dat'
||' ; mail -s ''' ||'&1'||''' '||'&2'||' < x.dat'
||' ; rm '||substr('/tmp/TEST.csv',1,length('/tmp/TEST.csv')-4)||'.dat'||' ;'
from dual
list
spool /tmp/email.txt
spool off
host chmod 777 /tmp/email.txt
host /tmp/email.txt
Thanks
Edited by: user10648285 on May 13, 2011 5:27 AMopen a blank Excel (2007 version), go to Data tab, then from External Data click From Text, select the CSV file (That having more than 65k records), click import, then from "start import at row" select 65001 and click next button, select delimiter as Comma, click Next button and filaly finish.
In this way you will have the data after 65k rows in excel. Now you can simply open that cvs file in excel then you will have first 65k records (remening part will be discarded).
So now you have two excel files and you can paste it in two diff tab.
Note - you can repeate this activity if you have more than 130000 records... -
SBO SQL Query outputs zero values as nulls but need the zeros
Hi all,
I'm having a problem with a query I'm writing in SBO where if the field contents are zero, these are output as null.
I have a field for the stock usage on sales orders and ont too for production orders, but if I add these together they only provide a result if both columns contain a numeric value.
I've tried adding "0" to the column value, adding and subtracting "1" and also multiplying the value by "1" but still no joy.
I have also tried adding a "cast" statement to the column, but that doesnt seem to have an effect either (I think as this is more an output function).
I need to be able to use these columns as separate displays in addition to being used in a further column as part of a calculation.
If anyone has an idea how I can output a true zero value as opposed to a null value your help would be appreciated.
Cheers,
JHello Julian,
You could try to use a CASE Statement as I have shown below and test this will the SQL below. If you use the T0.LineNum without any CASE or CAST the LineNum 0 will show as blank in SAP.
SELECT
CASE WHEN T0.LineNum != 0 THEN CAST(T0.LineNum AS VARCHAR(10)) ELSE '0' END AS 'Row Number',
T0.ItemCode AS 'Item No.', T0.BaseQty AS 'Base Quantity', T0.PlannedQty AS 'Planned Quantity - Rows' FROM [dbo\].[WOR1\] T0 -
Dear friends ,
I want to view a select query using page by page . Is it possible to do in SQL ?
suppose here is an example of select query :
sql > select * from v$session ;
I want to see the output as page by page .
waiting for ur kind reply . .. ..Hi, (assuming you use Db 10g v.2)
you should read the chapter "6 Formatting SQL*Plus Reports" of e-book:
SQL*Plus® User's Guide and Reference
Release 10.2
Part Number B14357-01
and especially the 'break' command.....
Greetings,
Sim -
HI FRENDS
MY PROBLEM IS IN BELOW QUERY
select SUBSTR('Sales - Alternate Channels (Sub Department).Area Manager.1',1,7) from dual
HERE I WANT TO TAKE ONLY 'SALES' FROM THE STRING.
BUT SOME TIME INSTEAD OF SALES IT WILL COME 'Branch Operations' LIKE THAT THEN I WANT TAKE THESE STRING ONLY....
IN SHORT I WAN TO TAKE ONLY THAT STRING WHICH IS BEFORE '-'......NOT THAT VALUE WHICH AFTER '-'...
PL HELP.If u want srting before '-' than use instr to search '-'
e.g.
select substr('Branch Operations - Alternate Channels (Sub Department).Area Manager.1',1
,instr('Branch Operations - Alternate Channels (Sub Department).Area Manager.1','-',1)-1)
from dual
SQL> select substr('Branch Operations - Alternate Channels (Sub Department).Area Manager.1',1
2 ,instr('Branch Operations - Alternate Channels (Sub Department).Area Manager.1','-',1)-1)
3 from dual
4 /
SUBSTR('BRANCHOPERATIONS-ALTER
Branch Operations
SQL> select substr('Sales - Alternate Channels (Sub Department).Area Manager.1',1
2 ,instr('Sales - Alternate Channels (Sub Department).Area Manager.1','-',1)-1)
3 from dual
4 /
SUBSTR('SALES-ALTERNATECHANNEL
Sales -
Table1:
ID EMPNAME COUNTRY
101 XYZ USA
102 ABC UK
103 XYZ USA
104 ABC UK
Required output:
ID EMPNAME COUNTRY CALCULATED_VALUE
101 XYZ USA 1
102 ABC UK 1
103 XYZ USA 0
104 ABC UK 0
Every 1st record of (EMPNAME, COUNTRY) combination should have CALCULATED_VALUE =1 and all succeeding records of same (EMPNAME, COUNTRY) combination should have CALCULATED_VALUE =0Try this ->
scott>
scott>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Elapsed: 00:00:00.02
scott>
scott>
scott>with t
2 as
3 (
4 select 101 ID, 'XYZ' EMPNAME, 'USA' COUNTRY from dual
5 union all
6 select 102, 'ABC', 'UK' from dual
7 union all
8 select 103, 'XYZ', 'USA' from dual
9 union all
10 select 104, 'ABC', 'UK' from dual
11 )
12 select ID,
13 EMPNAME,
14 COUNTRY,
15 case
16 when rn = 1 then
17 1
18 else
19 0
20 end CALCULATED_VALUE
21 from (
22 select ID,
23 EMPNAME,
24 COUNTRY,
25 row_number() over(partition by COUNTRY order by ID) rn
26 from t
27 )
28 order by ID;
ID EMP COU CALCULATED_VALUE
101 XYZ USA 1
102 ABC UK 1
103 XYZ USA 0
104 ABC UK 0
Elapsed: 00:00:00.00
scott>Regards.
Satyaki De. -
Reg : SQL query or Function -
Hi Experts,
I'm in a fix between 2 approaches.
Scenario :
There are 2 tables say LIT (contains Literature docs) and DIAG (contains Diagams). There's some concept called 'Base number' and 'Revision' for both the tables.
Ex - If Literature (or Diagram) is 1 then this is the 'Base number' and further revisions to this forms - 1A, 1B, 1C...
Similarly, 2 and 2A, 2B, 2C...
Inside a package I need to find out for each Base Lit and Base Diagram, their latest revisions.
Approach [1] :
Create 2 functions (1 for Lit and other for Diag) where we'll take input as a Base No and fetch its latest.
Approach [2] :
Create 2 queries, we'll use SUBSTR for all lits, find the Base no and use analytic funtions like ROW_NUMBER() and find the latest revision.
Which of the 2 will be more efficient?
In which 'context switch' will be an overhead or any other concerns?
Help much appreciated.
Thanks,
Ranit
Oracle version : Oracle Database 10g Enterprise Edition Release *10.2.0.5.0* - 64biranit B wrote:
Hi Experts,
I'm in a fix between 2 approaches.
Scenario :
There are 2 tables say LIT (contains Literature docs) and DIAG (contains Diagams). There's some concept called 'Base number' and 'Revision' for both the tables.
Ex - If Literature (or Diagram) is 1 then this is the 'Base number' and further revisions to this forms - 1A, 1B, 1C...
Similarly, 2 and 2A, 2B, 2C...
Inside a package I need to find out for each Base Lit and Base Diagram, their latest revisions.
Approach [1] :
Create 2 functions (1 for Lit and other for Diag) where we'll take input as a Base No and fetch its latest.
Approach [2] :
Create 2 queries, we'll use SUBSTR for all lits, find the Base no and use analytic funtions like ROW_NUMBER() and find the latest revision.
Oracle version : Oracle Database 10g Enterprise Edition Release *10.2.0.5.0* - 64biSince others have already expressed opinions about Context Switches, and I favor them, so I would not comment on it. And I will suggest to opt Approach 2.
Because, you would be able to harness the powers of FBI over the Columns storing versions and better the performance.
Another approach, I feel, worth trying is to have an MView, that separates the Base number and Max Version Number of the corresponding base number, which would be refreshed on Commit/some other way suitable for your situation. -
Hi,
I Have a table with below structure
Change_Type Old_Val New_val
AB 1 2
BC 11 12
AB 21 22
BC 31 32
CD 41 42
CD 51 52
Requirement is to display the records in following fashion.
AB 1 2
BC 11 12
CD 41 42
AB 21 22
BC 31 32
CD 51 52try this
with t as
select 'AB' a, 1 b, 2 c from dual
union
select 'BC' a, 11 b,12 c from dual
union
select 'AB' a, 21 b,22 c from dual
union
select 'BC' a, 31 b,32 c from dual
union
select 'CD' a, 41 b,42 c from dual
union
select 'CD' a, 51 b,52 c from dual
select a,b,c from(select a, b, c, row_number() over (partition by a order by b) rn from t) order by rn,a,b -
SQL Query - The number of columns specified in "SQL Query" does not match t
I am creating new UDM for tablespace alert, below is my query,however its failing with error
SQL Query - The number of columns specified in "SQL Query" does not match the value specified in "SQL Query Output"
I selected Metric type is number
SQL Query Format : Two columns
Query:
SELECT d.tablespace_name,round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2)
used_pct FROM sys.dba_tablespaces d,(select tablespace_name, sum(bytes) bytes, sum(greatest(maxbytes,bytes)) maxbytes from sys.dba_data_files group by tablespace_name) a,(select tablespace_name, sum(bytes) bytes from sys.dba_free_space group by tablespace_name) f
WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+)
AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY');
Any clues why i am getting error.SQL> SELECT d.tablespace_name,round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2) used_pct
2 FROM sys.dba_tablespaces d,(select tablespace_name, sum(bytes) bytes, sum(greatest(maxbytes,bytes)) maxbytes from sys.dba_data_files group by tablespace_name) a,(select tablespace_name, sum(bytes) bytes from sys.dba_free_space group by tablespace_name) f
3 WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+)
4 AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY');
TABLESPACE_NAME USED_PCT
MGMT_TABLESPACE .82
SYSAUX 1.52
UNDOTBS1 .32
RMAN .02
CORRUPT_TS 10.63
USERS 0
SYSTEM 2.26
MGMT_ECM_DEPOT_TS .04
MGMT_AD4J_TS 0 -
New Line Character in SQL Query
Dear All,
I am wondering if some one tell me how to insert new line character in the SQL Query Output for example I need out put in the following format. Every line on new line.
The total count is:
Registration: 1111
Fees paid: 2222
Admission Done: 3333
Total:4000
Many thanksHi
SQL> select
2 'The total count is:
3 Registration: 1111
4 Fees paid: 2222
5 Admission Done: 3333
6 Total:4000
7 ' dummy_txt from dual
8 /
DUMMY_TXT
The total count is:
Registration: 1111
Fees paid: 2222
Admission Done: 3333
Total:4000
SQL>
SQL> select 'a'||chr(10)||'b' from dual;
'A'
a
b
SQL> T -
SQL Query in Japanese Language
Hello ,
May i please ask a query.... We have a japanese customer and he prefers to get the SQL Query output in Japanese output. Is that possible via SQLPLUS?
Regards
AjayMay i please ask a query.... We have a japanese customer and he prefers to get the SQL Query output in Japanese output. Is that possible via SQLPLUS?Yes, make sure you set NLS_LANG properly.
The correct NLS_LANG setting in Unix Environments [ID 264157.1]
The correct NLS_LANG in a Windows Environment [ID 179133.1]
NLS_LANG Explained (How does Client-Server Character Conversion Work?) [ID 158577.1]
How to Determine the NLS_LANG setting of the SQL*Plus Client? [ID 344891.1]
The Priority of NLS Parameters Explained (Where To Define NLS Parameters) [ID 241047.1]
AL32UTF8 / UTF8 (Unicode) Database Character Set Implications [ID 788156.1]
Thanks,
Hussein -
Using 'Function Returning SQL Query' with Flash charts
I have created a pl/sql function that returns a SQL query as a varchar2 of this form:
select null link
<x value> value
<Series1 y value> Series 1 Label
<Series2 y value> Series 2 Label
<Series3 y value> Series 3 Label
from tablea a
join tableb b
on a.col = b.col
order by <x value>
If I now call the function from a Flash Chart Series SQL box with the Query Source Type set to 'Function Returning SQL Query' like this:
return functionname(to_date('30-sep-2010', 'dd-mon-yyyy'))
it parses correctly and the page is saved; however, when I run the page I don't get any output - nor any error messages or other indication of a problem.
Now, if I call the function in a SQL client, capture the SQL query output using dbms_output and paste that into the Flash Chart Series SQL box - changing the Query Source Type to SQL Query - and save the page it works fine when I run it and returns a multi-series flash chart.
Can anyone suggest either;
1. What have I might have missed or done wrong?
2. Any way to usefully diagnose the problem...
I have tried using the Apex debugger - which is very nice, by the way - but it doesn't provide any info on what my problem might be. I even tried writing my own debug messages from my function using the apex_debug_message package - got nothing...
Thanks,
EricHi Eric,
Try expressing the source as this:
begin
return functionname(to_date('30-sep-2010', 'dd-mon-yyyy'));
end;That works fine for me, and if I take out the begin-end and the trailing semicolon from the return statement I get the same behavior as you.
It does mention in the help for the source (only during the wizard though) that this source type has to be expressed that way, but I agree it would be helpful if the tool would validate for this format when 'Function Returning SQL Query' is used or give some sort of indication of the trouble. Anyway, this should get you going again.
Hope this helps,
John
If you find this information useful, please remember to mark the post "helpful" or "correct" so that others may benefit as well.
Maybe you are looking for
-
I am sure this has been worked out, just cant get it myself. I have a freind who uses gmail and keeps all his history of messages in his inbox. I have explained to him that its prob not the best thing to do, but that is how he has been doing it. He
-
TS3694 iPod Touch and error "21"
I have tried to restore my son's iPod touch twice and get error message "21". I have updated the iPod and have restarted the computer. The iPod was purchased in Nov 2011 and is a 32 GB iPod Touch. All I get now is the screen with an image of a USB po
-
Dear Expert, I want a report in which purchase price and sales price of each item, also if same item is sold at different ? Thanks Kevin
-
Daisy chain external drive?
I was looking into getting something like this: http://www.overstock.com/Electronics/Coolmax-Aluminum-Hard-Drive-Enclosure/24790 01/product.html for two computers to work on outside of a wireless/AirExtreme router where there isnt an option to connec
-
How to maintain the integrity of datbase??
Hi, I wanted to know that waht are the things which must always be considerd when you maintain the integrity of database and also how to maintain the security that balance the user requirement? I am asking in general point of view. hope for your prec