Oracle SQL developer is throwing an error message - oracle-sqldeveloper

CREATE TABLE eNB_INFO (
eNBID INTEGER,
eNB_name VARCHAR2(30 CHAR),
eNB_address VARCHAR2(30 CHAR),
eNB_structure VARCHAR2(30 CHAR),
eNB_RBS INTEGER,
eNB_cabinet BOOLEAN,
eNB_PLMNID INTEGER,
eNB_MCC INTEGER,
eNB_MNC INTEGER,
eNB_mncLength INTEGER,
eNB_DUL_count INTEGER,
eNB_tac INTEGER,
eNB_primary_DUL_name VARCHAR2(30 CHAR),
eNB_inter_DU VARCHAR2(30 CHAR),
eNB_DU_one_type INTEGER,
eNB_XMU_one VARCHAR2(30 CHAR),
eNB_XMU_one_port_one VARCHAR2(30 CHAR),
eNB_XMU_one_port_two VARCHAR2(30 CHAR),
eNB_DU_type_two VARCHAR2(30 CHAR),
eNB_XMU_two VARCHAR2(30 CHAR),
eNB_XMU_two_port_one VARCHAR2(30 CHAR),
eNB_XMU_two_port_two VARCHAR2(30 CHAR),
)
Error report -
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:

There's no Boolean datatype in Oracle SQL. Therefore, substitute it by something else. For example, a number (0/1) or char (N/Y) or whatever you find appropriate. For example:
eNB_cabinet NUMBER(1) DEFAULT 0 NOT NULL, --BOOLEAN,
When you remove the last (superfluous) comma, then:
SQL> CREATE TABLE eNB_INFO (
2 eNBID INTEGER,
3 eNB_name VARCHAR2(30 CHAR),
4 eNB_address VARCHAR2(30 CHAR),
5 eNB_structure VARCHAR2(30 CHAR),
6 eNB_RBS INTEGER,
7 eNB_cabinet NUMBER(1) DEFAULT 0 NOT NULL, --BOOLEAN,
8 eNB_PLMNID INTEGER,
9 eNB_MCC INTEGER,
10 eNB_MNC INTEGER,
11 eNB_mncLength INTEGER,
12 eNB_DUL_count INTEGER,
13 eNB_tac INTEGER,
14 eNB_primary_DUL_name VARCHAR2(30 CHAR),
15 eNB_inter_DU VARCHAR2(30 CHAR),
16 eNB_DU_one_type INTEGER,
17 eNB_XMU_one VARCHAR2(30 CHAR),
18 eNB_XMU_one_port_one VARCHAR2(30 CHAR),
19 eNB_XMU_one_port_two VARCHAR2(30 CHAR),
20 eNB_DU_type_two VARCHAR2(30 CHAR),
21 eNB_XMU_two VARCHAR2(30 CHAR),
22 eNB_XMU_two_port_one VARCHAR2(30 CHAR),
23 eNB_XMU_two_port_two VARCHAR2(30 CHAR)
24 );
Table created.
SQL>

Related

Procedure is not executing. Error message is ambiguous

I am trying to execute a stored procedure in postgresql.
create procedure add_future_tickers_intl(
v_ticker_serial numeric,
v_source_id character varying DEFAULT NULL::character varying,
v_ticker_id character varying DEFAULT NULL::character varying,
v_sector_id character varying DEFAULT NULL::character varying,
v_status character,
v_market_md character varying DEFAULT NULL::character varying,
v_source_ticker_id character varying DEFAULT NULL::character varying,
v_instrument_type_id numeric DEFAULT NULL::numeric,
v_currency_id character varying DEFAULT NULL::character varying,
v_country_code character varying DEFAULT NULL::character varying,
v_decimal_places numeric DEFAULT NULL::numeric,
v_decimal_correction_factor numeric DEFAULT NULL::numeric,
v_parent_ticker_id character varying DEFAULT NULL::character varying,
v_parent_source_id character varying DEFAULT NULL::character varying,
v_isin_code character varying DEFAULT NULL::character varying,
v_lot_size numeric DEFAULT NULL::numeric, v_unit character varying DEFAULT NULL::character varying,
v_display_ticker character varying DEFAULT NULL::character varying,
v_last_updated_on timestamp without time zone DEFAULT NULL::timestamp without time zone,
v_comments character varying DEFAULT NULL::character varying,
v_listing_date timestamp without time zone,
v_listing_status numeric DEFAULT NULL::numeric,
v_stock_published_status character varying DEFAULT NULL::character varying,
v_max_stocks numeric DEFAULT NULL::numeric,
v_is_settlement_to numeric DEFAULT NULL::numeric,
v_is_main_stock numeric DEFAULT NULL::numeric,
v_last_updated_time timestamp without time zone DEFAULT NULL::timestamp without time zone,
v_currency_correction_factor numeric,
v_global_sector_id character varying DEFAULT NULL::character varying,
v_dfn_sector character varying DEFAULT NULL::character varying,
v_category character varying DEFAULT NULL::character varying,
v_index_type numeric DEFAULT NULL::numeric,
v_source_source_id character varying DEFAULT NULL::character varying,
v_wkn character varying DEFAULT NULL::character varying,
v_reuter_ssymbol character varying DEFAULT NULL::character varying,
v_bloomberg_symbol character varying DEFAULT NULL::character varying,
v_symbol_status character varying DEFAULT NULL::character varying,
v_eligibility_id numeric DEFAULT NULL::numeric,
v_sharia_compliant numeric DEFAULT NULL::numeric,
v_symbolcode character varying DEFAULT NULL::character varying,
v_exchange_status numeric,
v_assct_ticker_serial numeric DEFAULT NULL::numeric,
v_ticker_assctn_date timestamp without time zone DEFAULT NULL::timestamp without time zone,
v_first_trading timestamp without time zone DEFAULT NULL::timestamp without time zone,
v_idx_main_source_id character varying DEFAULT NULL::character varying,
v_otc numeric DEFAULT NULL::numeric,
v_clearance_duration character varying DEFAULT NULL::character varying,
v_lasttradabledate timestamp without time zone DEFAULT NULL::timestamp without time zone,
v_all_descriptions character varying,
v_maturity_date timestamp without time zone DEFAULT NULL::timestamp without time zone,
v_cusip character varying DEFAULT NULL::character varying,
v_is_desc_updated numeric DEFAULT 1,
v_bbgid character varying DEFAULT NULL::character varying,
v_bbgid_composite character varying DEFAULT NULL::character varying,
v_dec_lot_size numeric DEFAULT NULL::numeric,
v_ticker_classification numeric DEFAULT NULL::numeric,
v_display_decimal_places numeric DEFAULT NULL::numeric,
v_ticksize numeric DEFAULT NULL::numeric,
v_sharesoutstanding numeric DEFAULT NULL::numeric,
v_ticker_class_l1 numeric DEFAULT NULL::numeric,
v_ticker_class_l2 numeric DEFAULT NULL::numeric,
v_ticker_class_l3 numeric DEFAULT NULL::numeric,
v_tick_size_string character varying DEFAULT NULL::character varying,
v_mic_code character varying DEFAULT NULL::character varying,
v_min_size numeric DEFAULT NULL::numeric,
v_max_long_size numeric DEFAULT NULL::numeric,
v_max_short_size numeric DEFAULT NULL::numeric,
v_margin_percentage numeric DEFAULT NULL::numeric,
v_display_symbol character varying DEFAULT NULL::character varying,
v_sedol character varying DEFAULT NULL::character varying,
v_stamp_duty_flag numeric DEFAULT NULL::numeric,
v_margin_initial_cash numeric DEFAULT NULL::numeric,
v_margin_maintenance_cash numeric DEFAULT NULL::numeric
)
language edbspl
as
$$
v_is_manually_modified number(1);
begin
begin -- insert block
add_ticker_intl (
v_ticker_serial,
v_source_id,
v_ticker_id,
v_sector_id,
v_status,
v_market_md,
v_source_ticker_id,
v_instrument_type_id,
v_currency_id,
v_country_code,
v_decimal_places,
v_decimal_correction_factor,
v_parent_ticker_id,
v_parent_source_id,
v_isin_code,
v_lot_size,
v_unit,
v_display_ticker,
v_last_updated_on,
v_comments,
v_listing_date,
v_listing_status,
v_stock_published_status,
v_max_stocks,
v_is_settlement_to,
v_is_main_stock,
v_last_updated_time,
v_currency_correction_factor,
v_global_sector_id,
v_dfn_sector,
v_category,
v_index_type,
v_source_source_id,
v_wkn,
v_reuter_ssymbol,
v_bloomberg_symbol,
v_symbol_status,
v_eligibility_id,
v_sharia_compliant,
v_symbolcode,
v_exchange_status,
v_assct_ticker_serial,
v_ticker_assctn_date,
v_first_trading,
v_idx_main_source_id,
v_otc,
v_clearance_duration,
v_lasttradabledate,
v_all_descriptions,
v_cusip,
v_is_desc_updated,
v_bbgid,
v_bbgid_composite,
v_dec_lot_size,
v_ticker_classification,
v_display_decimal_places,
null,
null,
v_TickSize,
v_SharesOutstanding,
v_ticker_class_L1,
v_ticker_class_L2,
v_ticker_class_L3,
v_tick_size_string,
v_mic_code,
v_min_size,
v_max_long_size,
v_max_short_size,
v_margin_percentage,
v_display_symbol,
v_sedol,
v_stamp_duty_flag
);
insert into future_tickers
(
ticker_serial,
contract_size,
maturity_date,
exp_date,
parent_source_id,
parent_ticker_id,
last_updated_on,
DECIMAL_SUPPORTED_LOT_SIZE,
MARGIN_INITIAL_CASH,
MARGIN_MAINTENANCE_CASH
)
values
(
v_ticker_serial,
v_lot_size,
v_maturity_date,
v_lasttradabledate,
v_parent_source_id,
v_parent_ticker_id,
v_last_updated_on,
v_dec_lot_size,
v_margin_initial_cash,
v_margin_maintenance_cash
);
exception
when dup_val_on_index
then
begin -- insert into block
select is_manually_modified
into v_is_manually_modified
from tickers
where ticker_serial=v_ticker_serial;
exception
when no_data_found
then v_is_manually_modified := null;
end; -- insert into block
if (v_is_manually_modified <> 1 or v_is_manually_modified is null)
then
update future_tickers
set
contract_size = v_lot_size,
maturity_date = v_maturity_date,
exp_date = v_lasttradabledate,
parent_source_id = v_parent_source_id,
parent_ticker_id = v_parent_ticker_id,
last_updated_on = v_last_updated_on,
DECIMAL_SUPPORTED_LOT_SIZE = v_dec_lot_size,
MARGIN_INITIAL_CASH = v_margin_initial_cash,
MARGIN_MAINTENANCE_CASH = v_margin_maintenance_cash
where
ticker_serial = v_ticker_serial;
end if;
end; -- insert block
--commit;
end add_future_tickers_intl
$$;
alter procedure add_future_tickers_intl(numeric, varchar, varchar, varchar, char, varchar, varchar, numeric, varchar, varchar, numeric, numeric, varchar, varchar, varchar, numeric, varchar, varchar, timestamp, varchar, timestamp, numeric, varchar, numeric, numeric, numeric, timestamp, numeric, varchar, varchar, varchar, numeric, varchar, varchar, varchar, varchar, varchar, numeric, numeric, varchar, numeric, numeric, timestamp, timestamp, varchar, numeric, varchar, timestamp, varchar, timestamp, varchar, numeric, varchar, varchar, numeric, numeric, numeric, numeric, numeric, numeric, numeric, numeric, varchar, varchar, numeric, numeric, numeric, numeric, varchar, varchar, numeric, numeric, numeric) owner to office;
When I try to execute the following call,
call pkg_ticker_utils.add_future_tickers_intl(
12768341,
'FCBT',
'TY\M23',
null,
'1',
null,
'F:TY\M23',
68,
'USD',
null,
9,
10000000,
'TY\P',
null,
null,
1000,
'Metric Ton ',
'TYM3',
'2023-02-08 04:42:24.808+00',
null,
null,
null,
null,
null,
null,
null,
'2023-06-21 00:00:00+00',
'0'::numeric,
null,
null,
null,
null,
'674',
null,
null,
'TYM3 CBT',
null,
null,
null,
'TYM3',
0,
null,
null,
null,
null,
null,
null,
'2023-06-21 00:00:00+00',
'EN^XTen-Year US Treasury Note Futures Jun-2023 Composite^XTen-Year US Treasury Note Futures Jun-2023 Composite^X|',
null,
null,
1,
'BBG019PMT181',
null,
'0'::numeric,
null,
3,
'0'::numeric,
null,
null,
null,
null,
null,
null,
'0'::numeric,
null,
null,
'0'::numeric,
'TYM3',
null,
0,
null,
null
);
it is throwing error:
[42883] ERROR: procedure pkg_ticker_utils.add_future_tickers_intl(integer, unknown, unknown, unknown, unknown, unknown, unknown, integer, unknown, unknown, integer, integer, unknown, unknown, unknown, integer, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, integer, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, integer, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, integer, unknown, unknown, integer, unknown, integer, integer, unknown, unknown, unknown, unknown, unknown, unknown, integer, unknown, unknown, integer, unknown, unknown, integer, unknown, unknown) does not exist Hint: No procedure matches the given name and argument types. You might need to add explicit type casts. Position: 6
At the end it says:
Hint: No procedure matches the given name and argument types. You might need to add explicit type casts. Position: 6
I do not understand what it means in the end, by position 6 ?
I have tried to count the parameters and all, and they all match. I do not see any discrepancies.
I have tried to count the parameters, match the types and all and it all checks out. What do I have wrong here?
Good luck with finding someone who is ready to dig through tons of parameters.
My advice: avoid character varying or any other non-preferred type in function arguments. Use preferred types, because they facilitate type resolution:
SELECT typname, typcategory FROM pg_type WHERE typispreferred;
typname │ typcategory
═════════════╪═════════════
bool │ B
text │ S
oid │ N
float8 │ N
inet │ I
timestamptz │ D
interval │ T
varbit │ V
(8 rows)
The exception is probably with the numeric types, as you don't want to use double precision there. There, it is best to use types that can be cast to implicitly, so prefer the right-hand types over the left-hand types in the following list:
SELECT c.castsource::regtype, c.casttarget::regtype
FROM pg_cast AS c
JOIN pg_type AS t1 ON c.castsource = t1.oid
JOIN pg_type AS t2 ON c.casttarget = t2.oid
WHERE t1.typcategory = 'N'
AND t2.typcategory = 'N'
AND c.castcontext = 'i'
AND t2.typname !~~ ALL ('{oid,reg%}');
castsource │ casttarget
════════════╪══════════════════
bigint │ real
bigint │ double precision
bigint │ numeric
smallint │ bigint
smallint │ integer
smallint │ real
smallint │ double precision
smallint │ numeric
integer │ bigint
integer │ real
integer │ double precision
integer │ numeric
real │ double precision
numeric │ real
numeric │ double precision
numeric │ numeric
(16 rows)
Since your main question seems to be the "position 6": that is the position in the SQL statement that is related to the error, so probably the procedure call:
CALL procname(tons_of_parameters);
^
|
here

Is there Oracle RecordType equivalence in PostgreSQL

I am converting a Oracle Package to PostgreSQL stored procedure. The Oracle package has "Record" Type in it, is there any equivalence in PostgreSQL for "Record" Type in PostgreSQL?
Here is the code.
CREATE OR REPLACE PACKAGE BODY LODAXR_TICP_O_pkg02
IS
g_chnl_key NUMBER := 0;
g_crrnt_user VARCHAR2(50);
TYPE g_entity_dtl_rec IS RECORD
(
entity_id VARCHAR2(5 CHAR),
bank_id VARCHAR2(4 CHAR),
branch_id VARCHAR2(10 CHAR),
lob_cd VARCHAR2(15 CHAR),
acct_num VARCHAR2(15 CHAR),
)
g_rec_01 g_entity_dtl_rec;
....
....

crosstab function in postgresql causes invalid memory alloc request size

PostgreSQL 9.5.10, RAM = 8GB
I have a table with three columns (ID, Category, anzahl (=Count)). the table has around 132million rows. There are 58 unique values in category column i.e.: 58 different category.
Similar to example demonstrated here PostgreSQL Crosstab Query i want to create a pivot where i have ID and 58 Categories as columns (so in all 59 columns) and row populated with respective Count values. below is the query:
select * into sde.demographie100m_transposed
from crosstab(
'select gitter_id_100m, category, anzahl
from sde.demographie100m_3col
order by 1,2',
'select distinct category from sde.demographie100m_3col order by 1'
)
AS ct
("gitter_id_100m" text,
"INSGESAMT_Einheiten insgesamt" integer,
"ALTER_10JG_10 - 19" integer,
"ALTER_10JG_20 - 29" integer,
"ALTER_10JG_30 - 39" integer,
"ALTER_10JG_40 - 49" integer,
"ALTER_10JG_50 - 59" integer,
"ALTER_10JG_60 - 69" integer,
"ALTER_10JG_70 - 79" integer,
"ALTER_10JG_80 und älter" integer,
"ALTER_10JG_Unter 10" integer,
"ALTER_KURZ_18 - 29" integer,
"ALTER_KURZ_30 - 49" integer,
"ALTER_KURZ_50 - 64" integer,
"ALTER_KURZ_65 und älter" integer,
"ALTER_KURZ_Unter 18" integer,
"FAMSTND_AUSF_Eingetr. Lebenspartner/-in verstorben" integer,
"FAMSTND_AUSF_Eingetr. Lebenspartnerschaft" integer,
"FAMSTND_AUSF_Eingetr. Lebenspartnerschaft aufgehoben" integer,
"FAMSTND_AUSF_Geschieden" integer,
"FAMSTND_AUSF_Ledig" integer,
"FAMSTND_AUSF_Ohne Angabe" integer,
"FAMSTND_AUSF_Verheiratet" integer,
"FAMSTND_AUSF_Verwitwet" integer,
"GEBURTLAND_GRP_Deutschland" integer,
"GEBURTLAND_GRP_EU27-Land" integer,
"GEBURTLAND_GRP_Sonstige" integer,
"GEBURTLAND_GRP_Sonstige Welt" integer,
"GEBURTLAND_GRP_Sonstiges Europa" integer,
"GESCHLECHT_Männlich" integer,
"GESCHLECHT_Weiblich" integer,
"RELIGION_KURZ_Evangelische Kirche (öffentlich-rechtlich)" integer,
"RELIGION_KURZ_Römisch-katholische Kirche (öffentlich-rechtlich)" integer,
"RELIGION_KURZ_Sonstige, keine, ohne Angabe" integer,
"STAATSANGE_GRP_Deutschland" integer,
"STAATSANGE_GRP_EU27-Land" integer,
"STAATSANGE_GRP_Sonstige" integer,
"STAATSANGE_GRP_Sonstige Welt" integer,
"STAATSANGE_GRP_Sonstiges Europa" integer,
"STAATSANGE_HLND_Bosnien und Herzegowina" integer,
"STAATSANGE_HLND_Deutschland" integer,
"STAATSANGE_HLND_Griechenland" integer,
"STAATSANGE_HLND_Italien" integer,
"STAATSANGE_HLND_Kasachstan" integer,
"STAATSANGE_HLND_Kroatien" integer,
"STAATSANGE_HLND_Niederlande" integer,
"STAATSANGE_HLND_Österreich" integer,
"STAATSANGE_HLND_Polen" integer,
"STAATSANGE_HLND_Rumänien" integer,
"STAATSANGE_HLND_Russische Föderation" integer,
"STAATSANGE_HLND_Sonstige" integer,
"STAATSANGE_HLND_Türkei" integer,
"STAATSANGE_HLND_Ukraine" integer,
"STAATSANGE_KURZ_Ausland" integer,
"STAATSANGE_KURZ_Deutschland" integer,
"STAATZHL_Eine Staatsangehörigkeit" integer,
"STAATZHL_Mehrere Staatsangehörigkeiten, deutsch und ausländisch" integer,
"STAATZHL_Mehrere Staatsangehörigkeiten, nur ausländisch" integer,
"STAATZHL_Nicht bekannt" integer
);
but it results in error as below:
ERROR: invalid memory alloc request size 1073741824
SQL Status:XX000
Kontext:SQL statement "select gitter_id_100m, category, anzahl
from sde.demographie100m_3col
order by 1,2"
Try the canonical form instead:
SELECT gitter_id_100m,
SUM(CASE when category='INSGESAMT_Einheiten insgesamt' then anzahl END) AS "INSGESAMT_Einheiten insgesamt",
SUM(CASE when category='ALTER_10JG_10 - 19' then anzahl END) AS "ALTER_10JG_10 - 19",
...etc...
FROM sde.demographie100m_3col
GROUP BY 1
ORDER BY 1; -- remove the ORDER BY if you can do without it.
Presumably that form would be much easier (than crosstab) for the server to spill to disk if necessary as opposed to generating the entire result in memory.
You may also use a SQL cursor to retrieve the result in chunks. In some cases it can help a lot with the memory consumption, both client-side and server-side.
Client-side code to use a cursor:
BEGIN; -- open transaction
DECLARE mycursor CURSOR FOR SELECT ... rest of the query;
FETCH mycursor; -- retrieve 1 line
-- FETCH mycursor repeatedly
CLOSE mycursor;
COMMIT;
There's also a dynamic_pivot function on github that can be used to automate the above (creates the pivot query and returns a cursor to it), but I'm not sure how its implementation would behave performance-wise with 132M rows.

How to insert characters such as "±, ≧, ≦" inside a table in PL/SQL

Here is the SQL I'm using to create my table:
create table LAB_REQUESTS_REQUREMENTS
(
id INTEGER not null,
request_id INTEGER not null,
test_id INTEGER not null,
requrement VARCHAR2(30) not null,
assistant_id INTEGER,
measured_result VARCHAR2(50),
measured_condition VARCHAR2(50),
price_id INTEGER not null,
single_price NUMBER(15,2) default 0 not null,
measured_date DATE,
measure NVARCHAR2(30),
metric_tolerance NVARCHAR2(30)
)
tablespace VIK
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
How should I go about inserting those characters inside 'MEASURE' for example without going through conversion when inserting and then reading from the table?

PostgreSQL: foreign table and discarded records

where PostgreSQL stores records which were discarded from the foreign table during select? I have following table:
CREATE FOREIGN TABLE ext.alternatenamesext (
altid BIGINT,
geoid BIGINT,
isolanguage VARCHAR(7),
alternatename TEXT,
ispreferredname INTEGER,
isshortname INTEGER,
iscolloquial INTEGER,
ishistoric INTEGER
)
SERVER edrive_server
OPTIONS (
delimiter E'\t',
encoding 'UTF-8',
filename '/mnt/storage/edrive/data/alternateNames.txt',
format 'csv');
alternateNames.txt contains ~11 mln records. But when I do "SELECT * FROM ext.alternatenamesext" it returns only ~9.5mln records. Where the rest of 2mln are? Is there a way to put them into the separate file, like Oracle's sql*ldr?
Problem has been solved by the following syntax of CREATE FOREIGN TABLE...:
CREATE FOREIGN TABLE ext.alternatenamesext (
altid BIGINT,
geoid BIGINT,
isolanguage VARCHAR(7),
alternatename VARCHAR(400),
isPreferredName INT,
isShortName INT,
isColloquial INT,
isHistoric INT
)
SERVER edrive_server
OPTIONS (
delimiter E'\t',
encoding 'UTF-8',
filename '/mnt/storage/edrive/data/alternateNames.txt',
format 'text', -- not 'csv'!
null ''); -- eliminate null values (some kind of TRAILING NULLCOLLS in Oracle I guess)