'Invalid input values for pname' during table statistics gathering? - oracle

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

Related

Oracle SQL: Running insert statements from a large text file

I have a large text file (around 50mb). This text file has thousands of insert statements. I tried to open the text file in Oracle SQL Developer, but it is too large. How do I insert the data into my tables without opening the file in SQL Developer?
I tried to loop through the insert statements one by one and insert them into my table like this:
DECLARE
V1 VARCHAR2(32767);
fileVariable UTL_FILE.FILE_TYPE;
BEGIN
fileVariable := UTL_FILE.FOPEN('h:/Documents',
'clob_export.sql',
'R',
32760);
UTL_FILE.GET_LINE(fileVariable,V1,32767);
UTL_FILE.FCLOSE(fileVariable);
END;
But this doesn't seem to work. I can't create directories on the machine, and anyways, the text file is on the computer where I am running SQL Developer and SQL Developer is connected remotely to the database.
The simplest way - from my point of view - is to run it from SQL*Plus, such as:
c:\Temp>sqlplus scott/tiger
SQL*Plus: Release 11.2.0.2.0 Production on Uto Sij 26 22:20:18 2021
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> #insert_data.sql
1 row created.
1 row created.
<snip>
presuming that insert_data.sql contains something like
insert into dept values (1, 'Dept 1', 'NY');
insert into dept values (2, 'Dept 2', 'London');
...
Use sqlplus and if where are too much text use options to log only in the file not on screen
SET TERMOUT OFF;
spool M:\Documents\test.log;
Call the file with # instead of trying to open the file. You may also want to disable feedback to avoid many thousands of "1 row inserted" messages.
set feedback off;
#c:\users\jon\Desktop\test.sql
The above commands are SQL*Plus syntax, but Oracle SQL Developer worksheets understand basic SQL*Plus commands. If you need to frequently run large scripts then you might want to learn the command line SQL*Plus, but if this is just a one-time task then stick with SQL Developer.

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

SERVEROUTPUT shows results one after another execution

When I execute the following trigger code it is compiled. Then after inserting data, serveroutput says '1 row inserted' trigger result ('User Example has insrted a data') didn't displayed.
Then after execution of another PL/SQL the previous trigger result will appears on display. What should i do to solve this issue?
Here is the trigger and the insertion command and also the results,
/
SET SERVEROUTPUT ON;
CREATE OR REPLACE TRIGGER BTR_SUPERHEROS
BEFORE INSERT ON SUPERHEROS
FOR EACH ROW
ENABLE
DECLARE
V_USER VARCHAR2(30);
BEGIN
SELECT USER INTO V_USER FROM DUAL;
DBMS_OUTPUT.ENABLE();
DBMS_OUTPUT.PUT_LINE('USER:' ||V_USER||' HAS INSERTED A DATA');
END;
/
RESULT - Trigger BTR_SUPERHEROS compiled
INSERT INTO SUPERHEROS VALUES('SUPERMAN');
RESULT - 1 row inserted. (Didn't Shows the DBMS_OUTPUT)
You need to set serveroutput on in the client application (SQL*Plus, SQL Developer etc) in the session where you run a statement, otherwise it won't know that you want it fetch and display the output buffer when the statement completes. The set server output on prior to creating the trigger is just a client setting and doesn't set it permanently for the trigger.
Please confirm whether your test case was run from a single session, like this:
SQL*Plus: Release 12.1.0.1.0 Production on Tue Aug 15 08:17:48 2017
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Last Successful login time: Tue Aug 15 2017 08:14:08 +01:00
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> SET SERVEROUTPUT ON;
SQL>
SQL> CREATE OR REPLACE TRIGGER BTR_SUPERHEROS
2 BEFORE INSERT ON SUPERHEROS
3 FOR EACH ROW
4 ENABLE
5
6 DECLARE
7 V_USER VARCHAR2(30);
8 BEGIN
9 SELECT USER INTO V_USER FROM DUAL;
10 DBMS_OUTPUT.ENABLE();
11 DBMS_OUTPUT.PUT_LINE('USER:' ||V_USER||' HAS INSERTED A DATA');
12 END;
13 /
Trigger created.
SQL> INSERT INTO SUPERHEROS VALUES('SUPERMAN');
USER:WILLIAM HAS INSERTED A DATA
1 row created.
Note also that it is not recommended to call dbms_output.enable. From the documentation:
You should generally avoid having application code invoke either the DISABLE Procedure or ENABLE Procedure because this could subvert the attempt of an external tool like SQL*Plus to control whether or not to display output.
You can also assign values using the assignment := operator instead of a select into statement. The trigger could therefore be written as:
create or replace trigger btr_superheros
before insert on superheros
for each row
enable
declare
v_user user_users.username%type := sys_context('userenv', 'current_schema');
begin
dbms_output.put_line('User: ' ||v_user||' inserted value '''||:new.name||'''');
end;
/

ORA-00932 - inconsistent datatypes after creating table of custom type

I'm developing a query which return two columns as result: VARCHAR(256) and NUMBER. In order to store the query result for future use, I created the types below:
-- An object representing each of the records of my query
create or replace TYPE TP_SOME_TYPE IS OBJECT(
SOME_TEXT VARCHAR2(256),
SOME_NUMBER NUMBER
);
-- A table of the objects created above:
create or replace TYPE TP_SOME_TABLE AS TABLE OF TP_SOME_TYPE;
Finally, I run a sample SQL trying to collect the result in a variable of type TP_SOME_TABLE:
DECLARE
SOME_RESULT TP_SOME_TABLE;
BEGIN
EXECUTE IMMEDIATE 'SELECT ''TEXT'' AS SOME_TEXT, 1 AS SOME_NUMBER FROM DUAL'
BULK COLLECT INTO SOME_RESULT;
END;
And get the following error message:
ORA-00932: tipos de dados inconsistentes: esperava - obteve -
ORA-06512: em line 4
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*Cause:
*Action:
I've tried defining a RECORD TYPE instead of OBJECT TYPE on the body of my function with the same fields and it worked, unfortunately, since I'm going to expose the collected result in a TABLE() call, I have to use something database level like OBJECT.
Any ideas to make the current structure work?
My database setup:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
"CORE 11.2.0.4.0 Production"
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 - Production
Thanks in advance.
An object has to be explicitly constructed. Change the query in your test to:
EXECUTE IMMEDIATE 'SELECT tp_some_type(''TEXT'', 1) FROM DUAL'
you to convert the covert the column being referenced in select statement of TP_SOME_TYPE type.
DECLARE
SOME_RESULT TP_SOME_TABLE;
BEGIN
EXECUTE IMMEDIATE 'SELECT TP_SOME_TYPE(''TEXT'' , 1) FROM DUAL'
BULK COLLECT INTO SOME_RESULT;
END;
you can still be able to access this collection like
select SOME_TEXT ,SOME_NUMBER from table(ur_collection);

what's the reason of dbms_metadata.get_granted_ddl('SYSTEM_GRANT', 'AQ_ADMINISTRATOR_ROLE') ora-31608 error?

I'd like to get ddls of all roles in the database using dbms_metadata package. Unfortunately dbms_metadata.get_granted_ddl fails with error when there are no grant (object, system or role type) for the role. That's why I have to check the presence of privileges in dba_tab_privs, dba_sys_privs and dba_role_privs views.
However AQ_ADMINISTRATOR_ROLE role has system privileges the following statement fails. Checked on two databases.
sqlplus system/pass#db1
select dbms_metadata.get_granted_ddl('SYSTEM_GRANT', 'AQ_ADMINISTRATOR_ROLE')
from dual
where exists (select 1 from dba_sys_privs where grantee = 'AQ_ADMINISTRATOR_ROLE')
/
ORA-31608: specified object of type SYSTEM_GRANT not found ORA-06512:
at "SYS.DBMS_METADATA", line 4018 ORA-06512: at "SYS.DBMS_METADATA",
line 5991 ORA-06512: at line 1
select * from v$version
/
Oracle Database 11g Release 11.2.0.2.0 - 64bit Production PL/SQL
Release 11.2.0.2.0 - Production CORE 11.2.0.2.0 Production
Oracle returns that exception if there are no rows that match your parameters. There must be no SYSTEM_GRANT objects for QA_ADMINISTRATOR_ROLE
This will return what you are looking for:
select dbms_metadata.GET_GRANTED_DDL('SYSTEM_GRANT') from dual;
This will return something like:
GRANT CREATE JOB TO "SCOTT"
GRANT SELECT ANY DICTIONARY TO "SCOTT"
GRANT EXECUTE ANY TYPE TO "SCOTT"
I assume, you want to extract DDL for all privileges (roles/permissions) given to current schema user (when you say 'database').
If one wants to extract for a given user, use the following:
select dbms_metadata.GET_GRANTED_DDL('SYSTEM_GRANT', 'SCOTT') from dual;
If one wants to extract privileges given on a OBJECT from current user to another schema user, use the following:-
select DBMS_METADATA.GET_DEPENDENT_DDL('OBJECT_GRANT','TEST_TABLE') from dual;

Resources