Showing posts sorted by relevance for query character set. Sort by date Show all posts
Showing posts sorted by relevance for query character set. Sort by date Show all posts

Monday, 4 May 2020

ORA-02374: conversion error loading table,ORA-12899: value too large for column


When you run import dump into a database you may get below error.

ORA-02374: conversion error loading table "DATA"."TEST_TABLE"
ORA-12899: value too large for column AT_TEXT (actual: 2001, maximum: 2000)
ORA-02372: data for row: AT_TEXT : '999999934389384734HUKL83434JJ'

Reason: you can observe the error messages saying column length of the table is not sufficient to import the data, its saying column length is 2000 characters but value to be loaded into the column is 2001. how its possible?, how the table in source is having more characters in the column?.

Its due to character set change from source to target, you may find the message in import log as below.

import done in AL32UTF8 character set and AL16UTF16 NCHAR character set
export done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
Warning: possible data loss in character set conversions

in the above message its clearly saying export is done in  WE8MSWIN1252 and doing import in AL32UTF8

Solution:
1. you can import the only metadata of the table first and increase column length and import it, make sure the data is validated in this case, because you may get strange characters in the data. to avoid this you may regenerate data.
2. character set conversion, before importing to the target database, you need to import into a dummy database which is in the same character set as source then convert into target database character set by using tools like DMU tool, CSALTER etc.

you can check here how to convert character set using CSALTER


Thursday, 27 July 2017

Changing character set for a database

In this example, we are changing to UTF8 from AL32UTF8

Step 1: Check current character set.

SELECT value$ FROM sys.props$ WHERE name ='NLS_CHARACTERSET';

Step 2: Drop existing user CSMIG form database if exists.

drop user csmig cascade;

Step 3: Create new CSMIG user using below script.

@?/rdbms/admin/csminst.sql

Step 4: Check the objects impact if character set changed, we need to check looses.

csscan \"sys/sys as sysdba\" FULL=Y FROMCHAR=AL32UTF8 TOCHAR=UTF8 
LOG=dbcheck_utf82 CAPTURE=N ARRAY=1000000 PROCESS=6

Step 5: export the objects which are impacted in above step

Step 6: shutdown and start database in restricted mode.

shut immediate
startup restrict

Step 7: change character set using below script, it will take inputs from step 4.

@?/rdbms/admin/csalter.plb

Step 8: start the database in normal mode.

shut immediate 
startup

Step 9: check the character set after change.

SELECT value$ FROM sys.props$ WHERE name ='NLS_CHARACTERSET';


Wednesday, 26 June 2013

steps for database creation manually in oracle

->in this example i assume database name is demo
-----------------------------------------------------


Step 1: Specify an Instance Identifier (SID)

Decide on a unique Oracle system identifier (SID) for your instance, open a command window, and set the ORACLE_SID environment variable.
$export ORACLE_SID=demo

Step 2: Ensure That the Required Environment Variables Are Set

For example, on most platforms, ORACLE_SID and ORACLE_HOME must be set. In addition, it is advisable to set the PATH variable to include theORACLE_HOME/bin directory

$export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
$export PATH=$PATH:$ORACLE_HOME/bin

Step 3: Choose a Database Administrator Authentication Method

·         With a password file
·         With operating system authentication
To be authenticated with a password file, create the password file
$orapwd FILE=orapworcl password=****** ENTRIES=30
 To be authenticated with operating system authentication, ensure that you log in to the host computer with a user account that is a member of the appropriate operating system user group. On the UNIX and Linux platforms, for example, this is typically the dba user group.

Step 4: Create the Initialization Parameter File

If you create the initialization parameter file manually, ensure that it contains at least the parameters listed in . All other parameters not listed have default values.

Parameter Name
Mandatory
Notes
DB_NAME
Yes
Database identifier. Must correspond to the value used in the CREATE DATABASE statement. Maximum 8 characters.
CONTROL_FILES
No
Strongly recommended. If not provided, then the database instance creates one control file in the same location as the initialization parameter file. Providing this parameter enables you to multiplex control files.
Ex: CONTROL_FILES = (/u01/oracle/demo/control01.ctl,
                 /u02/oracle/demo/control02.ctl,
                 /u03/oracle/demo/control03.ctl)
MEMORY_TARGET
No
Sets the total amount of memory used by the instance and enables automatic memory management. You can choose other initialization parameters instead of this one for more manual control of memory usage. See "Configuring Memory Manually".

Example:

*.audit_file_dest='/u01/app/oracle/admin/demo/adump'
*.audit_trail='db'
*.compatible='11.2.0.0.0'
*.control_files='/u01/app/oracle/oradata/demo/control01.ctl','/u01/app/oracle/flash_recovery_area/demo/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='demo'
*.db_recovery_file_dest='/u01/app/oracle/flash_recovery_area'
*.db_recovery_file_dest_size=4039114752
*.diagnostic_dest='/u01/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'
*.log_archive_format='%t_%s_%r.dbf'
*.memory_target=856686592
*.open_cursors=300
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.resource_limit=TRUE
*.undo_tablespace='UNDOTBS1'

Step 5: (Windows Only) Create an Instance

On the Windows platform, before you can connect to an instance, you must manually create it if it does not already exist. The ORADIM command creates an Oracle instance by creating a new Windows service.

>oradim -NEW -SID sid -STARTMODE MANUAL -PFILE pfile

Step 6: Connect to the Instance

To authenticate with a password file, enter the following commands, and then enter the SYS password when prompted:

$ sqlplus /nolog

SQL> CONNECT SYS AS SYSDBA

To authenticate with operating system authentication, enter the following commands:

$ sqlplus /nolog

SQL> CONNECT / AS SYSDBA

Step 7: Create a Server Parameter File

SQL>CREATE SPFILE FROM PFILE;

Step 8: Start the Instance

SQL> STARTUP NOMOUNT

Step 9: Issue the CREATE DATABASE Statement

CREATE DATABASE demo
   USER SYS IDENTIFIED BY oracle
   USER SYSTEM IDENTIFIED BY oracle
   LOGFILE GROUP 1 ('/u01/app/oracle/oradata/demo/redo1a.log') SIZE 64M REUSE,
           GROUP 2 ('/u01/app/oracle/oradata/demo/redo2a.log') SIZE 64M REUSE
   MAXLOGFILES 32
   MAXLOGMEMBERS 3
   MAXLOGHISTORY 1
   MAXDATAFILES 200
   CHARACTER SET AL32UTF8
   NATIONAL CHARACTER SET AL16UTF16
   EXTENT MANAGEMENT LOCAL
   DATAFILE '/u01/app/oracle/oradata/demo/system01.dbf' SIZE 325M REUSE
   SYSAUX
   DATAFILE '/u01/app/oracle/oradata/demo/sysaux01.dbf' SIZE 128M REUSE
   DEFAULT TABLESPACE users
   DATAFILE '/u01/app/oracle/oradata/demo/users01.dbf'  SIZE 32M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
   DEFAULT TEMPORARY TABLESPACE tempts1
   TEMPFILE '/u01/app/oracle/oradata/demo/temp01.dbf' SIZE 32M REUSE
   UNDO TABLESPACE undotbs1
   DATAFILE '/u01/app/oracle/oradata/demo/undotbs01.dbf' SIZE 128M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

Step 11: Run Scripts to Build Data Dictionary Views

@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql
@?/sqlplus/admin/pupbld.sql


Script
Description
CATALOG.SQL
Creates the views of the data dictionary tables, the dynamic performance views, and public synonyms for many of the views. Grants PUBLIC access to the synonyms.
CATPROC.SQL
Runs all scripts required for or used with PL/SQL.
PUPBLD.SQL
Required for SQL*Plus. Enables SQL*Plus to disable commands by user.

Friday, 6 January 2017

Oracle Data Pump:

Oracle Data Pump is a newer, faster and more flexible alternative to the "exp" and "imp" utilities used in previous Oracle versions.

Roles:
Many Data Pump Export and Import operations require the user to have the DATAPUMP_EXP_FULL_DATABASE role and/or the DATAPUMP_IMP_FULL_DATABASE role.The DATAPUMP_EXP_FULL_DATABASE role affects only export operations. The DATAPUMP_IMP_FULL_DATABASE role affects import operations and operations that use the Import SQLFILE parameter.

Key Features:

Fast Performance:

Operations performed with the new Data Pump Export and Import utilities are typically much faster than operations performed with the original Export and Import utilities. With Data Pump Export, when the direct path method of unloading is used, a single stream of data unload is about two times faster than original Export. This is because the direct path API has been modified to be even more efficient than before. Depending on the level of parallelism, the performance improvement can be even greater.

With Data Pump Import, a single stream of data load is about 15-45 times faster than original Import. This is because original Import uses only conventional mode inserts, whereas Data Pump Import uses the direct path method of loading. As with Export, the performance improvement can be even greater depending on the level of parallelism.

Improved Management Restart:

Every Data Pump operation has a master table that is created in the schema of the user running a Data Pump job. The master table maintains information about all aspects of the job, such as the current state of every object exported or imported and its location in the dump file set. In the event of a planned or unplanned job stoppage, Data Pump knows which objects were currently being worked on and whether or not they completed successfully. Therefore, all stopped Data Pump jobs can be restarted without loss of data as long as the master table and dump file set remain undisturbed while the job is stopped.

Object Selection:

A Data Pump job can exclude or include virtually any type of object and any subset of objects within a type. The following client parameters are used:

    The EXCLUDE parameter filters the metadata that is exported and imported by specifying objects and object types to be excluded from the current operation. An optional name qualifier can be used for finer selectivity within each object type specified.
    The INCLUDE parameter filters the metadata that is exported and imported by specifying objects and object types to be included for the current operation. An optional name qualifier can be used for finer selectivity within each object type specified.
    The CONTENT parameter specifies what is exported or imported: metadata only, data only, or both.
    The QUERY parameter filters data by specifying a clause for a SQL SELECT statement, which is applied to all tables in the export job or to a specific table.

Monitoring and Estimating Capability:

In addition to the standard progress and error messages printed by the client and to the log file, the new interactive STATUS command displays cumulative status of the job, along with a description of the current operation. An estimated completion percentage for the job is also returned. The user can also specify a time period, in seconds, for an automatic status update at specific intervals.

Because more than one client can be attached to a running job, the user can start a job at work, detach from it, go home, reattach to the job at home, and monitor it throughout the evening.

The start of every export job now includes an estimate phase in which the approximate amount of all data to be unloaded is determined. This allows the user to allocate a sufficient amount of disk space for the dump file set.

Network Mode:

Data Pump Export and Import both support a network mode in which the job's source is a remote Oracle instance. When you perform an import over the network, there are no dump files involved because the source is another database, not a dump file set.

When you perform an export over the network, the source can be a read-only database on another system. Dump files are written out on the local system just as they are with a local (non-networked) export.

Default Locations for Dump, Log, and SQL Files
Because Data Pump is server-based, rather than client-based, dump files, log files, and SQL files are accessed relative to server-based directory paths. Data Pump requires you to specify directory paths as directory objects. A directory object maps a name to a directory path on the file system.
For example, the following SQL statement creates a directory object named dpump_dir1 that is mapped to a directory located at /u01/app/dumpfiles.

SQL> CREATE DIRECTORY dpump_dir1 AS '/u01/app/dumpfiles';

The reason that a directory object is required is to ensure data security and integrity. For example:
If you were allowed to specify a directory path location for an input file, you might be able to read data that the server has access to, but to which you should not.
If you were allowed to specify a directory path location for an output file, the server might overwrite a  file that you might not normally have privileges to delete.
On Unix and Windows NT systems, a default directory object, DATA_PUMP_DIR, is created at database creation or whenever the database dictionary is upgraded. By default, it is available only to privileged users.
If you are not a privileged user, before you can run Data Pump Export or Data Pump Import, a directory object must be created by a database administrator (DBA) or by any user with the CREATE ANY DIRECTORY privilege.
After a directory is created, the user creating the directory object needs to grant READ or WRITE permission on the directory to other users. For example, to allow the Oracle database to read and write files on behalf of user hr in the directory named by dpump_dir1, the DBA must execute the following command:

SQL> GRANT READ, WRITE ON DIRECTORY dpump_dir TO ramesh;

Note that READ or WRITE permission to a directory object only means that the Oracle database will read or write that file on your behalf. You are not given direct access to those files outside of the Oracle database unless you have the appropriate operating system privileges. Similarly, the Oracle database requires permission from the operating system to read and write files in the directories.

Original Export and Import versus Data Pump Export and Import
If you are familiar with the original Export (exp) and Import (imp) utilities, it is important to understand that many of the concepts behind them do not apply to Data Pump Export (expdp) and Data Pump Import (impdp). In particular:
Data Pump Export and Import operate on a group of files called a dump file set rather than on a single sequential dump file.
Data Pump Export and Import access files on the server rather than on the client. This results in improved performance. It also means that directory objects are required when you specify file locations.
Data Pump Export and Import use parallel execution rather than a single stream of execution, for improved performance. This means that the order of data within dump file sets and the information in the log files is more variable.
Data Pump Export and Import represent metadata in the dump file set as XML documents rather than as DDL commands. This provides improved flexibility for transforming the metadata at import time.
Data Pump Export and Import are self-tuning utilities. Tuning parameters that were used in original Export and Import, such as BUFFER and RECORDLENGTH, are neither required nor supported by Data Pump Export and Import.
At import time there is no option to perform interim commits during the restoration of a partition. This was provided by the COMMIT parameter in original Import.
There is no option to merge extents when you re-create tables. In original Import, this was provided by the COMPRESS parameter. Instead, extents are reallocated according to storage parameters for the target table.
Sequential media, such as tapes and pipes, are not supported.
The Data Pump method for moving data between different database versions is different than the method used by original Export/Import. With original Export, you had to run an older version of Export (exp) to produce a dump file that was compatible with an older database version. With Data Pump, you can use the current Export (expdp) version and simply use the VERSION parameter to specify the target database version.
When you are importing data into an existing table using either APPEND or TRUNCATE, if any row violates an active constraint, the load is discontinued and no data is loaded. This is different from original Import, which logs any rows that are in violation and continues with the load.
Data Pump Export and Import consume more undo tablespace than original Export and Import. This is due to additional metadata queries during export and some relatively long-running master table queries during import. As a result, for databases with large amounts of metadata, you may receive an ORA-01555: snapshot too old error. To avoid this, consider adding additional undo tablespace or increasing the value of the UNDO_RETENTION initialization parameter for the database.
If a table has compression enabled, Data Pump Import attempts to compress the data being loaded. Whereas, the original Import utility loaded data in such a way that if a even table had compression enabled, the data was not compressed upon import.

Examples:
--------------
Export Full Database Mode
Only users with the DBA role or the DATAPUMP_EXP_FULL_DATABASE role can export in full database mode. In this example, an entire database is exported to the filedba.dmp.

Scenario:
Connect to database and create user.
Sql>create user ramesh identified by ramesh;
User created
SQL> grant connect,resource to ramesh;
Grant succeeded.
SQL>create directory dump as ‘/u01/app/backup’;
NOTE: Check the directory exists or not physically in OS level. In not there need to create.
$mkdir /u01/app/backup
SQL>grant read,write on directory dump to system;
SQL> conn ramesh
Enter password:
Connected.
And create some tables in the user, I created two tables as bellow
SQL> select * from tab;
TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
TEST                           TABLE
TEST_TBL                       TABLE
Sql>conn sys as sysdba
Enter password:
connected
Sql>create user siva identified by siva;
User created
SQL> grant connect,resource to siva;
Grant succeeded.
SQL> conn siva
Enter password:
Connected.
Create table in this user also.
SQL> select * from tab;
TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
EMPLOYEE                       TABLE

Now export full database by using full=y parameter.
$expdp system/xxxxx directory=dump dumpfile=full_db.dmp logfile=full_db.log full=y
After completing the export, drop the user.
SQL> drop user ramesh cascade;
User dropped.
SQL> drop user siva cascade;
User dropped.
Check the user existence in database;
SQL> select username from dba_users where username in ('RAMESH',’SIVA’);
no rows selected
Now import the exported dumpfile to restore the dropped user using ignore=y.
$impdp system/xxxxxx directory=dump dumpfile=full_database.dmp logfile=full_db.log table_exists_action=append full=y
Now export data imported, now check the user in the database.
SQL> select username from dba_users where username IN ('RAMESH',’SIVA’);
USERNAME
------------------------------
RAMESH
SIVA

SQL> conn ramesh
Enter password:
Connected.
SQL> select * from tab;
TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
TEST                           TABLE
TEST_TBL                       TABLE
User Mode
For exporting user owner parameter will be used.
Scenario:
Export the user using owner parameter
$expdp system/xxxxx directory=dump dumpfile=ramesh_data.dmp logfile=ramesh_data.log schemas=ramesh
Now drop the user in database
SQL>drop user ramesh cascade;
User dropped.
Now check the user existence.
SQL>select username from dba_users where username=’RAMESH’;
no rows selected
Now try to import the dumpfile into database, so that dropped user will come back.
[oracle@localhost ~]$ impdp system/xxxxx directory=dump dumpfile=ramesh_data.dmp logfile=ramesh.log;
Import is done
SQL> select username from dba_users where username='RAMESH';
USERNAME
------------------------------
RAMESH

SQL> select object_name,object_type from dba_objects where owner='RAMESH';
OBJECT_NAME          OBJECT_TYPE
-------------------- --------------------
TEST_TBL             TABLE
TEST                 TABLE

 Exporting table:

To export a table we use tables parameter in expdp utility.
In this example we are taking backup of the table test_tbl belongs to ramesh schema to the dump file tbl_exp.dmp.
[oracle@localhost ~]$ expdp system/xxxxx directory=dump dumpfile=tbl_exp.dmp logfile=tbl_exp.log tables=ramesh.test_tbl;

Export: Release 11.2.0.1.0 - Production on Thu Jan 8 07:44:48 2015

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
EXP-00056: ORACLE error 28002 encountered
ORA-28002: the password will expire within 7 days
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses WE8MSWIN1252 character set (possible charset conversion)
About to export specified tables via Conventional Path ...
Current user changed to RAMESH
. . exporting table                       TEST_TBL          5 rows exported
Export terminated successfully without warnings.
Now import the exported table into another user siva. To do this, we need to user remapschema parameters as bellow.
[oracle@localhost ~]$ impdp system/xxxxx directory=dump dumpfile=tbl_exp.dmp logfile=tbl_imp.log remap_schema=ramesh:siva tables=ramesh.test_tbl;

Parameter File Method
$expdp SYSTEM/password PARFILE=params.par
The params.dat file contains the following information:
Userid=’system/xxxxx’
dumpfile=/u01/app/full_db.dmp
logfile=/u01/app/full_db.log
FULL=y



=========