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
Related
I run the follows to update the record
update lims_min.languages
set Apriori = 'Русский'
where langid = 'RUS';
COMMIT;
when I do select, I see the ???? instead of the correct word. Apriori is NVARCHAR2.
Is there another trick here?
This is not an answer but is too long for a comment.
As already said you need to check NLS_LANG but also
your database character sets
what is the tool used to display data
the platform used (Windows, Linux, ...)
if you use Windows are you using a GUI program or a CLI program.
The following works on Linux CLI environment with SQLPlus:
SQL> select banner from v$version where rownum=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
SQL> host echo $NLS_LANG
American_America.UTF8
SQL> --
SQL> select parameter, value
2 from nls_database_parameters
3 where parameter like '%SET%';
PARAMETER VALUE
------------------------------ --------------------
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_CHARACTERSET AL32UTF8
SQL> --
SQL> create table t(l varchar2(3), a nvarchar2(30));
Table created.
SQL> --
SQL> insert into t values('RUS', 'Русский');
1 row created.
SQL> --
SQL> select * from t;
L A
--------- ------------------------------
RUS Русский
SQL>
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.
How do you create an Oracle Automatic Workload Repository (AWR) report?
To generate AWR report follow below steps :
Take begin snap id
set serveroutput on;
DECLARE
v_snap_id number ;
begin
v_snap_id := DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT;
dbms_output.put_line(v_snap_id);
end;
/
Run your batch or the program you want to monitor.
Take end snap id
set serveroutput on;
DECLARE
v_snap_id number ;
begin
v_snap_id := DBMS_WORKLOAD_REPOSITORY.CREATE_SNAPSHOT;
dbms_output.put_line(v_snap_id);
end;
/
Go to oracle directory. e.g. in my case
cd C:\oraclexe\app\oracle\product\11.2.0\server\rdbms\admin
go to sqlplus promt
sqlplus dbusername/dbpassword#host:port/dbenv
run #awrrpt command
It will ask for format of the report, default is html.
provide no of days, if you dont remember your snap id
enter begin snap
enter end snap
Give report name and press enter
Your report will be generated in "admin" e.g. in my case
C:\oraclexe\app\oracle\product\11.2.0\server\rdbms\admin
sqlplus into to Oracle as the DBA users. Run the report sql. Answer the questions prompted by the report to narrow down the time period
sqlplus / as sysdba
#$ORACLE_HOME/rdbms/admin/awrrpt.sql
The script will ask you some questions so you get a report for the time period you are interested in.
You can use dbms_workload_repository package without the need to log into the server itself.
For a text report, use e.g.:
select output
from table(dbms_workload_repository.awr_report_text(1557521192, 1, 5390, 5392);
Or to get a HTML report, use awr_report_text() instead.
The first paramter is the DBID which can be obtained using:
select dbid from v$database
The second one is the instance number. Only relevant for a RAC environment.
And the last two parameters are the IDs of the start and end snapshot. The available snapshots can be obtained using:
select snap_id,
begin_interval_time
end_interval_time
from dba_hist_snapshot
order by begin_interval_time desc;
Especially for the HTML return - which returns a CLOB - you must configure your SQL client to properly display the output. In SQL*Plus you would use set long
conn / as sysdba
SQL> #$ORACLE_HOME/rdbms/admin/awrrpt.sql
Specify the Report Type
AWR reports can be generated in the following formats. Please enter the
name of the format at the prompt. Default value is 'html'.
'html' HTML format (default)
'text' Text format
'active-html' Includes Performance Hub active report
Enter value for report_type:
old 1: select 'Type Specified: ',lower(nvl('&&report_type','html')) report_type from dual
new 1: select 'Type Specified: ',lower(nvl('','html')) report_type from dual
Type Specified: html
old 1: select '&&report_type' report_type_def from dual
new 1: select 'html' report_type_def from dual
old 1: select '&&view_loc' view_loc_def from dual
new 1: select 'AWR_PDB' view_loc_def from dual
Current Instance
2. you can schedule report by email alert also.
When I'm trying to gather table statistics using GATHER_TABLE_STATS procedure, I'm getting the following error:
ORA-20001: Invalid input values for pname
ORA-06512: at "SYS.DBMS_STATS", line 31513
ORA-06512: at line 2
The code I'm running to gather statistics is
BEGIN
DBMS_STATS.gather_table_stats ('OWNER', 'TABLE_NAME');
END;
/
My Oracle version is Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
I guess you might have misspelled OWNER or TABLE_NAME parameter. Its working fine for me as shown below.
SQL> conn jay/jay
Connected.
SQL> select table_name from tabs;
TABLE_NAME
------------------------------
ROAD
EVENT
ALL_OBS
ACCOUNT
NVARCHAR2_EMAIL
TABLEA
T2
MYTABLE
8 rows selected.
SQL> exec dbms_stats.gather_table_stats('JAY','ROAD');
PL/SQL procedure successfully completed.
Update
As per the My Oracle Support Doc:755577.1, It is possible that the post installation scripts for the patch were not run correctly after a patch was applied.
You may need to reinitialize the DBMS_STATS package using execstat.sql under $ORACLE_HOME/rdbms/admin directory. Or reinstall DBMS_STATS.
Or you might hit the bug- Bug 14479079 : ORA-20001 GATHERING STATS AFTER CPU JULY 2012 PATCH
Our Oracle DBA is planning to move a number of schemas to new instances. One thing we've noticed - security policies are not being carried over in the exports. Also- they don't seem to count as 'objects' when querying 'all_objects' or 'user_objects'. Different kind of animal I guess.
Any ideas on how to migrate this stuff smoothly?
Personally I use a tool to extract/generate scripts for specific users or roles. Toad can script users, as can other tools. The one I now use is my own, but I cannot promote it here. If you don't have such a tool, there are other options.
Use export or data pump. When you do full system export (using exp or data pump) you will get all of the grants. You can then use the import / impdp utilities to dump all of the DDL for the grants for users of interest. Once you have the dmp file.
impdp system/ full=Y directory=dumpdir dumpfile=full.dmp logfile=dump.txt grants=y
Or for export
imp system/ full=y grants=y file=full.dmp log=dump.txt
This will dump everything to the dump.txt in text form and you can extract the SQL. Not super pretty, but works.
Use DBMS_METADATA to give you the grants for a user or role.
SQL> set long 50000
SQL> select dbms_metadata.get_ddl( 'USER', 'MSMITH' ) from dual;
SQL> select dbms_metadata.get_granted_ddl('SYSTEM_GRANT', 'MSMITH') from dual;
SQL> select dbms_metadata.get_granted_ddl('OBJECT_GRANT', 'MSMITH') from dual;
SQL> select dbms_metadata.get_granted_ddl('ROLE_GRANT', 'MSMITH') from dual;
Or for roles:
SQL> select dbms_metadata.get_ddl( 'ROLE', 'JUNIOR_DBA' ) from dual;
SQL> select dbms_metadata.get_granted_ddl('SYSTEM_GRANT', 'JUNIOR_DBA') from dual;
SQL> select dbms_metadata.get_granted_ddl('OBJECT_GRANT', 'JUNIOR_DBA') from dual;
SQL> select dbms_metadata.get_granted_ddl('ROLE_GRANT', 'JUNIOR_DBA') from dual;