Query select on varchar2 works without apex - oracle

I have a query on field type varchar2 that works also without apex.
E.g.
SELECT * FROM table WHERE field = 123456
where field is varchar2, and it returns the result and not the
ORA-01722: invalid number.
There is some setting on DB that make it possible? Thankx.

If that column's datatype is varchar2, then enclose its value with single quotes:
SELECT * FROM table WHERE field = '123456'
There's no setting that would "remove" invalid number error, as far as I can tell.
Query you posted works when there are only "numbers" in a table; though, when "something else" (it is a varchar2 after all) is stored in the column, it won't work any more:
Sample table:
SQL> create table test (id number, field varchar2(10));
Table created.
Numbers only:
SQL> insert into test (id, field) values (1, 123456);
1 row created.
SQL> select * from test where field = 123456;
ID FIELD
---------- ----------
1 123456
Enter value that contains e.g. letters in field:
SQL> insert into test (id, field) values (2, 'ABC');
1 row created.
SQL> select * from test where field = 123456;
ERROR:
ORA-01722: invalid number
no rows selected
SQL>
So, it is not "Apex" to blame, but you who tried to misuse what you have.

Related

How does Number data type work in Oracle 21c?

I created a table like this:
CREATE TABLE table(
id INTEGER GENERATED ALWAYS AS IDENTITY,
nome VARCHAR2(100 CHAR)
)
ALTER TABLE table ADD CONSTRAINT table_pk PRIMARY KEY (ID);
CREATE UNIQUE INDEX TABLE_UNIQ_IDX ON TABLE(NOME ASC);
ALTER TABLE table ADD (PERC NUMBER(1, 2) NOT NULL);
Then I tried to write 2 records on it:
INSERT INTO TABLE(NOME,PERC)VALUES('a',0.8);
INSERT INTO TABLE(NOME,PERC)VALUES('b',0.2);
Then I received this error:
ORA-01438: valor maior que a precisão especificada usado para esta coluna
Translated:
ORA-01438: value larger than specified precision allows for this column
I tried select cast (0.8 as number(1,1)) from dual; and it worked but when I tried select cast (0.8 as number(1,2)) from dual; I received the same error.
I then tried select cast (0.81 as number(1,2)) from dual; and received the same ORA-01438.
I changed my field to number(1,1), no big deal, but how does this "Number" data type work?
Shouldn't select cast (0.81 as number(1,2)) from dual; have worked?
Why does select cast (0.81 as number(2,2)) from dual; work and
select cast (0.81 as number(2,3)) from dual; does not?
Thanks for any help
If you have NUMBER(precision, scale) then precision is the number of digits and scale is the number of decimal places.
So, NUMBER(1, 2) has a single digit and 2 decimal places. The minimum value it can store is -0.09 and the maximum it can store is +0.09.
NUMBER(2,2) works as it stores 2 digits in 2 decimal places (from -0.99 to +0.99).
NUMBER(2,3) does not work as it stores 2 digits in 3 decimal places (from -0.099 to +0.099).
What you said, is that perc column should accept numeric values whose length is 1, and out of that 1, you want to keep 2 decimal places. That won't work.
SQL> create table test (perc number(1, 2));
Table created.
SQL> insert into test values (0.8);
insert into test values (0.8)
*
ERROR at line 1:
ORA-01438: value larger than specified precision allowed for this column
Perhaps you meant to put it vice versa?
SQL> alter table test modify perc number(2, 1);
Table altered.
SQL> insert into test values (0.8);
1 row created.
SQL>

The data model cannot be executed because of an error, please contact the administrator

I have a data sets that contains a columns which the parameters is by name, date and number. But everytime I view the data there's a error said The data model cannot be executed because of an error, please contact the administrator. But it only show the message but didn't show the details of the error. I also have a list of values because I set the parameter type of my parameters for name and number as a menu which is the result
that will return for the number is based on the name because if I didn't base it on the name it will return a 100+ values which is not okay to my user.
My query for my data set for example is,
select a.name, a.date, a.type_name, b.number, c.address
from details1 a, details2 b, details3 c
where
a.id = b.id
and b.id = c.id
and a.name = :name
and a.date between :start_date and :end_date
and b.number = :number
Query of List of Values for name
select a.name from details1 a
where a.type_name = 'person'
Query of List of Values for num
select b.number
from details1 a, details2 b
where 1=1
and a.id = b.id
and a.name = :name
I don't know BI Publisher, but - as far as Oracle is concerned, column name can not be number. It is reserved word for a datatype:
SQL> create table test (number number);
create table test (number number)
*
ERROR at line 1:
ORA-00904: : invalid identifier
Your query uses such a column:
select b.number ...
which can't work, unless someone created such a table by enclosing column name into double quotes, e.g.
SQL> create table test ("number" number);
Table created.
SQL> desc test
Name Null? Type
----------------------------------------- -------- ---------------
number NUMBER
SQL>
However, you'll have to specify such a column name using double quotes every time, paying attention to letter case (meaning: if column was created as "NumBER", you have to reference it exactly that way. "numBER" or "NUMber" or "nUmBeR" or "number" or "NUMBER" won't work). A few examples:
SQL> insert into test (number) values (1);
insert into test (number) values (1)
*
ERROR at line 1:
ORA-00928: missing SELECT keyword
SQL> insert into test ("NUMber") values (1);
insert into test ("NUMber") values (1)
*
ERROR at line 1:
ORA-00904: "NUMber": invalid identifier
SQL> insert into test ("NUMBER") values (1);
insert into test ("NUMBER") values (1)
*
ERROR at line 1:
ORA-00904: "NUMBER": invalid identifier
SQL> insert into test ("number") values (1);
1 row created.
SQL> select t."number" from test t;
number
----------
1
SQL>
Therefore, I'd suggest you to check table description and try with what you see; maybe it is as simple as
select b."number" ...
If that's the case, it is more than obvious that doing something because you can do it doesn't mean that you should do it. Avoid such things, never enclose Oracle object names into double quotes, use defaults.

How to increment the value of the unique constraint column value in ORACLE

How to increment the value of the unique constraint column value in ORACLE, in the select statement.
For example, in a table 'BILLING_TABLE' - column BLNG_Sk is the unique key (Autoincremented).
So while inserting a new record into the BILLING_TABLE, for the column BLNG_SK we need to give the value (Which is the increment by 1 from the present max value.)
For example, if BLNG_SK max value is 12321.
new record should be 12322.
how to achieve this in Oracle?
Oracle has a SEQUENCE object which provides the functionality you require.
You create one using the CREATE SEQUENCE SQL statement.
The Oracle documentation provides all the required information and the documentation is available via Oracle's Web site.
Assuming you are on Oracle 12.1 or later, define it as an identity column and do not pass any value when inserting:
create table testtable
( test_id number generated always as identity
constraint testtable_pk primary key
, othercol varchar2(10) );
insert into testtable (othercol) values ('Demo');
select * from testtable;
TEST_ID OTHERCOL
---------- ----------
1 Demo
insert into testtable (othercol) values ('Demo #2');
select * from testtable;
TEST_ID OTHERCOL
---------- ----------
1 Demo
2 Demo #2
Try creating a sequence and a trigger. This is the case when you provide the value manually.
CREATE SEQUENCE dept_seq START WITH 12322;
Trigger definition:
CREATE OR REPLACE TRIGGER dept_bir
BEFORE INSERT ON BILLING_TABLE
FOR EACH ROW
BEGIN
SELECT dept_seq.NEXTVAL
INTO :new.id
FROM dual;
END;
/

How should I use an object type in an insert DML statement?

I have created two TYPE objects to try out OOP processing in PL/SQL.
I tried to use my type o_customers in my INSERT statement, but I could not do it.
There is a Customers table. It has same columns as o_customers.
create or replace type o_customers as object (
id number,
name varchar2(40),
age number,
address o_addressC,
salary number
);
create or replace type o_addressC as object (
mahalle varchar(30),
apartman varchar(15),
ilce varchar(15),
apt_no number
);
declare
adres o_addressC;
musteri o_customers;
begin
adres := o_addressC('selami ali mah','çınar apt',' üsküdar',19);
musteri:= o_customers(10,'UĞUR SİNAN SAĞIROĞLU',26,adres,1000);
insert into customers values (musteri);
end;
" There is a customers table. it has same columns with o_customers"
In OOP it is not enough for objects to have the same structure to be compatible in a programming context: they must be the same type, or related to each other through inheritance.
So you need to create the table using that type:
SQL> create table customers of o_customers
2 /
Table created.
SQL> desc customers
Name Null? Type
---------------------- -------- -------------
ID NUMBER
NAME VARCHAR2(40)
AGE NUMBER
ADDRESS O_ADDRESSC
SALARY NUMBER
SQL>
Now your insert statement will work:
SQL> declare
2 adres o_addressC;
3 musteri o_customers;
4 begin
5 adres := o_addressC('selami ali mah','cınar apt','uskudar',19);
6 musteri:= o_customers(10,'UĞUR SİNAN SAĞIROĞLU',26,adres,1000);
7 insert into customers values(musteri);
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> select * from customers;
ID NAME AGE
---------- ---------------------------------------- ----------
ADDRESS(MAHALLE, APARTMAN, ILCE, APT_NO)
------------------------------------------------------------------------------------------------------------------------------------------------------
SALARY
----------
10 UĞUR SİNAN SAĞIROĞLU 26
O_ADDRESSC('selami ali mah', 'c??nar apt', ' uskudar', 19)
1000
SQL>
Incidentally I had to make minor changes to the inserted values because the posted statement hurled
declare
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 6
This is because your o_addressC type attributes are too small for strings with multi-byte characters.
Unless customers is an object table (create table customers of o_customers), you'll need to refer to the object's properties explicitly:
insert into customers
( id, name, age, address, salary)
values
( musteri.id, musteri.name, musteri.age, musteri.address, musteri.salary );
By the way, o_customer (no 's') would make more sense than o_customers for an object name.

Data Type issue in one of the filelds in Table

One of my field has Data Type as Numeric and the size is (16,8). If I give the value as 0.000000012 will it take and load it in the table? As there are 9 places after the decimal.
It will accept and round the values (at least in 11g):
SQL> CREATE TABLE tst (c1 NUMBER(10,2));
Table created
SQL> INSERT INTO tst VALUES (9.123);
1 row inserted
SQL> INSERT INTO tst VALUES (9.129);
1 row inserted
SQL> SELECT * FROM tst;
C1
------------
9.12
9.13

Resources