Issue in converting sql query to oracle
Hi Friends,
I have a sql query as follows,
Select Name From SysObjects Where XType = 'U' And Name = @NameI want to convert this to oracle. I have tried to convert this in someways. But I'm getting errors only. Please anyone help me to fix this issue.
Thanks,
Ram
Most Oracle dictionary views come in DBA_, ALL_ and USER_ flavours. Probably you don't have privileges to view DBA_OBJECTS, in which case try ALL_OBJECTS or <a gref="http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_2005.htm">USER_OBJECTS</a>.
Based on what I read, you might need something like
SELECT * FROM all_objects WHERE owner <> 'SYS' AND object_type = 'TABLE'btw a sure way to wind up Oracle professionals is to use "SQL" to mean another DBMS product and not Structured Query Language. As you may have noticed, we have SQL over here as well.
Similar Messages
-
How to convert sql query to oracle query?
Hi all,
Hope doing well,
sir i am using oracle database where i am running my sql query in oracle. but this query is not working properly. i used sql developer translation scratch editor to convert that.
it's converted but i am not getting the exact value.
which i was getting in sql server.
here is my query below:
SELECT C.*,ISNULL(P.Comp_Name,'') + ' (' + ISNULL(P.Comp_ID,'') + ')' Parent FROM Comp_Master C LEFT JOIN Comp_Master P ON C.Parent_ID = P.Comp_ID Where C.Comp_ID='C02'
please convert it into oracle so that i can use this query
thanks in advance.Try --
1. Use NVL instead of isNull
2. Use *||* instead of +*
/* Formatted on 9-13-2012 4:39:09 PM (QP5 v5.163.1008.3004) */
SELECT c.*, NVL (p.comp_name, '') || ' (' || NVL (p.comp_id, '') || ')' parent
FROM comp_master c LEFT JOIN comp_master p ON c.parent_id = p.comp_id
WHERE c.comp_id = 'C02'
PS - Do remember to mark the solutions as Helpful or Correct. Thanks for understanding. -
Hi All,
I have two queries of SQL for creating table.
Query1.
CREATE TABLE [dbo].[DocumentType] (
[DocType] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[SubCat] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DocumentType] ADD
CONSTRAINT [PK_DocumentType] PRIMARY KEY CLUSTERED
[DocType],
[SubCat]) ON [PRIMARY]
Query2.
CREATE TABLE [dbo].[SBU] (
[SBU] [varchar] (51) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[SBU] ADD
CONSTRAINT [PK_SBU] PRIMARY KEY CLUSTERED
[SBU]
) ON [PRIMARY]
What will be the Query in Oracle??
Please suggest!!!
Regards,
ShahHi,
First of all you need to go to scheme in which you need to create those tables. Or you can do it from sys user by giving allias.
I will explaing you by going to user account.
open command prompt --> sqlplus --> userid@database_name enter-->password
write below commands :-
CREATE TABLE DocumentType
DocType varchar(20) NOT NULL ,
SubCat varchar(20) NOT NULL
ALTER TABLE DocumentType ADD
CONSTRAINT PK_DocumentType PRIMARY KEY on (DocType);And same for the second table.
Enjoy. -
Sub-Select SQL query in Oracle BI Answers
Hi
What's the proper usage of Sub-Select SQL query in Oracle BI Answers Version Oracle Business Intelligence 10.1.3.2.1?
I get [SQL_STATE: HY000] [nQSError: 10058] A general error has occured when trying to Sub Select query like:
itemno = (SELECT MIN(orders.itemno) FROM mydatabase where rownum < 2 order by orders.itemno)Maybe the best is to create a new physical and logical object for your sub-select and join this with your current objects.
-
Issue with SQL query of Oracle Apps Alert
Hi,
I have build the following SQL Query for one of the alert.
But when i try to valid it it is throwing an error as
"APP-ALR-04108: SQL Error - ORA-07144 in appropriate into occurred in '
My SQL is as follows:
===============
SELECT details into
&v_details from (SELECT 2, RPAD(SUBSTR(lookup_code,1),25,' ') ||' - '||RPAD(SUBSTR(NVL(lu.description,' '),1),240,' ') Details
INTO &V_seq,&V_resp
from apps.FND_LOOKUP_VALUES_VL lu,apps.fnd_user fu
where lookup_type ='XX_TEST'
AND lookup_code = fu.user_name
AND (fu.end_date IS NULL OR fu.end_date >= SYSDATE))
Please help on this.
Thanks,
NazWhy there are 2 into clauses? You need to change your query to fetch all columns first and then use into to fetch into variables.
Thanks
Shree -
Doubt in conversion of SQL query to oracle
Hi guys,
I'm new to oracle. I have a SQL query like the following,
Select * From my_table With(Index(PK_my_key))
I want to convert this to oracle. How can I specify the syntax *'With(Index(PK_my_key)) '* in oracle.
Please advice.
RamIs it possible to test that and find out the performance of the query? You need to check the execution plan of the query.
See these informative threads that explain in more detail :
When your query takes too long... When your query takes too long ...
How to post a SQL statement tuning request HOW TO: Post a SQL statement tuning request - template posting
Also, please post your database version (the result of: select * from v$version; ).
INDEX hints are nowadays (almost) never needed, unless you're on ancient database version.
As SomeoneElse already said: let Optimizer decide. -
Sql query from Oracle/Hyperion
Hi, guys. my problem is:
My work environment is windows 2003 server sp2 on both servers, to have a Hyperion System 9.2 and the other Hyperion System 9.3.1. I have an Oracle ODBC server to fetch data.
When you load data from an Oracle database (version 9.2.0.5) to an Essbase cube through a rule file sql Hyperion System with version 9.2 everything works fine, I am all the necessary information. But when I try to do the same (in another server, version 9.3.1 Hyperion System) with the sql query does not do well. What is the problem. the bag is a bad version or set the ODBC
please help me
Thank you very much.
Alberto.without knowing more information, I'm going to guess the probem is with the ODBC driver. Try using the SQL in a tool like toad to use the ODBC to query the data. That will tell you if it is an ODBC issue or not.
-
Can anyoone help me out to convert this SQL query in SSRS.
create table tickets_every_hour_ict(ddate datetime,dgroup varchar(50))
Insert into tickets_every_hour_ict
Select
--incident.actie,
incident.dataanmk ,
incident.ref_operatorgroup
/*,incident.ref_status as "Status",
incident.datumaangemeld as "Datum aanmelding" */
From incident
WHERE incident.dataanmk >= DATEADD(day,-7, GETDATE())
AND incident.ref_operatorgroup in ('Automatisering')
order by incident.dataanmk desc
Select ddate1,[00:00],[01:00],[02:00],[03:00],[04:00],[05:00],[06:00],[07:00],[08:00],[09:00],[10:00],[11:00],[12:00],
[13:00],[14:00],[15:00],[16:00],[17:00],[18:00],[19:00],[20:00],[21:00],[22:00],[23:00]
From
Select dgroup 'dgroup',cast(Convert(varchar(10),ddate,101)+' '+ convert(varchar(3),ddate,108) +'00' as date) ddate1,convert(varchar(3),ddate,108) +'00' dtime From tickets_every_hour_ict
)p
PIVOT
Count(dgroup) for dtime in([00:00],[01:00],[02:00],[03:00],[04:00],[05:00],[06:00],[07:00],[08:00],[09:00],[10:00],[11:00],[12:00],
[13:00],[14:00],[15:00],[16:00],[17:00],[18:00],[19:00],[20:00],[21:00],[22:00],[23:00])
)PVTIn SSRS you just need to use matrix container and use query as below
Select dgroup 'dgroup',cast(Convert(varchar(10),ddate,101)+' '+ convert(varchar(3),ddate,108) +'00' as date) ddate1,convert(varchar(3),ddate,108) +'00' dtime From tickets_every_hour_ict
Then in report add dtime column inside column group of matrix and add
=Count(Fields!dgroup.value)
as expression inside data area.
add
ddate1 to row group and you'll get pivoted values
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
I created it your way but then it will not show the tables with 0. I want it to show all hours even if the count is 0. -
Converting this query to Oracle-Help
New account as my old email address has changed so I had to create a new one. Sucks!
Either way can I please get some help with converting the query below to oracle syntax not microsoft sql. Cheers
select eventtypeid as Payment_Type,
sum(commission_amount) as commission_amount,
startdate as commission_date
from
SELECT distinct
PERIOD.STARTDATE,
Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE,
case when Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE in ('2573','185')
then 'D'
when Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE in ('1126','1055')
then 'O'
when Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE in ('789','4000','785','871','1028','743')
then 'R'
else Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE
end as SDC,
Master_Usage.GENERICATTRIBUTE2 AS Service_Id,
Master_Usage.EVENTTYPEID,
sum(Master_Usage.CONTRIBUTIONVALUE) AS Commission_Amount
FROM Master_Usage INNER JOIN PERIOD
ON Master_Usage.PERIODSEQ = PERIOD.PERIODSEQ
INNER JOIN (select distinct
lastname,
super_distributor_code,
distributor_code,
participantid,
startperiod
from Dealer_Hierarchy_107_114
where startperiod in ('107','108','110','111','112','114')
AND NOT POSITIONTYPEID LIKE 'MI %'
and not super_distributor_code = 'null' or distributor_code = 'null') as dealer_hierarchy
ON Master_Usage.GENERICATTRIBUTE1 = dealer_hierarchy.PARTICIPANTID and dealer_hierarchy.startperiod in ('107','108','110','111','112','114')
WHERE
(NOT Master_Usage.PRODUCTID = 'IDDV' OR Master_Usage.PRODUCTID IS NULL)
AND Master_Usage.PERIODSEQ in ('107','108','110','111','112','114')
and Dealer_Hierarchy.startperiod in ('107','108','110','111','112','114')
and Master_Usage.NAME not like '%revenue%'
and Master_Usage.name not like '%GST%'
group by PERIOD.STARTDATE,
Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE,
Master_Usage.GENERICATTRIBUTE2,
Master_Usage.EVENTTYPEID
) as asf
group by asf.EVENTTYPEID,
startdate
order by commission_amount descplease see the bold section,
could that be the reason ??
select eventtypeid as Payment_Type,
sum(commission_amount) as commission_amount,
startdate as commission_date
from
SELECT distinct
PERIOD.STARTDATE,
Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE,
case when Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE in ('2573','185')
then 'D'
when Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE in ('1126','1055')
then 'O'
when Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE in ('789','4000','785','871','1028','743')
then 'R'
else Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE
end as SDC,
Master_Usage.GENERICATTRIBUTE2 AS Service_Id,
Master_Usage.EVENTTYPEID,
sum(Master_Usage.CONTRIBUTIONVALUE) AS Commission_Amount
FROM Master_Usage INNER JOIN PERIOD
ON Master_Usage.PERIODSEQ = PERIOD.PERIODSEQ
INNER JOIN (select distinct
lastname,
super_distributor_code,
distributor_code,
participantid,
startperiod
from Dealer_Hierarchy_107_114
where startperiod in ('107','108','110','111','112','114')
AND NOT POSITIONTYPEID LIKE 'MI %'
and not (super_distributor_code = 'null' or distributor_code = 'null') as dealer_hierarchy
ON Master_Usage.GENERICATTRIBUTE1 = dealer_hierarchy.PARTICIPANTID and dealer_hierarchy.startperiod in ('107','108','110','111','112','114')
WHERE
(NOT Master_Usage.PRODUCTID = 'IDDV' OR Master_Usage.PRODUCTID IS NULL)
AND Master_Usage.PERIODSEQ in ('107','108','110','111','112','114')
and Dealer_Hierarchy.startperiod in ('107','108','110','111','112','114')
and Master_Usage.NAME not like '%revenue%'
and Master_Usage.name not like '%GST%'
group by PERIOD.STARTDATE,
Dealer_Hierarchy.SUPER_DISTRIBUTOR_CODE,
Master_Usage.GENERICATTRIBUTE2,
Master_Usage.EVENTTYPEID
) as asf
group by asf.EVENTTYPEID,
startdate
order by commission_amount desc -
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 use this sql query in oracle?
Hi all,
i am using one sql query that is
SELECT @ToDate = '2012-10-03 00:00:00.000'
select @BetweenDate = DATEADD(MM,-1,@ToDate)
select @FromDate = DATEADD(m,DATEDIFF(m,0,@BetweenDate),0)
SELECT @ToDate = DATEADD(month, ((YEAR(@BetweenDate) - 1900) * 12) + MONTH(@BetweenDate), -1)
so @todate value is = '2012-10-03 00:00:00.000'
so in @betweendate value will come 1 month before like '2012-09-03 00:00:00.000'
again in @fromdate value will come like that '2012-09-01 00:00:00.000' means first date of @betweendate
and again @todate value will come like that '2012-09-30 00:00:00.000' means last date of @betweendate
it's happening in sql and i have to use same logic in oracle also.
how to use it??
thanksdeclare
todate date:= to_date('2012-10-03 00:00:00','yyyy-mm-dd hh:mi:ss');
betwendate date := add_months(todate,-1);
for datediff / additions you can direct subtract/add two different date variables
like
datediff = betweendate -todate
dateadd := todate+1; -
Store SQL Query in Oracle database
Hello,
I am storing SQL query in database. here is an example of query.
INSERT INTO TABLE_1 Values (' " + getValue1() + " ', ' " + getValue2() + " ' )
getValue1() and getValue2() are functions to retrieve values.
When I read query from the database and execute it, it doesn't read values from function.
After I read query from database I would expect it to be
INSERT INTO TABLE_1 Values ('value1', ' value2' ) but it is not reading values and trying to execute whatever I got from database.
Any help?
ThanksThanks for your reply. Let me give you more info.
All I am trying to do is storing queries in oracle
database to use it in future for reporting. As I am
doing reporting where clause will be different every
time. Reporting involves queries not updates. But in any case that means that you would use a java SQL string that is useable via a prepared statement. As such your statement would look like....
INSERT INTO TABLE_1 Values (?,?)
Is it not possible to substitute variable string I
got from database?What do you mean?
SQL is SQL. You construct SQL so it is valid and runs. Can you construct SQL so it runs a function/select and uses that value in some more SQL - depends on the database, but usually.
But that has nothing to do with java - it is SQL.
Query contains variables that I have in Java code .Then it is SQL. It is java. You use bind variables (see PreparedStatement) and assign values to it.
The SQL for such a query would look like the following...
select field1, field2 from table1 where id=?
In your java you would then use something like PreparedStatement.setInt(1, 100), to fill in the value for the '?' in the above.
You might also note that your solution will not work for any arbritrary SQL statement unless you are also storing meta data about the SQL itself. For instance the following SQL statements would return the same result set but your java code would have to populate the bind variables different for both...
select field1, field2 from table1 where id=? and name=?
select field1, field2 from table1 where name=? and id=? -
Can users see the query plan of a SQL query in Oracle?
Hi,
I wonder for a given sql query, after the system optimization, can I see the query plan in oracle? If yes, how to do that? thank you.
XingYou can use explain plan in SQLPlus
SQL> explain plan for select * from user_tables;
Explained.
Elapsed: 00:00:01.63
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
Plan hash value: 806004009
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 2014 | 1123K| 507 (6)| 00:00:07 |
|* 1 | HASH JOIN RIGHT OUTER | | 2014 | 1123K| 507 (6)| 00:00:07 |
| 2 | TABLE ACCESS FULL | SEG$ | 4809 | 206K| 34 (3)| 00:00:01 |
|* 3 | HASH JOIN RIGHT OUTER | | 1697 | 873K| 472 (6)| 00:00:06 |
| 4 | TABLE ACCESS FULL | USER$ | 74 | 1036 | 3 (0)| 00:00:01 |
|* 5 | HASH JOIN OUTER | | 1697 | 850K| 468 (6)| 00:00:06 |
| 6 | NESTED LOOPS OUTER | | 1697 | 836K| 315 (6)| 00:00:04 |
|* 7 | HASH JOIN | | 1697 | 787K| 226 (8)| 00:00:03 |
| 8 | TABLE ACCESS FULL | TS$ | 13 | 221 | 5 (0)| 00:00:01 |
| 9 | NESTED LOOPS | | 1697 | 759K| 221 (8)| 00:00:03 |
| 10 | MERGE JOIN CARTESIAN | | 1697 | 599K| 162 (10)| 00:00:02 |
|* 11 | HASH JOIN | | 1 | 326 | 1 (100)| 00:00:01 |
|* 12 | FIXED TABLE FULL | X$KSPPI | 1 | 55 | 0 (0)| 00:00:01 |
| 13 | FIXED TABLE FULL | X$KSPPCV | 100 | 27100 | 0 (0)| 00:00:01 |
| 14 | BUFFER SORT | | 1697 | 61092 | 162 (10)| 00:00:02 |
|* 15 | TABLE ACCESS FULL | OBJ$ | 1697 | 61092 | 161 (10)| 00:00:02 |
|* 16 | TABLE ACCESS CLUSTER | TAB$ | 1 | 96 | 1 (0)| 00:00:01 |
|* 17 | INDEX UNIQUE SCAN | I_OBJ# | 1 | | 0 (0)| 00:00:01 |
| 18 | TABLE ACCESS BY INDEX ROWID| OBJ$ | 1 | 30 | 1 (0)| 00:00:01 |
|* 19 | INDEX UNIQUE SCAN | I_OBJ1 | 1 | | 0 (0)| 00:00:01 |
| 20 | TABLE ACCESS FULL | OBJ$ | 52728 | 411K| 151 (4)| 00:00:02 |
Predicate Information (identified by operation id):
1 - access("T"."FILE#"="S"."FILE#"(+) AND "T"."BLOCK#"="S"."BLOCK#"(+) AND
"T"."TS#"="S"."TS#"(+))
3 - access("CX"."OWNER#"="CU"."USER#"(+))
5 - access("T"."DATAOBJ#"="CX"."OBJ#"(+))
7 - access("T"."TS#"="TS"."TS#")
11 - access("KSPPI"."INDX"="KSPPCV"."INDX")
12 - filter("KSPPI"."KSPPINM"='_dml_monitoring_enabled')
15 - filter("O"."OWNER#"=USERENV('SCHEMAID') AND BITAND("O"."FLAGS",128)=0)
16 - filter(BITAND("T"."PROPERTY",1)=0)
17 - access("O"."OBJ#"="T"."OBJ#")
19 - access("T"."BOBJ#"="CO"."OBJ#"(+))
42 rows selected.
Elapsed: 00:00:03.61
SQL> If your plan table does not exist, execute the script $ORACLE_HOME/RDBMS/ADMIN/utlxplan.sql to create the table. -
Optimizing an SQL Query using Oracle SQL Developer
Hi ,
Currently i am using Oracle SQL Developer as my Database IDE .
Is it possible to use Orqcles SQLDeveloper for the purpose of Optimizing an SQL Query ??
For example assume i am having a query as :
Select from Tranac_Master where CUST_STATAUS='Y' and JCC_REPORT='N'*
Could anybody please tell me how can i use Oracle SQL Developer to optimize this query or any other SQL queries ??
Please share your ideas , thanks in advance .1. Your query looks very simplistic as it is, so I fail to see how you can better optimise it (unless 'Tranac_Master' is a view, in which case I'd need to see the view details).
2. No tool can automagically optimise your SQL to any degree of practical use. Very minor adjustments may be possible automatically, but really it is a question of you knowing your data & database design accurately, and then you applying your expert knowledge to tune it. -
How to convert Access query to Oracle?
I am trying to convert this query into an Oracle 8i query: -
SELECT *
FROM EMPLOYEE
LEFT JOIN ATTENDANCE ON EMPLOYEE.EMPID = ATTENDANCE.EMPID
WHERE ATTENDANCE.COL1="#"
AND ATTENDANCE.COL2>=#1/1/2007#
AND ATTENDANCE.COL2<Now()
GROUP BY EMPLOYEE.EMPID, EMPLOYEE.EMPNO;
How do I put the above query in plain Oracle join operator (+) notation? Thanks for the help.Hi,
Let us take a look at the solution you had suggested -
EMPLOYEE.EMPID = ATTENDANCE.EMPID (+)
AND ATTENDANCE.COL1="#"
AND ATTENDANCE.COL2 >= TO_DATE ('1/1/2007','dd/mm/yyyy')
AND ATTENDANCE.COL2< SYSDATE;
Since we are outer joining ATTENDANCE but not using the (+) operator in the later filter conditions; it will still be a normal join i.e. it will not outer join on ATTENDANCE. That is my question.
Maybe you are looking for
-
DVR620 incorrect aspect ratio when recording DVD or VHS
I have a DVR620KU connected to a Sony Digital LCD Bravia TV, Sony HT-CT100 Home Theater system and a Scientific Atlantic Explorer 8300HDC cable box. I am using HDMI cables except for the connection from the "out" on cable box to the "in" on the DVR6
-
How to read a local file from Applet Code
Hi I am developing a application and i want to access a local file from the applet So pls help me in coding for this
-
Unable to import table using SOA database adapter in jdeveloper
I am trying to build a simple flow to access database so I have dropped a database adapter in composite.xml and trying to configure the adapter. I have successfully tested the database connection within the adapter configuration wizard and can view t
-
Parallel ABAP programming while using references
Hi SCN, first of all the context of my problem, to get to its root: I have created a kind of Framework (object oriented), which later on will provide an easy way to set up Charts in a Dashboard. Put simply, the framework works like this: There is a i
-
The situation is: A portal page is configured that requires login before accessing this page. Oracle portal logon server PL/SQL API is used to verify the user id, password and privilege. Thus, whenever the user dosen't have enough privilege to access