Simple SQl statement help needed!!!
New to SQL..Please can you advice where is the problem..
select file_id, a.file_name, a.sum(bytes/1024/1024) Used_space, b.sum(bytes/1024
/1024) Free_space from dba_data_files a, dba_free_space b where tablespace_name
='DATA_TS' OR tablespace_name='INDEX_TS' OR tablespace_name='LOB_TS' group by fi
le_id
ERROR at line 1:
ORA-00918: column ambiguously defined
Thanks!
Hi,
Should you chose to format your SQL the problem is easily seen:
SQL>select file_id
2 ,a.file_name
3 ,a.sum(bytes / 1024 / 1024) used_space
4 ,b.sum(bytes / 1024 / 1024) free_space
5 from dba_data_files a, dba_free_space b
6 where tablespace_name = 'DATA_TS'
7 or tablespace_name = 'INDEX_TS'
8 or tablespace_name = 'LOB_TS'
9 group by file_id;
group by file_id
ERROR at line 9:
ORA-00918: column ambiguously defined
SQL>So, which file_id do you want - a or b?
Regards
Peter
Similar Messages
-
I am sure some of you will laugh lol, but I am drawing a blank and need some assistance if anyone is willing to help:
I have this query:
SELECT DISTINCT ID
FROM (SELECT productcode
FROM sforce_product2
WHERE productcode NOT LIKE 'DSXXX%'
AND productcode NOT LIKE 'DO NOT USE%'
AND productcode NOT LIKE 'MAXXXX%'
AND isactive = 'true'
MINUS
SELECT productcode
FROM vew_product_export) a,
sforce_product2
WHERE a.productcode = sforce_product2.productcode
which returns 112 ID's (which is wrong)
The inner SELECT statement:
SELECT productcode
FROM sforce_product2
WHERE productcode NOT LIKE 'DSXXX%'
AND productcode NOT LIKE 'DO NOT USE%'
AND productcode NOT LIKE 'MAXXXX%'
AND isactive = 'true'
MINUS
SELECT productcode
FROM vew_product_export
returns 106.
Am I doing something simple wrong or is my query just mangled!
TIA,
MikeSELECT DISTINCT ID
FROM (SELECT productcode
FROM sforce_product2
WHERE productcode NOT LIKE 'DSXXX%'
AND productcode NOT LIKE 'DO NOT USE%'
AND productcode NOT LIKE 'MAXXXX%'
AND isactive = 'true'
MINUS
SELECT productcode
FROM vew_product_export) a,
sforce_product2
WHERE a.productcode = sforce_product2.productcodethe above code is returning an ID column which i think most probable from the sforce_product2 table
while this query below returns the 106 value that is coming from the column productcode.
SELECT productcode
FROM sforce_product2
WHERE productcode NOT LIKE 'DSXXX%'
AND productcode NOT LIKE 'DO NOT USE%'
AND productcode NOT LIKE 'MAXXXX%'
AND isactive = 'true'
MINUS
SELECT productcode
FROM vew_product_exportso i think there is nothing wrong because if you will review the 112 is from the column ID while the 106 is from the column productcode. -
Can we Run a simple SQL statement from OBIEE Middle Tier node
Hi
i am working in OBIEE 11g environment. Database is installed on one node and Middle tier (BI services ) in other node,
Can i use any utility to run a simple SQL statement from Middle tier ?
Thanks
ReddyAny utility means?
We can create an ODBC connection on the BI server and run the sql.
Mark if helps. -
Copy records: is there a simpler sql statement
For each record in one table "msTab" of a MS Sql Server database, I need basically to insert a new record to another one table "oraTab" in Oracle.
I want to do this via codes to meet other requirements. I use Java with jdbc.
It looks like a sql statement (built using codes) must look like:
"Insert into oraTab(field1, field2, field3) values ('XXX', TO_DATE('13-NOV-92','DD-MON-YY', 322)"
If my codes find the date data in msTab being null I thought I need to build insert statement as:
"Insert into oraTab(field1, field3) values ('XXX', 322)", in order that Oracle will insert the default value for field2 automatically (field 2 of oraTab does not allow null).
The logic is not as complicated if there are only 3 fields. But for a table with over a hundred fields, the codes to achieve this is not quite simple. Do I miss some simpler sql statement to do the job?
Thanks.I believe Satish's suggestion was to use the DEFAULT keyword in the insert
INSERT INTO table_name( col1, col2, col3 )
VALUES( 1, DEFAULT, 2 );will insert the default value for col2. If you don't know which columns should take on the default value, though, I'm not sure how practical that would be.
Were it me, I'd probably create a BEFORE INSERT trigger that replaced NULL values with appropriate default values and then just do
INSERT INTO oracleTable( column_list )
SELECT column_list
FROM sqlTable@databaseLinkJustin -
Having trouble with SQLServer 2008 (not MySQL) and my database connection in Dreamweaver CS6. My document type is set as .asp using VBScript. I can list the table information but cannot use the insert wizard to add new records. I don't get any errors after creating the insert form, but no records get inserted. I'm not a VBScript expert, but do I have to manually write some code to insert records? How do I attach it to a button?
Thanks for the quick reply. I won't be back in the office for a few days, but I'll try to post it when I get back in. It's pretty much the code generated from the Dreamweaver Insert Record wizard. I see where the submit button is created and the value is set but the action on the form is set to MM_insert, so I don't see where the submit code is actually called.
Date: Wed, 3 Oct 2012 12:06:14 -0600
From: [email protected]
To: [email protected]
Subject: SQL Server2008 help needed
Re: SQL Server2008 help needed
created by bregent in Dreamweaver General - View the full discussion
This post should be moved to the app dev forum. Please post the code from your form and the insert script pages.
Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/4746757#4746757
Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4746757#4746757
To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4746757#4746757. In the Actions box on the right, click the Stop Email Notifications link.
Start a new discussion in Dreamweaver General by email or at Adobe Community
For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746. -
Stored Procedures for Simple SQL statements
Hi Guys,
We are using Oracle 10g database and Web logic for frontend.
The Product is previously developed in DotNet and SQL Server and now its going to develop into Java (Web Logic) and Oracle 10g database.
Since the project is developed in SQL Server, there are lot many procedures written for simple sql queries. Now I would like to gather your suggestions / pointers on using procedures for simple select statements or Inserts from Java.
I have gathered some list for using PL/SQL procedure for simple select queries like
Cons
If we use procedures for select statements there are lot many Ref Cursors opened for Simple select statements (Open cursors at huge rate)
Simple select statements are much faster than executing them from Procedure
Pros
Code changes for modifying select query in PL/SQL much easier than in Java
Your help in this regard is more valuable. Please post your points / thoughts here.
Thanks & Regards
Srinivas
Edited by: Srinivas_Reddy on Dec 1, 2009 4:52 PMSrinivas_Reddy wrote:
Cons
If we use procedures for select statements there are lot many Ref Cursors opened for Simple select statements (Open cursors at huge rate)No entirely correct. All SQLs that hit the SQL engine are stored as cursors.
On the client side, you have an interface that deals with this SQL cursor. It can be a Java class, a Delphi dataset, or a PL/SQL refcursor.
Yes, cursors are created/opened at a huge rate by the SQL engine. But is is capable of doing that. What you need to do to facilitate that is send it SQLs that uses bind variables. This enables the SQL engine to simply re-use the existing cursor for that SQL.
Simple select statements are much faster than executing them from ProcedureAlso not really correct. SQL performance is SQL performance. It has nothing to do with how you create the SQL on the client side and what client interface you use. The SQL engine does not care whether you use a PL/SQL ref cursor or a Java class as your client interface. That does not change the SQL engine's performance.
Yes, this can change the performance on the client side. But that is entirely in the hands of the developer and how the developer selected to use the available client interfaces to interface with the SQL cursor in the SQL engine.
Pros
Code changes for modifying select query in PL/SQL much easier than in JavaThis is not a pro merely for ref cursors, but using PL/SQL as the abstraction layer for the data model implemented, and having it provide a "business function" interface to clients, instead of having the clients dealing with the complexities of the data model and SQL.
I would seriously consider ref cursors in your environment. With PL/SQL servicing as the interface, there is a single place to tune SQL, and a single place to update SQL. It allows one to make data model changes without changing or even recompiling the client. It allows one to add new business logical and processing rules, again without having to touch the client. -
If someone would be so kind, I need help in formulating a SQL statement.
Table A - employees(empoyee_id, employee_name, status)
This table contains all employees
employee status can be one of three values (A=active, T=temporary, I=inactive)
Table B - savings_program(employee_id, plan_type)
This table only has employee_id's of those that participate in a savings program (subset of all employees).
plan_type can be one of three numeric values (30,35,40)
I need SQL to report a.employee_id,a.employee_name,b.plan_type (return plan_type 30,35, or none)of all active employees in Table A that don't participate in Table B plan_type 40.
Working with version 9iR2. Thanks!
Edited by: fosterk on Nov 21, 2008 12:59 PMThe tables and columns above were for demo purposes but actual code I'm trying is below. Please excuse me I'm more of an SA type so SQL is not my thing.
As you can see from the first SQL statement below I know that I have exactly
3,000 employees that meet this criteria. The second SQL statement is my attempt to return the rows I want (I'm just nesting it in a count(*) until the numbers look right)
The last statement is what was given to me by someone else (seeking my help haha) trying to resolve it and it only returns 3 rows. This SQL shows the actual columns that we're trying to return from both tables.
HR> select count(*) from ps_All_employees where empl_status != 'T'
2 and emplid not in
3 (select emplid from ps_savings_pt_vw where plan_type = 40)
4 /
COUNT(*)
3000
HR> select count(*) from (
2 (select * from ps_all_employees where empl_status != 'T') a left outer join
3 (select emplid from ps_savings_pt_vw where plan_type != 40) s
4 on a.emplid = s.emplid
5 )
6 /
COUNT(*)
4587
select count(*) from (
select a.location, a.ssn, a.first_name, a.last_name, a.birthdate, a.orig_hire_dt, a.hire_dt, a.location, a.street1,
a.street2, a.city, a.state, a.zip, s.plan_type
from ps_all_employees a, ps_savings_pt_vw s
where a.empl_status != 'T' and
a.emplid = s.emplid and
a.emplid not in (select s.emplid from ps_savings_pt_vw s where s.plan_type = 40)
COUNT(*)
3 -
How to optimize this SQL. Help needed.
Hi All,
Can you please help with this SQL:
SELECT /*+ INDEX(zl1 zipcode_lat1) */
zl2.zipcode as zipcode,l.location_id as location_id,
sqrt(POWER((69.1 * ((zl2.latitude*57.295779513082320876798154814105) - (zl1.latitude*57.295779513082320876798154814105))),2) + POWER((69.1 * ((zl2.longitude*57.295779513082320876798154814105) - (zl1.longitude*57.295779513082320876798154814105)) * cos((zl1.latitude*57.295779513082320876798154814105)/57.3)),2)) as distance
FROM location_atao l, zipcode_atao zl1, client c, zipcode_atao zl2
WHERE zl1.zipcode = l.zipcode
AND l.client_id = c.client_id
AND c.client_id = 306363
And l.appType = 'HOURLY'
and c.milessearchzipcode >= sqrt(POWER((69.1 * ((zl2.latitude*57.295779513082320876798154814105) - (zl1.latitude*57.295779513082320876798154814105))),2) + POWER((69.1 * ((zl2.longitude*57.295779513082320876798154814105) - (zl1.longitude*57.295779513082320876798154814105)) * cos((zl1.latitude*57.295779513082320876798154814105)/57.3)),2))
I tried to optimize it by adding country column in zipcode_atao table. So that we can limit the search in zipcode_atao table based on country.
Any other suggestions.
ThanksWelcome to the forum.
Please follow the instructions given in this thread:
How to post a SQL statement tuning request
HOW TO: Post a SQL statement tuning request - template posting
and add the nessecary details we need to your thread.
Depending on your database version (the result of: select * from v$version; ):
Have you tried running the query without the index-hint?
Are your table (and index) statatistics up-to-date? -
Native SQL Statement help!
Hi guys,
I need some help here.
I have a requirement to select from Microsoft SQL database
Question
How do I select with RANGE internal tables? As you can see, I have 4 range tables for this.
BElow are my codes
EXEC SQL.
CONNECT TO 'CONNECTION_NAME'
ENDEXEC.
IF sy-subrc <> 0.
MESSAGE 'Unable to connect to CONNECTION_NAME' TYPE 'E' DISPLAY LIKE 'I'.
RETURN.
ENDIF.
* Define database cursor
EXEC SQL.
OPEN dbcur FOR
SELECT name1, zvctk, kunnr, yyear, mmonth, matnr,
qty, zopcd, bstnk, wekunnr
FROM <TABLE_NAME>
WHERE month IN i_month
AND yyear IN i_year
AND kunnr IN i_kunnr
AND bstnk IN i_bstnk
ENDEXEC.
* Fill itab
DO.
EXEC SQL.
FETCH NEXT dbcur INTO :l_dest-name1,
:l_dest-zvctk,
:l_dest-kunnr,
:l_dest-yyear,
:l_dest-mmonth,
:l_dest-matnr,
:l_dest-qty,
:l_dest-zopcd,
:l_dest-bstnk,
:l_dest-wekunnr
ENDEXEC.
IF sy-subrc <> 0.
EXIT.
ELSE.
APPEND l_dest TO it_dest.
ENDIF.
ENDDO.
its giving me a shortdump
>>>>> OPEN dbcur FOR
35 SELECT name1, zvctk, kunnr, yyear, mmonth, matnr,
36 qty, zopcd, bstnk, wekunnr
37 FROM v_promise_sa
38 WHERE month IN i_month[]
39 AND yyear IN i_year[]
40 AND kunnr IN i_kunnr[]
41 AND bstnk IN i_bstnk[]
Error message:
Database error text........: "[Microsoft][SQL Server Native Client 10.0][SQL
Server]Incorrect syntax near 'i_month'."
Database error code........: 102
Triggering SQL statement...: "SELECT name1, zvctk, kunnr, yyear, mmonth, matnr,
qty, zopcd, bstnk, wekunnr FROM <TABLE_NAME> WHERE month IN i_month[] AND
yyear IN i_year[] AND kunnr IN i_kunnr[] AND bstnk IN i_bstnk[]"
Internal call code.........: "[DBDS/NEW DSQL]"
Please check the entries in the system log (Transaction SM21).
Can anyone guide me? If I do not enter the where clause, it is selecting fine.
Appreciate it guys! Thanks in advance!lol, Come guys, don't judge me by just my forum nick man. It was just something random during registration a few years back...was indeed new in ABAP language :P
But anyway, the table v_promimse_sa is not in the DDIC, its some microsoft MYSQL database or something.
anyway what I did now:
EXEC SQL.
CONNECT TO 'MSSQL_PROMISE'
ENDEXEC.
IF sy-subrc <> 0.
MESSAGE 'Unable to connect to MSSQL_PROMISE' TYPE 'E' DISPLAY LIKE 'I'.
RETURN.
ENDIF.
* Define database cursor
EXEC SQL.
OPEN dbcur FOR
SELECT name1, zvctk, kunnr, yyear, mmonth, matnr,
qty, zopcd, bstnk, wekunnr
FROM v_promise_sa
WHERE mmonth = :i_month
AND yyear = :i_year
* AND ( kunnr BETWEEN :i_kunnr-low AND :i_kunnr-high )
* AND ( bstnk BETWEEN :i_bstnk-low AND :i_bstnk-high )
ENDEXEC.
* Fill itab
DO.
EXEC SQL.
FETCH NEXT dbcur INTO :l_dest-name1,
:l_dest-zvctk,
:l_dest-kunnr,
:l_dest-yyear,
:l_dest-mmonth,
:l_dest-matnr,
:l_dest-qty,
:l_dest-zopcd,
:l_dest-bstnk,
:l_dest-wekunnr
ENDEXEC.
IF sy-subrc <> 0.
EXIT.
ELSE.
APPEND l_dest TO it_dest.
ENDIF.
ENDDO.
* EXEC SQL.
* CLOSE dbcur
* ENDEXEC.
DELETE it_dest WHERE kunnr NOT IN i_kunnr
AND bstnk NOT IN i_bstnk.
Well, after checking with the functional person, there are only 3 records so I guess the selection + filtering is working. -
Guys,
Help me understand the syntax please!! With PL/SQL I have achieved a task quite easily, with a branch of code to include or exclude some part of the query - no problem. But to use SQL ......
If i have a variable on a page, say :p10_open_or_closed
.. and I set the value of this to the text "Is Not Null"
How can I incorporate this into an SQL query, say
Select ID, Date1, Date2, Comment
From Table1
where Date1 Is Not Null
Is there a way of substituting the ":p10_open_or_closed" variable into this query?
ie
Select ID, Date1, Date2, Comment
From Table1
where Date1 ":p10_open_or_closed"
Thanks.Thanks for your help gents.
Originally, I had a PL/SQL Statement constructing the code as needed, as Rekha
suggested.
if :P1_OPEN_OR_CLOSED = 1 then
q:=q||' and ';
q:=q||' p.ACTUAL_INSTALL_DATE is null ';
end if;
if :P1_OPEN_OR_CLOSED = 2 then
q:=q||' and ';
q:=q||' p.ACTUAL_INSTALL_DATE is not null ';
end if;
But, to use a Tabular form, where users can update fields of multiple records on screen then submit for a MRU, the option of PL/SQL code is not allowed, only SQL. So Phil UK, no it's not an elegant way of doing things, but I'm forced to use SQL, yeah?
There are definitely ways that I can filter for the solution I am after, but they all involve more in depth solutions (that are not that great). Thus, I asked at this forum.
Andy, your solution works :~) which makes me very happy. I'm not sure how just now but I'll learn from it.
Thanks again. -
Oracle Spatial operator SQL statement help
I have a 3D elevation point feature class (elev) and a polygon feature class (Building) loaded in Oracle Spatial. I am trying to update the "HEIGHT" attribute of the "Building" Feature class using the average elevation of "elev" feature class. Here below is the SQL statement I used, which generated the same value for all buildings. The avg(elevation) returns the average elevation of all points within all building polygons, not all points within ONE polygon.
Please help and thanks.
update building
set height = (select avg(elevation)
from elev e, building b
where sdo_anyinteract(e.shape, b.shape) = 'TRUE');Hi,
try this
update building b
set height = (select avg(elevation)
from elev e where sdo_anyinteract(e.shape, b.shape) = 'TRUE');
Udo -
EarlyWatch - Expensive SQL Statements help
Hi all,
i need to analyze an EWA report and i don't know how exactly can i identify an "expensive SQL statement".
The report says:
During this session, the following expensive SQL statements were identified as causing a database load of at least 1%.
The corresponding stored procedure names are referenced in the table below.
And in the table with stored procedure names, a row looks like this:
ID Stored Procedure Name
1 ##Y4DCWWES7EHY100000053960000254832042037
What does it mean and how can i identify the name of program and the exact statement (probably select) that is causing this problem?
Thank you,
OndrejHi Ondrej,
you're running on SQL Server. SAP creates stored procedures for each and every statement run against the database. The name you get seems to be a temporary stored procedure which (if I'm not wrong) is marked by the two # characters at the beginning. You may be still find it in the stored procedures of your system.
Open the Enterprise Manager and open your database, then the stored procedure link (you should run the Enterprise Manager on the server or on a PC with enough RAM). The search for the procedure and double click on it. I think that should show you the SQL statement. There should also the report name is a comment.
Regards
Ralph -
Performance - SQL Statements- Script needed
Hi All
I am working on Performance Tuning on Oracle 10g/ Solaris environment.
I am looking for a shell script that gives top 10 Time Consuming SQL Statements...... My client does not want me to use statspack or OEM for somereasons which i dont know. I am wondering if any of you might help me out ....
thanks in advance
riah.>> My client does not want me to use statspack
Your client does not want you to use the scripts provided by Oracle that do exactly what you want but will allow you to run sripts that come from some unknown (to the client, at least) source???? -
PL/SQL error - help needed.
I have a item which gives me an error message when tring to open a page.
When field is null (back end) there is no problem but when I input any value I get this error.
ORA-06550: line 1, column 48: PLS-00201: identifier 'P9_CANC_BY' must be declared ORA-06550: line 1, column 7: PL/SQL: Statement ignored
Any idea?
ThanksI am using oracle back-end but not build-in apex therefore creating application in apex.oracle.com won't work (I guess, correct me if I am wrong).
Going back to the error message.
I have various items like that on form and this is the first one giving me this error. I even deleted it and recreated with different name. Another thing that I would like to point out is that my page contains more than 100 items. Is there a limit of how many items you can create on the page?
Regards
Robert -
Help with a really simple SQL statement
Hi All
I'm relatively new to SQL and can't get my head round what I believe to be a really simple problem.
I have a table I want to query called locations. We use locations to mean groups and regions as well as people s ofr example:
TABLE: LOCATION
IDENTIFIER----------NAME-----------------PART_OF
101--------------------USER A---------------123
123--------------------GROUP A-------------124
etc
What I'm trying to write is a statement that will return the 'PART_OF' as the 'NAME' rather than the ID number if the ID = 101.
I was wondering if a nested select statement would do (select as select etc) but just can't get my head round it!
Any ideas?
TIA. Jake.Hi Jake,
It's not clear what you are looking for. If USER A is just Part of GROUP A, a self-join will do:
SQL> with loc as (select 101 locid, 'USER A' locname, 123 part_of from dual
union all
select 123 locid, 'GROUP A' locname, 124 part_of from dual
union all
select 124 locid, 'REGION A' locname, null part_of from dual)
-- End of test data
select l1.locid, l1.locname, l2.locname part_of
from loc l1, loc l2
where l2.locid(+) = l1.part_of
LOCID LOCNAME PART_OF
101 USER A GROUP A
123 GROUP A REGION A
124 REGION A
3 rows selected.But if you want USER A to be part of REGION A, then you need a hierarchia lquery:
SQL> with loc as (select 101 locid, 'USER A' locname, 123 part_of from dual
union all
select 123 locid, 'GROUP A' locname, 124 part_of from dual
union all
select 124 locid, 'REGION A' locname, null part_of from dual)
-- End of test data
select l1.locid, l1.locname, connect_by_root(locname) part_of
from loc l1
start with part_of is null
connect by prior locid = part_of
LOCID LOCNAME PART_OF
124 REGION A REGION A
123 GROUP A REGION A
101 USER A REGION A
3 rows selected.Regards
Peter
Maybe you are looking for
-
.MOV file won't play in QuickTime Player? QT Components?
I have a bunch of .MOV clips on my hard drive that I'd like to ultimately import to Final Cut Express (4.0.1) to edit (my wedding video!!). If I double click on the clip, it automatically opens in QuickTime Player (7.6.9), and I then prompted to a Qu
-
Problems with auto upgrade Anyconnect 3.1
Hello, I'm having problem with auto upgrade of Anyconnect 2.5 to 3.1. Here is the situation : I have ASA5510 running ASA 8.4.5 and clients are running Anyconnect 2.5.3055 and 3.1.00495 with 2 different profiles. Clients with 2.5 can upgrade to 3.1 bu
-
Advanced table in advanced table- Need custom Detail table data.
hi, I have a advanced table in table. Now for the inner detail table I have a Language column. For each row in master table I have correspoding 3 detail table records for 3 different languages. This languages are related to another master table calle
-
Convert non-partition table to partition table
Hello Everybody I am just want to ask about how to Convert non-partition table to partition table ? Thanks Ramez S. Sawires
-
Have DW 8.0.2 loaded on New PC with Vista Home Premium. Some things do not seem to work as with XP. True? Must I invest in CS3? Thank y'all.