How to get an accurate sql query in oracle?
Hi allHope it's right,
Mr President, I was using a SQL query that can be found here:
Declare @nshiftmax datetime
Set @nshiftmax = convert (time, DATEADD(N,1439,0))
impression @nshiftmax
When extracting the result is 23:59 01/01/1900
and a single request more is there
Declare @nshiftmax datetime
Set @nshiftmax = convert (time, DATEADD (N, 0, 0))
impression @nshiftmax
When extracting the result is 01/01/1900 12:00 a.m..
How the same oracle query result.
Thanks in advance.
Like this...
SQL> select to_char(date '1900-01-01' + 1439/(24*60),'DD/MM/YYYY HH:MI AM') from dual;
TO_CHAR(DATE'1900-0
-------------------
01/01/1900 11:59 PM
SQL> select to_char(date '1900-01-01' + 0/(24*60),'DD/MM/YYYY HH:MI AM') from dual;
TO_CHAR(DATE'1900-0
-------------------
01/01/1900 12:00 AM
Tags: Database
Similar Questions
-
How do I know what sql query is taken on time for the concurrent program
Hi Sir,
I am running simultaneous program, which takes time to run, I want to know what sql query causing performance
Thanaks,
Anthony
Hi Anthony,.
Activate the traces on the simultaneous program and then run tkprof on trace file.
Octavio
-
How to get a PL/SQL output in Excelsheet &; preserve zero leak to VARCHAR
Hi all
I try to get the PL/SQL out procedure has developed the Excel sheet, I wrote the code below and it worked fine.
CREATE OR REPLACE PROCEDURE plsql_to_excel_demo IS
CURSOR cur_stock_details
IS
SELECT *.
FROM stocks;
outfile UTL_FILE.file_type;
l_chr_string VARCHAR2 (100);
l_chr_col_header VARCHAR2 (100);
l_chr_file VARCHAR2 (100);
l_chr_date VARCHAR2 (20);
BEGIN
SELECT TO_CHAR (sysdate, 'DD_MON_YYYY')
IN l_chr_date
DOUBLE;
l_chr_col_header: = "SYMBOL" | CHR (9) | ' COMPANY '. CHR (9) | "CURRENT_PRICE' | CHR (9) | ' TRADE_DATE' | CHR (9) | ' NUMBER_TRADED_TODAY'
|| CHR (9) | ' TODAYS_HIGH' | CHR (9) | ' TODAYS_LOW';
l_chr_file: = 'STOCK_REPORTS_ ' | l_chr_date |'. XLS;
outfile: = UTL_FILE. FOPEN (' / u01/app/UTL/out ', l_chr_file, 'W');
UTL_FILE. Put_line (outfile, l_chr_col_header);
FOR rec_stock_details IN cur_stock_details LOOP
/ * l_chr_string: = rec_stock_details.symbol | Chr (9) | " "| rec_stock_details.company |" ' || CHR (9)
|| rec_stock_details.CURRENT_PRICE | CHR (9) |
To_char(rec_stock_details.trade_date,'DD/mm/yyyy'). CHR (9) | rec_stock_details.number_traded_today | CHR (9) |
rec_stock_details.todays_high | CHR (9) | rec_stock_details.todays_low;
*/
l_chr_string: = rec_stock_details.symbol | Chr (9) | rec_stock_details.Company | Chr (9) | rec_stock_details.CURRENT_PRICE | CHR (9) |
To_char(rec_stock_details.trade_date,'DD/mm/yyyy'). CHR (9) | rec_stock_details.number_traded_today | CHR (9) |
rec_stock_details.todays_high | CHR (9) | rec_stock_details.todays_low;
UTL_FILE. Put_line (outfile, l_chr_string);
END LOOP;
UTL_FILE. FCLOSE (outfile);
EXCEPTION
WHILE OTHERS THEN
dbms_output.put_line (' error in hand ' |) SQLERRM);
END plsql_to_excel_demo;
/
I am faced with the question when I column VARCHAR2 say Company in the table of stocks whose value as 0000234. When I get the Excel data
sheet, I see only 234
for the name of the company. I want to keep the trailing zeros while getting the result in the Excel worksheet.
I tried with the addition of a single quotation mark ('), please see the comments in the code above, but it will give me output in the company
column in excel '0000234', which I don't.
Is it possible that I can do this job and get only 0000234 as company name in Excel.
Thanks for reading the post...
Kind regards
Shyam.
Edited by: Suryawanshi on March 22, 2010 17:40Change the function provided by Shakr as follows. Also, if your text contains numbers and characters (especially preceded by "0"), then you have to manage this type of text in function. Change the function code according to your requirement
Note: Not tested
create or replace function excel_text
(in_text in varchar2)
return varchar2
IS
out_text varchar (100);
StartIf upper (trim (in_text)) = lower (trim (in_text)) then
out_text: ='= TEXT('|| in_text ||',» ' ||) RPAD ('0', length (in_text),'0 '): ' ")';"
on the otherReturn in_text;
end if;
Return out_text;
end;
/ -
SQL Query for Oracle DB followed by using vCOPS
Hi guys,.
I installed a general SQL adapter to monitor an Oracle database in my environment. But I am not able to make it work there are a lot of problems in writing a SQL Quries. I work with one of the DBA and we are still not able to write the query to the right. Can someone give me an example of a query so that I can test it or tell me how to write the query to Oracle DB. Examples of files that are given under/samples/folder conf in the plug-in does not help us. So if someone has a link or if someone has it please help me with query files.
Thanks in advance
fix. the biggest challenge with the SQL adapter is to write the query in such a way the release of product that is easily consumable by vcops and maps directly to RESOURCEKIND and RESOURCENAME in vcops. The result can also be hierarchical for more efficiency, i.e.
metric
-submetric1
-submetric2
-
How to get the value of PMT in oracle?
Hi all
I need to calculate the value of the PMT
There is the Excel PMT function == > PMT (rate, nPer, PV, (FV), (TYPE))
I have to calculate using pl/sql.
Can any body help how to get the value of PMT in PL/SQL?
Thanks for your help.
Kind regards
IwantoThere is no Oracle built-in function to calculate the payments, but the formula is easy to find. If you look at using Excel PV function, you should find the formula that excel uses to calculate. You can rearrange the calculation in terms of payment. If FV and TYPE are 0, then the calculation is
PV*rate*power((1+rate),nPer)/(power((1+rate),nPer) - 1)
You don't need really PL/SQL to do this.
Kind regards
Bob -
How only migrate data between SQL Server 2008 Oracle 11?
According to our requirement, we only have to migrate data from a SQL Server database to an existence
Oracle database user.
(1) I tried to do with the wizard of Migration SQL Developer 3.0.04, but find a problem.
My SQL Server database name is SCDS41P2 and my Oracle database user name is CDS41P2;
When I used SQL Developer move offline data by the Migration Wizard, I found all the oracle user
name in movedata files who obtained by running the Migration Wizard
is dbo_SCDS41P2. If the Oracle user name is not the same as my Oracle username existed.
the data cannot be moved to my user Oracle existed when I run oracle_ctl.bat in the command line window.
So I had to change the Oracle username in all the movedata files, but it is difficult to change because there are a lot of tables in
databases. So could you please tell me how to get the movedata files which is the name of user oracle in them my
WHEREAS Oracle user name?
(2) I also tried to use the "copy to Oracle" to copy the data to SQL Server database tables
the user database was Oracle. When you click on 'copy to Oracle', I selected the option 'Include data' and 'replace '.
But I found some tables cannot be copied, the error info is as below:
SPSSCMOR_CONTROLTABLE table failed. Message: ORA-00955: name is already used by an existing object
Could you please tell me how to deal with this kind of mistake?
Thank you!
Published by: 870587 on July 6, 2011 02:57Hello
After following with development the following should work too-1 use the migration option to capture and convert the SQL * database server
2. go in SQL * Developer and remove the converted model.
3. click on the captured model and choose 'convert '.
4. click Next and you should get a screen with 2 options - "Data Type Mapping" and "Object Naming.
5. choose "Object Naming" and scroll down the list until you see the name of the user who will be transformed. For example, in my test, I got the names scott_test and dbo_test - where the owners are 'scott' and 'dba' and 'test' was the name of the database.
6. change the name of oner_database to just owner - scott_test to scott
7 complete the conversion process and the owners must be created without the name of the database.
8. you should now be able to generate the SQL * scripts of charger with only the name of the owner in the CTL files.Please try this and let us know if it works for you.
Kind regards
Mike -
Convert the SQL query to Oracle
Hi all
I have two SQL queries to create the table.
Query1.
CREATE TABLE [dbo]. [DocumentType] (
[DocType] [varchar] (20) GATHER SQL_Latin1_General_CP1_CI_AS NOT NULL,.
[SubCat] [varchar] (20) GATHER SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo]. [DocumentType] ADD
CONSTRAINT [PK_DocumentType] PRIMARY KEY CLUSTER
(
[DocType],
[SubCat]) ON [PRIMARY]
Query2.
CREATE TABLE [dbo]. [SBU] (
[SBU] [varchar] (51) GATHER SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo]. [SBU] ADD
[PK_SBU] CLUSTERED PRIMARY KEY CONSTRAINT
(
[SBU]
) ON [PRIMARY]
What will be the query in Oracle?
Please suggest!
Kind regards
ShahQuery1.
CREATE TABLE dbo. DocumentType)
DocType varchar2 (20) NOT NULL,
SubCat varchar (20) NOT NULL,
CONSTRAINT PK_DocumentType PRIMARY KEY (DocType, SubCat)
)
/Query2.
CREATE TABLE dbo. SBU)
SBU varchar2 (51),
CONSTRAINT PK_SBU PRIMARY KEY (UDF)
)
/It is useful for you?
Published by: insa on June 12, 2012 22:42
-
Hello
I have an app running, but does not end.
I can see the SQL, but I need to find out what PL/SQL-package the SQL.
Does anyone have a tip for me where to look?
There are many examples in order to recover the call in the exception management stack, but none to recover by session_id.
Thanks in advance,
Mynz
Columns in session $ v % plsql_ can help, the query below is about the same.
https://community.Oracle.com/thread/2232972?TSTART=0Alternatively, you can get some respect distinctive within the SQL text and research in dba/all/user_source for him.
-
How can I write the SQL query for this requirement?
Hello
I have a table that looks like this:
NAME | ANNUAL | VALUE
==== | ====== | =====
execno | 480. 000004
step | 480. 0400
SCNA | 480. cd_demo
System | 480. D47-010
type | 480. step
free_text | 480. stage 400
rbare | 480. RBA-1
execno | 482. 000004
SCNA | 482. cd_demo
System | 482. D47-010
free_text | 482. step 300
step | 482. 0300
type | 482. step
rbare | 482. RBA-1
execno | 483. 000001
type | 483. step
rbare | 483. rke1
SCNA | 483. rke10
step | 483. 0240
Now, say that I want to fetch ONLY annual with execno = '000004' and '400' = step and scna = "cd_demo" and system = "d47-010' and type = 'step', how to write SQL code?
At first, it seemed like a simple writing query but I've been struggling with it for hours without success. I must admit though that I'm not strong in SQL :-)
There, can anyone help? Please...
Thanks in advance.
Emmanuel
Published by: user12138559 on October 30, 2009 03:05Hi, Emmanuel.
Welcome to the forum!
Here's a way to do what you asked:
SELECT doc_id FROM table_x GROUP BY doc_id HAVING SUM (CASE WHEN name = 'execno' AND value = '000004' THEN 1 END) > 0 AND SUM (CASE WHEN name = 'step' AND value = '400' THEN 1 END) > 0 AND SUM (CASE WHEN name = 'scna' AND value = 'cd_demo' THEN 1 END) > 0 AND SUM (CASE WHEN name = 'system' AND value = 'd47-010' THEN 1 END) > 0 AND SUM (CASE WHEN name = 'type' AND value = 'step' THEN 1 END) > 0 ;
If you think that a WHERE clause would be used, but WHERE does apply to a single line. You need a condition that checks several rows in the same group.
WHEN has an effect something like WHERE.Published by: Frank Kulash, October 30, 2009 06:26
This solution assumes that (name, annual) is unique.
-
How to transform this PL/SQL query in a PL/SQL function?
Salvation of nice people!
I have a nice flash chart that SQL code is below. I want to see this table only if this query returns results. I tried to put it in condition. How transformt this ciode SQL "SLQ function returning a Boolean"?
Thank you for your kind replies.DECLARE X VARCHAR2 (4000); BEGIN x := 'SELECT NULL LINK, trunc(a.DATE1, '''||:P13_TRUNC||'''), avg(b.pourcentage_remplissage) FROM EVV_'||:P13_SITE||' a, bassin_remplissage b WHERE a.CLEF_VAR = (SELECT CLEF_VAR FROM SITE_ECHELLE WHERE SITE='''||:P13_SITE||''') AND round(a.valeur, 1) = b.cote_ngf AND DATE1 BETWEEN TO_DATE ('''||:P13_DATE_DEBUT||'000000'', ''DD/MM/YYYYHH24MISS'') AND TO_DATE ('''||:P13_DATE_FIN||'235959'', ''DD/MM/YYYYHH24MISS'') group by trunc(a.DATE1, '''||:P13_TRUNC||''') ORDER BY trunc(a.DATE1, '''||:P13_TRUNC||''')'; RETURN (X); END;
ChristianChristian:
Try this
DECLARE x VARCHAR2 (4000); BEGIN x := 'SELECT COUNT(*) FROM EVV_' || NVL(:p13_site, 'E003') || ' a, bassin_remplissage b WHERE a.CLEF_VAR = (SELECT CLEF_VAR FROM SITE_ECHELLE WHERE SITE=''' || NVL(:p13_site, 'E003') || ''') AND round(a.valeur, 1) = b.cote_ngf AND DATE1 BETWEEN TO_DATE (''' || NVL(:p13_date_debut, '01/01/1980') || '000000'', ''DD/MM/YYYYHH24MISS'') AND TO_DATE (''' || NVL(:p13_date_fin, '01/01/2080') || '235959'', ''DD/MM/YYYYHH24MISS'') '; EXECUTE IMMEDIATE x INTO WWV_FLOW.g_id; IF wwv_flow.g_id IS NULL OR wwv_flow.g_id = 0 THEN RETURN FALSE; ELSE RETURN TRUE; END IF; END;
Published by: city has 8 July 2009 06:12
Moved the 'back' clause where it should be :)Published by: city has 8 July 2009 06:13
-
How to get a year back dynamically in Oracle?
Hello experts,
I try to create partitions on a table and would go back up to the year last to create partitions. I am currently hardcode values. I want to configure it dynamically based on SYSDATE. Someone here could help me please?
CREATE TABLE PRDT_SALES (SALES_ID NUMBER NOT NULL ENABLE, PRDT_NM VARCHAR2(50 CHAR) NOT NULL ENABLE, SALE_START TIMESTAMP (6), SALE_END TIMESTAMP (6), PRDT_TYPE VARCHAR2(50 CHAR), PRDT_NM VARCHAR2(50 CHAR), PRDT_CODE VARCHAR2(50 CHAR), PRDT_DESC VARCHAR2(50 CHAR), SALE_DT DATE NOT NULL ENABLE, SALE_UPDT_TS TIMESTAMP (6) DEFAULT SYSTIMESTAMP NOT NULL ENABLE ) PARTITION BY RANGE (SALE_DT) (PARTITION P20131001 VALUES LESS THAN (TO_DATE('2013-10-02 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) );
Later, I am running this script.
DECLARE c_start_dt DATE := TO_DATE ('11-NOV-2013') ; c_end_dt DATE := TO_DATE ('11-NOV-2014'); BEGIN FOR dt_rec IN (SELECT 'P' || TO_CHAR (dt, 'YYYYMMDD') AS part_nm, dt + 1 AS part_dt FROM (SELECT c_start_dt - 1 + ROWNUM AS dt FROM all_objects WHERE c_start_dt - 1 + ROWNUM <= c_end_dt ) ORDER BY dt ) LOOP EXECUTE IMMEDIATE 'ALTER TABLE prdt_sales' || ' ADD PARTITION ' || dt_rec.part_nm || ' VALUES LESS THAN (TO_DATE(' || '''' || TO_CHAR (dt_rec.part_dt, 'DD-MON-YYYY') || '''' || ',' || '''' || 'DD-MON-YYYY' || '''' || '))'; END LOOP; END; /
I would like to know how to make the c_start_dt and dynamic c_end_dt based on SYSDATE.
Thank you
Julaayi
Thank you. This helped.
Just to clarify, we need to declare it as date.
c_start_dt DATE: = trunc ((sysdate-12) add_months);
c_end_dt DATE: = trunc (sysdate);
-
How to get current utc date time in oracle
Hello
SYSDATE shows date current time in the time zone based on SessionTimeZone. Is there a built in function or in some other way to get the current utc date time without changing the value of the SessionTimeZone.
Thank you
YGOr
SELECT SYS_EXTRACT_UTC(SYSTIMESTAMP)UTC_SYS, SYSTIMESTAMP FROM DUAL;
* 009 *.
-
SQL query to get the numbers from 0 to 99
How can we write a sql query to get values from 0 to 99... This should not come from any tableSELECT LEVEL - 1 FROM DUAL CONNECT BY LEVEL <= 100 /
SY.
-
Hello
Suppose I need to check the number of records of 30 tables in the oracle database in a particular schema, it may have hundreds of tables.
How to check with simple sql query.I know that under method,
Select count (*) from
Table1, table2, table3... table30;But I need in format below. If I use Group by we will get but we must specify all 30 tables to groupby, is any alternative group instead of keep all 30 tables
SELECT TABLENAME, COUNT (*)
OF table1, table2, table3... table30Group of table1, table2, table3... table30;
Try the following query if all tables are present in the same pattern in the case otherwise you must use dba_tables:
SELECT table_name, to_number( extractvalue( XMLTYPE( dbms_xmlgen.getxml('select count(*) c from '||table_name)) ,'/ROWSET/ROW/C')) count FROM user_tables WHERE table_name IN ('A','B','C') ORDER BY table_name;
-
How to get LASTDAY for each month between data dates...
Hi friend
I have a doubt, how to get LASTDAY for each month between data dates...
for ex:
My contribution will be like this
date = 01/12/2011
To date = 14/04/2011
And I need an output like
31/01/2011
28/02/2011
31/03/2011
is it possible to achieve through sql query in oracle
Thanks in advance for all friends to help himHello
Something like this (assuming that the dates are originally VARCHAR2s):
SQL> var dt_start varchar2(10) SQL> var dt_end varchar2(10) SQL> exec :dt_start := '12-01-2011' PL/SQL procedure successfully completed SQL> exec :dt_end := '14-04-2011' PL/SQL procedure successfully completed SQL> SQL> select last_day( 2 add_months( 3 trunc(to_date(:dt_start,'DD-MM-YYYY'),'MM'), 4 level-1 5 ) 6 ) as result 7 from dual 8 connect by level <= months_between(to_date(:dt_end,'DD-MM-YYYY'), to_date(:dt_start,'DD-MM-YYYY')) 9 ; RESULT ----------- 31/01/2011 28/02/2011 31/03/2011
If the dates are already of the date data type, simply remove the to_date function.
Maybe you are looking for
-
I just got an email. Is - this truth? Anyone know? Thank you all!
-
Receiver fake spam on Thunderbird myself.
Turned on my computer at work and I get an avalanche of spam from my own email every minute Thunderbird checks for new emails. Each message is titled "MyFax message 'unknown' from - 3 page (s)" with at: [email protected]. It doesn't make sense as to w
-
I have a CD for my HP DeskjetD1460, on this laptop which has XP Ms. now I have a new laptop with Ms Vista but my Cd is said to use on XP. How to get a CD or download to the Vista system? and are there fees? Thks
-
Hello I have a Toshiba Qosmio G50-10 t and I want to replace the keyboard on the Toshiba Qosmio X 500 - 110.I know the topic is 4001lvl forum, but maybe someone knows where, how, where you can order the keyboard.
-
I need instructions to connect my laptop to my TV using a HMDI cable.
HP G60 laptop. Windows Vista 32-bit I cannot connect my laptop to my TV using an HDMI cable. Any suggestion would be appreciated.