Oracle - Unable to set precision to the database setting #5705

Closed
opened 2026-01-22 15:15:04 +01:00 by admin · 2 comments
Owner

Originally created by @nuncanada on GitHub (Sep 19, 2017).

Our current database has been created with the NUMBER datatype without any precision parameter.

Is it possible to configure Doctrine to not use any precision parameter?

For some reason Doctrine defaults to precision 10? I am trying to make Doctrine output the correct precision (which could be *) but unable to do so because Doctrine is checking for an integer:

[Doctrine\Common\Annotations\AnnotationException]
[Type Error] Attribute "precision" of @ORM\Column declared on property Stm\Model\SIPOC_WEB\TbResposta::$id expects a(n) integer, but got string.

I have already tried to put precision=38 which is the maximum precision for Oracle, but for some reason Oracle still thinks we are trying to change the precision when modifying the datatype from NUMBER to NUMBER(38).
The coversion does work from NUMBER to NUMBER(*).

Originally created by @nuncanada on GitHub (Sep 19, 2017). Our current database has been created with the NUMBER datatype without any precision parameter. Is it possible to configure Doctrine to not use any precision parameter? For some reason Doctrine defaults to precision 10? I am trying to make Doctrine output the correct precision (which could be *) but unable to do so because Doctrine is checking for an integer: [Doctrine\Common\Annotations\AnnotationException] [Type Error] Attribute "precision" of @ORM\Column declared on property Stm\Model\SIPOC_WEB\TbResposta::$id expects a(n) integer, but got string. I have already tried to put precision=38 which is the maximum precision for Oracle, but for some reason Oracle still thinks we are trying to change the precision when modifying the datatype from NUMBER to NUMBER(38). The coversion does work from NUMBER to NUMBER(*).
admin closed this issue 2026-01-22 15:15:04 +01:00
Author
Owner

@cyframepaul commented on GitHub (Nov 30, 2017):

@nuncanada you can just extend the OraclePlatform getIntegerTypeDeclarationSQL in your project if you have this requirement. Alternatively, you could add a custom mapping type that extends IntegerType..

Here is an example of extending OraclePlatform. Adjust as needed.

Add this to your configs:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                platform_service: stm.dbal.oracle_platform

services:
    stm.dbal.oracle_platform:
      class: Stm\Doctrine\DBAL\Platforms\OraclePlatform

And extend OraclePlatform like so:

<?php
namespace Stm\Doctrine\DBAL\Platforms;

use Doctrine\DBAL\Platforms\OraclePlatform as OraclePlatformOrigin;

class OraclePlatform extends OraclePlatformOrigin{
    /**
     * {@inheritDoc}
     */
    public function getIntegerTypeDeclarationSQL(array $field)
    {
        return 'NUMBER';
    }
}
@cyframepaul commented on GitHub (Nov 30, 2017): @nuncanada you can just extend the [OraclePlatform getIntegerTypeDeclarationSQL](https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/OraclePlatform.php#L270) in your project if you have this requirement. Alternatively, you could [add a custom mapping type](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/custom-mapping-types.html) that extends IntegerType.. Here is an example of extending OraclePlatform. Adjust as needed. Add this to your configs: ```yml doctrine: dbal: default_connection: default connections: default: platform_service: stm.dbal.oracle_platform services: stm.dbal.oracle_platform: class: Stm\Doctrine\DBAL\Platforms\OraclePlatform ``` And extend OraclePlatform like so: ```php <?php namespace Stm\Doctrine\DBAL\Platforms; use Doctrine\DBAL\Platforms\OraclePlatform as OraclePlatformOrigin; class OraclePlatform extends OraclePlatformOrigin{ /** * {@inheritDoc} */ public function getIntegerTypeDeclarationSQL(array $field) { return 'NUMBER'; } } ```
Author
Owner

@beberlei commented on GitHub (Dec 8, 2020):

Yes custom type is the solution.

@beberlei commented on GitHub (Dec 8, 2020): Yes custom type is the solution.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5705