How can I get this syntax to work in Oracle? - oracle

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
simplest repo, how can I get this to work in Oracle?
SELECT 'X' NewColumn, * FROM MyTable;
I get
ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action: Error at Line: 1 Column: 23
My actual issue is:
I'm using an ETL tool that allows automapping if I use SELECT *
I want to use ORA_ROWSCN to implement incremental loads
So the real query I'm running is:
SELECT ORA_ROWSCN, * FROM MyTable;
I get the same error for this

The syntax is valid if you alias the table and the *.
SELECT ORA_ROWSCN, t.* FROM MyTable t;
No idea whether your ETL tool knows how to do that. Of course, you could always create a view vw_table that runs this select and then use the view in the ETL tool.

Related

Oracle Number issue on 18c vs 19c

Need a confirmation on this below behavior of NUMBER Datatype on both the Oracle versions(18c vs 19c),
In 18c,
select cast(0.003856214813393653 as number(20,18)) from dual;
--output
0.00385621481339365
In 19c,
select cast(0.003856214813393653 as number(20,18)) from dual;
--output
0.003856214813393653
Why does the truncation of last digit happen for 18c?
Is this an issue with version?
Plus 18c seems to to be unable to handle scale values more than 17.
This is related to Oracle / PLSQL developer tool setting issue. please try with the below options to resolve the same
Tools -> Preferences -> SQL Window -> Number fields to_char
This is at the whim of the client settings not the database. For example, I ran all of these on the same database
SQL Plus
========
SQL> select cast(0.003856214813393653 as number(20,18)) from dual;
CAST(0.003856214813393653ASNUMBER(20,18))
-----------------------------------------
.003856215
SQL Developer
=============
select cast(0.003856214813393653 as number(20,18)) from dual;
0.003856214813393653
SQLcl
======
SQL> select cast(0.003856214813393653 as number(20,18)) from dual;
CAST(0.003856214813393653ASNUMBER(20,18))
-----------------------------------------
.00385621481
The client tool decides on the precision to show

Running query cannot connect to vendort's database, even dblink exists

I have a simple query, which I run on sqldeveloper on put database, but it select data from different vendor database. We have db_link created. but I run, as in my Pro C program:
select some_files from mytable trd, vendordbname.vendortable
where(condition)
and I get an error:
ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error at Line: 25 Column:
What kind of solution I have to find, to make it run? Use dblink name? or something else? I will appreciate any possible help
Thanks
ok, when it runs with Pro C, everything sets up on UNIX and sqlplus.
When I run it from sqldeveloper I have to add the vendor host name
select some_files from mytable trd, vendordbname.vendortable#vendorhost
where(condition)

How can I avoid errors with dbms_metadata.GET_DEPENDENT_DDL

I'm writing a custom program to dump the database metadata to files in order to manage them with version control. The default way that data pump or export works isn't ideal for a few reasons (eg. I'd like a separate directory per table).
Sql Developer provides a number of ways of creating export scripts for any object. One way is just by right-clicking the object and selecting Quick DDL. By viewing the logs it creates, one can see the actual SQL it issues to create the DDL script. I've used these scripts to write my custom program and for the most part, they've been perfect.
When I generate the DDL for a materialized view, the SQL it generates is:
SELECT DBMS_METADATA.GET_DDL('MATERIALIZED_VIEW',:name,:owner) FROM DUAL
UNION ALL
SELECT DBMS_METADATA.GET_DEPENDENT_DDL('INDEX',TABLE_NAME, TABLE_OWNER) FROM (
SELECT table_name, table_owner FROM all_indexes
WHERE table_owner = :owner AND table_name = :name
AND index_name NOT IN (
SELECT constraint_name FROM sys.all_constraints
WHERE table_name = table_name AND constraint_type = 'P'
) AND ROWNUM = 1
)
UNION ALL
SELECT dbms_metadata.GET_DEPENDENT_DDL ('COMMENT', :name,:owner ) FROM DUAL
For this script, when executed via SQL Developer Quick DDL, it generates the metadata for the materialized view properly. When I run this script in a program (or even manually with SQL Developer itself), it produces the following errors:
ORA-31608: specified object of type COMMENT not found
ORA-06512: at "SYS.DBMS_METADATA", line 5805
ORA-06512: at "SYS.DBMS_METADATA", line 8436
ORA-06512: at line 1
31608. 00000 - "specified object of type %s not found"
*Cause: The specified object was not found in the database.
*Action: Correct the object specification and try the call again.
This particular materialized view doesn't have any comments (obviously), but I would have expected this part of the clause to just return 0 rows instead of generating an error (especially since SQL Developer uses this itself seemingly without errors).
Is there a way I can avoid this error, while still including comments in the metadata if they exist?
This issue exists on both Oracle 10g & 11g databases.
I was not able to test as I don't really know how to create mview without comment... However the below should work for you. Try to query dba_mview_comments instead of dual to not execute the function when you don't have comments.
UNION ALL
SELECT dbms_metadata.get_dependent_ddl ('COMMENT', :name, :owner)
FROM dba_mview_comments mvc
WHERE mvc.mview_name = :name AND
mvc.owner = :owner AND
length(comments) > 0 AND
rownum = 1

Recovering deleted Records

I have accdently deleted some rows in a table and did the commit too. Now
I want to recover them.
The DB I'm using is Oracle 11g R2.
I used the following query to get deleted records:
SELECT * FROM MY_TABLE AS OF TIMESTAMP ('13-MAR-11 8:50:58','DD-MON-YY HH24: MI: SS')
But while executing it gives an error saying:
Error at Command Line:3 Column:75
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
But I couldn't figure the problem in this queury.
Can anyone pls help?
That requires an actual timestamp (or date), you're passing a pair of values.
Try:
SELECT * FROM MY_TABLE
AS OF TIMESTAMP TO_DATE('13-MAR-11 08:50:58','DD-MON-YY HH24:MI:SS')
(Your time format specifier isn't correct either and doesn't match your date string.)
for example :
SELECT * FROM EMP AS OF TIMESTAMP
TO_TIMESTAMP('2005-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS')
WHERE name = 'JOHN';
But flashback query may fail with ORA-1555 , other option :
Logminer
if Oracle supplement log is enabled , you can get undo sql for your delete statement
-- switch again logfile to get a minimal redo activity alter system switch logfile;
-- mine the last written archived log
exec dbms_logmnr.add_logfile('archivelog/redologfile', options =>dbms_logmnr.new);
exec dbms_logmnr.start_logmnr(options => dbms_logmnr.dict_from_online_catalog);
select operation, sql_redo from v$logmnr_contents where seg_name = 'EMP';
Oracle PRM-DUL
PRM-DUL will be last option. Even deleted row piece in Oracle block is always just marked row flag with deleted mask, the row piece still can be read via scan Oracle data block . PRM-DUL can scan the whole table , find out every record/row piece marked deleted and write out to flat file.

Error in select query in Oracle

I've used a select statement in stored procedure in oracle 11g xe.But an error is showing as
pls-00428-an INTO clause is expected with select statement
I just cannot understand the error.When i searched i found out that in pl/sql an into clause is needed.I'm using toad.But when i used sql editor same error is showing.
Here's my procedure
CREATE OR REPLACE PROCEDURE ACTSINFO.sp_Get_WorkDetails
IS
BEGIN
select * from workdetails;
END sp_Get_WorkDetails;
Oracle is different from Microsoft SQL Server and therefor returning a result set from a procedure (or function) is different as well.
What you are looking for is a "pipelined table function".
Please refer to the manual for a description and an example:
http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/tuning.htm#i53109
Here are some more examples from other sites:
http://www.oracle-developer.net/display.php?id=207
http://www.oracle-base.com/articles/misc/PipelinedTableFunctions.php
http://psoug.org/reference/pipelined.html
You are trying to write wrong syntax or improper use of SELECT statement. You have to either create a cursor or use SELECT .. INTO syntax to set scalar value to the local variables.

Resources