postgres oracle sql difference functionality - ghdrako/doc_snipets GitHub Wiki

oracle postgresql desc
to_number(col,'xxxxxxxxxxxxxxxx') SELECT ('x' || lpad(hex, 16, '0'))::bit(64)::bigint conv 16 znakow hex na number
len(col_str) lenght(col_str) dlugosc stringu
123 || 456 -> 123456 123 || 456 -> Error concatenation
nvl(MY_FIELD,'N/A') coalesce(MY_FIELD,'N/A') default value
is not equal to NULL is equal to NULL empty string
upper(description) like '%DISCUSS%' description ilike '%DISCUSS%' case-insensitive like query
substr(tag,20) substring(tag from 0 for 20) first 20 characters of the tag string
automonous transaction unsupported unsupported
alter table test add c4 varchar2(10) default 'd1' not null; alter table test add c4 varchar(10) not null default 'd1'; add defalut column not null
sysdate current_date current date
ROWID ctid physical address of a table row
alter table t add column c char(1); alter table t add c char(1); add column to table
ALTER TABLE tbl_name ALTER COLUMN col_name TYPE integer USING (NULLIF(col_name, '')::integer); ALTER TABLE <table_name> MODIFY (<column_name> <new_Type>) modify column typ from text to integer
ALTER TABLE tbl_name ALTER COLUMN col_name TYPE varchar (11), ALTER COLUMN col_name2 TYPE varchar (11),ALTER COLUMN col_name3 TYPE varchar (11); ALTER TABLE place MODIFY (street_name VARCHAR2(20), county VARCHAR2(20), city VARCHAR2(20)) modify multiple column typ/size
create table t(id serial primary key); create sequence seq start with 1; create table t(id number primary key); insert into t(id) values(seq.NEXVAL); autoincrementacja
STRING_AGG LISTAGG f. analityczna
:: or function CAST selet '123':INTEGER; selet cast('123' as number) from dual; rzutowanie typow
LIMIT/OFFSET select * from t limit 10 ofset 5; ROWNUM lub `FETCH FIRST N ROWS ONLY' limitowanie wynikow zapytan
ALTER TABLE table_name RENAME TO new_table_name; ALTER TABLE table_name RENAME TO new_table_name;' alter table ebk.jeden rename to temp_jeden;` rename table
SELECT ROWNUM, * FROM employees; SELECT ROW_NUMBER() OVER () AS rownum, * FROM employees;
brak synonymes,hints

Types conversion

Postgres Oracle
boolean NUMBER(1) 0/1 CHAR(1) T/F
bigint / int8 int , number(18,0)
character varying(s) , bpchar(s) varchar2(s) ,character varying
character(s) char(s) character(s)
integer / int4 int, number(9,0)
numeric / decimal number
numeric(p,s) / decimal(p,s) number(p,s)
numeric(p) / decimal(p) numeric(p,0)
real float
xml xmltype
  • Oracle ROWID format OOOOOO.FFF.BBBBBB.RRR ... - unikalny w skali bazy, określa fizyczna lokalizacje wiersza
  • ctid . unikalny tylko w tabeli - nie określa lokalizacji wiersza

PCTFREE - fillfactor

CREATE TABLE distributors (
did integer,
name varchar(40),
UNIQUE(name) WITH (fillfactor=70)
)
WITH (fillfactor=70);

Virtual Column in Oracle

CREATE TABLE employees (
id NUMBER,
first_name VARCHAR2(10),
salary NUMBER(9,2),
commission NUMBER(3),
salary2 NUMBER GENERATED ALWAYS AS
(ROUND(salary*(1+commission/100),2)) VIRTUAL
);

Postgres 12

CREATE TABLE employees (
id bigint,
first_name varchar(10),
salary double precision,
commission integer,
salary2 double precision generated always as
(ROUND((salary*(1+commission/100))::numeric,2)) STORED
);

Tabele w Oraclu z defaulta przechowywane sa z duzej litery a w postgres z malej.

Oracle pozwala na

SELECT * FROM test HAVING count(*) > 3 GROUP BY i;

Indexes

In Oracle indexes on column not contain null values but in Postgres contain. To simulate use for postgres partia index that exclude null values and for oracle function Index where function convert null to something other and indexing

⚠️ **GitHub.com Fallback** ⚠️