Is there any way to set table or fields to be ignore case? And I don't want to use lower or upper function. I'm shocked from oracle if they not support Ignore case, I still searching but I didn't find any solution
As you said, you can't explicitly make a column "case insensitive".
You can, however, work around it by using virtual columns, triggers, check constraints or just querying using case insensitive predicates and upper/lower functions.
Some examples:
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.4.0
Connected as fsitja#sitja
SQL>
SQL> create table job (JOB_TITLE varchar2(40));
Table created
SQL> alter table job add constraint ck_job_upper check (job_title = upper(job_title));
Table altered
SQL> insert into job values ('clerk');
insert into job values ('clerk')
ORA-02290: restrição de verificação (FSITJA.CK_JOB_UPPER) violada
SQL> insert into job values ('CLERK');
1 row inserted
SQL> commit;
Commit complete
SQL> create or replace trigger tr_br_upper_job_title before insert or update of job_title on job
2 for each row
3 begin
4 :new.job_title := upper(:old.job_title);
5 end;
6 /
Trigger created
SQL> insert into job values ('clerk');
1 row inserted
SQL> select * from job;
JOB_TITLE
----------------------------------------
CLERK
SQL> commit;
Commit complete
SQL>
SQL> drop table job;
Table dropped
SQL> create table job (JOB_TITLE varchar2(40), upper_job_t as (upper(job_title)));
Table created
SQL> insert into job (job_title) values ('CLERK');
1 row inserted
SQL> insert into job (job_title) values ('clerk');
1 row inserted
SQL> commit;
Commit complete
SQL> select * from job where regexp_like(job_title, 'CLERK', 'i');
JOB_TITLE UPPER_JOB_T
---------------------------------------- ----------------------------------------
CLERK CLERK
clerk CLERK
SQL>
Related
I'm getting mutating table error for statement insert into employee select 'xyz',200 from dual and scripts executes successfully for insert into employee values ('abc',100);.
Can somebody explain why the statement fails for one type of insert statement? Both scripts insert similar type of data into table
details of script:
--table creation
create table employee (name varchar2(30),salary number);
--trigger creation
create or replace trigger emp_trig
before insert on employee
for each row
begin
delete from employee where name=:new.name;
end;
/
--insert statement 1
insert into employee values ('abc',100);
--result : 1 row inserted
--insert statement 2
insert into employee select 'xyz',200 from dual
--result:
Error report -
ORA-04091: table NMS_CON.EMPLOYEE is mutating, trigger/function may not see it
ORA-06512: at "NMS_CON.EMP_TRIG", line 2
ORA-04088: error during execution of trigger 'NMS_CON.EMP_TRIG'
Inserting a single row will not lead to a mutating table error - how could it, since that row wasn't there before?
But insert-select potentially involves more than one row, so then you get the error.
Generally, you should not have non-query DML operations in your trigger. Too many possible side effects and undesirable consequences.
A better approach is to write a procedure that will do the insert for you, do not give insert privileges on the table directly, only to the package that owns the procedure. Then inside that procedure you can do a delete before your insert, or you can do a merge - or whatever.
All the logic is hidden inside the procedure and by restricting privs on the table, you ensure that the procedure must be called.
Hope that helps!
How to insert into oracle cluster tables and how to validate data inserted into that two tables correctly or not?
if I have two tables amp and dept.
these two table is cluster table and share same data blocks.
can I insert data into both table by simple insert statement.
can I insert data into both table by simple insert statement.
Yes, using INSERT ALL, such as
insert all
into emp (empno, ename) values (1, 'Little')
into emp (empno, ename) values (2, 'Foot')
--
into dept (deptno, dname) values (100, 'IT')
select * from dual;
I have a db in sqllite and it has almost 140 tables and many columns. And I don't know which table contain what column I have a specific requirement to search for specific column name
.
For example I have a database called msg. And it has almost 100 tables after lots of try I am unable to find exact column name like I am searching for localid in db from all table. I am using Sqllitestudio to see the db.
My question is can I search for just a column name and in which table or in how many tables that particular column exist.
Start the sqlite commandline tool.
Ask the "table of tables" about anything mentioning " localid " in the creation statement.
create table toy1 (thisid int, aletter char(1), anotherint int);
create table toy2 (globalid int, aletter char(1), localid int);
select * from sqlite_master where sql like '% localid %';
Output (with .headers on, in SQLite 3.18.0):
type name tbl_name rootpage sql
---------- ---------- ---------- ---------- --------------------------------------------------------------
table toy2 toy2 3 CREATE TABLE toy2 (globalid int, aletter char(1), localid int)
Edit the "where" clause to make the filter tighter or more generous, depending on what you need.
In sqlite, how do I restrict the values of a column to being not in another table/view column?
For example
sqlite> create table tab1(col1 check (col1 not in (1,2)));
does what I want except that it seems only to exclude hard-coded values. However, the following does not work -
sqlite> create table tab2(vals_to_exclude);
sqlite> insert into tab2 values(1);
sqlite> insert into tab2 values(2);
sqlite> create table tab3(col1 check (col1 not in (select vals_to_exclude from tab2)));
Error: subqueries prohibited in CHECK constraints
Is it possible to constrain a column to exclude a dynamically determined set of values?
If the built-in mechanisms are not sufficient, implement the check manually with a trigger:
CREATE TRIGGER tab3_col1_not_in_tab2
BEFORE INSERT ON tab3 -- you also need a trigger for UPDATEs
FOR EACH ROW
WHEN EXISTS (SELECT 1
FROM tab2
WHERE vals_to_exclude = NEW.col1)
BEGIN
SELECT RAISE(FAIL, "col1 conflicts with tab2");
END;
or, alternatively:
CREATE TRIGGER tab3_col1_not_in_tab2
BEFORE INSERT ON tab3 -- you also need a trigger for UPDATEs
FOR EACH ROW
BEGIN
SELECT RAISE(FAIL, "col1 conflicts with tab2")
FROM tab2
WHERE vals_to_exclude = NEW.col1;
END;
We just migrated from Oracle 8i to Oracle 11g. In doing so we ran into a problem we have a variable called current_time. we use it as both a variable in various procedures and functions ans as well as column names in several tables. The references to the term 'CURRENT_DATE) looks to be in the neighborhood of a few thousand in our procview. When we upgraded, suddenly any time we were referring to the term current_date the new function was overriding the variables and column names. My question is how can we disable the reference to the oracle defined function?
You need to qualify the column name. Otherwise, Oracle's scope resolution rules will choose the function over the column
SQL> create table foo( current_date date );
Table created.
SQL> insert into foo values( date '2011-01-01' );
1 row created.
SQL> select current_date from foo;
CURRENT_D
---------
07-FEB-12
SQL> select f.current_date from foo f;
CURRENT_D
---------
01-JAN-11