Hashing string in Oracle - oracle

I know there's a function to obtain the hash value from a varchar in Oracle, but when I run the query to see the returned value it sends the following message.
ORA-00904: : identificador no válido
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error en la línea: 70, columna: 7
What I'm doing is the following:
select DBMS_CRYPTO.hash(utl_raw.cast_to_raw('Foo'), 3) FROM dual;
It should return the SHA-1 of the string.

That works for me
SQL> select DBMS_CRYPTO.hash(utl_raw.cast_to_raw('Foo'), 3) FROM dual;
DBMS_CRYPTO.HASH(UTL_RAW.CAST_TO_RAW('FOO'),3)
--------------------------------------------------------------------------------
201A6B3053CC1422D2C3670B62616221D2290929
Are you sure that the user that is running this has been granted EXECUTE access on both the UTL_RAW and the DBMS_CRYPTO packages? If line 70 of your code is this SELECT statement, I'd wager that column 7 is where the DBMS_CRYPTO call starts and that you don't have access to the DBMS_CRYPTO package.

Related

oracle sql: collect aggregation

I want to group my database entries by an attribute and to know which entries are in each group at the same time. I collect the ids of the grouped entries with Oracle COLLECT function COLLECT Function
DECLARE
TYPE ids_type IS TABLE OF number(19, 0);
ids ids_type;
BEGIN
select cast(collect(r.id) as ids_type) into ids from rechnungsdaten r group by r.status;
END;
But then I get the error:
Error report - ORA-06550: Line 5, Column 44: PL/SQL:
ORA-00902: Invalid datatype ORA-06550: Line 5, Column 5:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
What is wrong here?
You cannot use COLLECT function on a type declared in a PL/SQL anonymous block.
You have other options like
Create a database type and run your collect query.
create or replace TYPE ids_type IS TABLE OF number(19, 0);
SELECT
r.status,
CAST(COLLECT(r.id) AS ids_type)
FROM
rechnungsdaten r
GROUP BY
r.status;
Use a simple LISTAGG query to see the list of ids as a string
SELECT
r.status,
LISTAGG(r.id,',') WITHIN GROUP(
ORDER BY
id
)
FROM
rechnungsdaten r
GROUP BY
r.status;
Demo

SQL Error 00905. 00000 - "missing keyword"

I am trying to execute this query ;
Grant SELECT on TYPE PPZ_C.BTS_BAUTEIL_STATION_INFO to PPZ_W;
and I get the folowing error:
Error starting at line : 3 in command - Grant SELECT on TYPE
PPZ_C.BTS_BAUTEIL_STATION_INFO to PPZ_W Error report - ORA-00905:
missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:
Does anyone know what keyword I am missing ?
Firstly you need to remove TYPE. This will fix your first part of issue.
Try this
Grant SELECT on PPZ_C.BTS_BAUTEIL_STATION_INFO to PPZ_W
Now when you execute the above , you will further get the error:
ORA-02305: only EXECUTE, DEBUG, and UNDER privileges are valid for
types
Which means you cannot grant select on any type. Only EXECUTE, DEBUG, and UNDER privileges are valid for types.
So you can use EXECUTE when you want it to be used in select statement :
Grant EXECUTE on PPZ_C.BTS_BAUTEIL_STATION_INFO to PPZ_W;
EDIT:
Your select statement should be :
SELECT ppz_bts.na_stat_anf( PPZ_C.BTS_BAUTEIL_STATION_INFO ('','IG','12345679') ) FROM dual;
See demo:
CREATE OR REPLACE TYPE myschema.array_t is varray(2) of number ;
---Running in My schema
SQL> select * from table(array_t('1','2'));
COLUMN_VALUE
------------
1
2
--Granted from myschema to otherschema
SQL> grant execute on myschema.array_t to othersschema ;
--Running in otherschema
SQL> select * from table(myschema.array_t('1','2'));
COLUMN_VALUE
------------
1
2
When Oracle receives requests for type information, it verifies that the requestor has EXECUTE privilege on the type before supplying the requested information.
Try this :
Grant EXECUTE on PPZ_C.BTS_BAUTEIL_STATION_INFO to PPZ_W;
Then try doing :
SELECT ppz_bts.na_stat_anf( PPZ_C.bts_bauteil_station_info('','IG','12345679') )
FROM dual;

oracle cannot insert values into a nested table field

I have the sample CUSTOMERS table.
I exported the values from table as INSERT script.
I took one row, modified the value from PK and re-executed the insert.
Insert into oe.customers (CUSTOMER_ID,
CUST_FIRST_NAME,
CUST_LAST_NAME,
CUST_ADDRESS,
PHONE_NUMBERS,
NLS_LANGUAGE,
NLS_TERRITORY,
CREDIT_LIMIT,
CUST_EMAIL,
ACCOUNT_MGR_ID,
CUST_GEO_LOCATION,
DATE_OF_BIRTH,
MARITAL_STATUS,
GENDER,
INCOME_LEVEL,
CREDIT_CARDS)
values ( oe.customer_seq.nextval,
'Donald',
'Hunter',
OE.CUST_ADDRESS_TYP('5122 Sinclair Ln','21206','Baltimore','MD','US'),
OE.PHONE_LIST_TYP('+1 410 123 4795'),
'us',
'AMERICA',
2600,
'Donald.Hunter#CHACHALACA.EXAMPLE.COM',
145,
MDSYS.SDO_GEOMETRY(2001,8307,MDSYS.SDO_POINT_TYPE(-76.545732,39.322775,NULL),NULL,NULL),
to_date('20-JAN-60','DD-MON-RR'),
'married',
'M',
'G: 130,000 - 149,999',
OE.TYP_CR_CARD_NST(OE.TYP_CR_CARD('Visa',100000000000011)));
and I have the following error message:
Error at Command Line : 32 Column : 29 Error report - SQL Error:
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
which refers to line:
OE.TYP_CR_CARD_NST(OE.TYP_CR_CARD('Visa',100000000000011)));
The definition of types are:
create or replace type typ_cr_card as object
( card_type VARCHAR2(25)
, card_num NUMBER);
create or replace type typ_cr_card_nst as table of typ_cr_card;
Can someone tell me, please, what is wrong with this insert line as it is the one provided by SQL DEVELOPER?
NOTE: Also, I tried to use a procedure which inserts values in this table and the error refers to TYP_CR_CARD_NST datatype.

store value of column into variable

I want to get a value of column, and put it into variable of the same type of that column, as the following :
select FRI_SEC_TEMP into friday_seconds
from TEMPTABLE
where rownum<2;
DBMS_OUTPUT.PUT_LINE(friday_seconds);
but when I run the script, it give me the following error:
Query Run In:Query Result 6
Error starting at line : 61 in command -
DBMS_OUTPUT.PUT_LINE(friday_seconds)
Error report -
Unknown Command
and when I run just the select statement I get the following error:
ORA-00905: missing keyword
00905. 00000 - "missing keyword"
*Cause:
*Action:
Just execute the script as a PL SQL block by surrounding it with begin - end
begin
select FRI_SEC_TEMP into friday_seconds
from TEMPTABLE
where rownum<2;
DBMS_OUTPUT.PUT_LINE(friday_seconds);
end;

SELECT a table from oracle data dictionary

I am new to SQL and recently installed Oracle 11g. I read the post here on selecting all tables from user_tables. I'm trying to select a specific table and following some of the suggestions in the post does not appear to work.
The following executes fine and returns all tables available to me including a table named faculty_t:
select * from user_tables;
select * from dba_tables;
select * from all_tables;
desc faculty_t;
But I get error when I do the following:
select * from user_tables where table_name = FACULTY_T;
The first set of statements confirm that I do have a table named faculty_t. However, trying to select this table from user_tables, all_tables, or dba_tables does not appear to work for me right now. The error message reads something like:
ORA-00904: "FACULTY_T": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
Error at Line: 208 Column: 8
Any thoughts? Thanks!
String literals in SQL are wrapped in '. So:
select * from user_tables where table_name = 'FACULTY_T';
When you did a desc faculty_t, the SQL engine knew that a table name was expected at that spot (the syntax expects a table name there). But in your select query, sql is just looking for the value of a column that happens to have a string data type, so you need to use the ' for a string literal.

Resources