Add Datamasking on table - oracle11g

I wanted to mask my table with any masking technique. From some sources, tried some on sql*plus but shows an error as shown below. Is it possible without pl/SQL? How to perform it directly on the command line?
SQL:
create table test1 (id int, name varchar2(10) MASKED with (function = 'default()');
create table test1 (id int, name varchar2(10) MASKED with (function = 'default()')
*
ERROR at line 1:
ORA-00907: missing right parenthesis

Related

Psycopg2 Insert into table two values from another table with a where conditional

Apologies for the simple question I am new to using PostgreSQL and Psycopg2. I have two columns in a table I am trying to populate using values from two other tables based on a where conditional. Example code below:
cur = con.cursor()
db_insert = """INSERT INTO "Database"."TABLE_ONE"
("LT_ID_ONE", "LT_ID_TWO")
VALUES(
(SELECT "LT_ID_ONE" FROM "Database"."TABLE_TWO" WHERE "LT_NUM_ONE" =%s),
(SELECT "LT_ID_TWO" FROM "Database"."TABLE_THREE" WHERE "LT_NUM_TWO" =%s)
);"""
insert_values = (df1.iloc[0, 0], df1.iloc[0, 1])
cur.execute(db_insert, insert_values)
When running this command I receive the following error:
psycopg2.errors.NotNullViolation: null value in column "LOT_ID_ONE" violates not-null constraint
DETAIL: Failing row contains (null, null).
Any help would be appreciated.
Looks as though my error was in the order of the elements for the insert_values variable. Once I swapped them it worked. So the SQL code I have is correct.

How to create multi-column indices DuckDB/SQLite?

I have a DuckDB with columns of data which I would like to query using multiple columns. I'm in R but I'm not sure how to create a multicolumn index (or even a single column index). Can anyone suggest a reference please? I've added SQLite as a tag because I gather that the commands could be the same.
Edit:
Based on kukuk1de's recommendation I'm trying the following
require(DBI)
require(duckdb)
DBI::dbExecute(con,statement = "CREATE INDEX multi_idx ON (percent prevalence fresh_flow maskProp dropExhale)")
but I get the following error:
Error in .local(conn, statement, ...) :
duckdb_prepare_R: Failed to prepare query CREATE INDEX multi_idx ON (percent prevalence fresh_flow maskProp dropExhale)
Error: Parser Error: syntax error at or near "("
LINE 1: CREATE INDEX multi_idx ON (percent prevalence fresh_flow maskProp...
Try this:
library("DBI")
con = dbConnect(duckdb::duckdb(), dbdir=":memory:", read_only=FALSE)
dbExecute(con, "CREATE TABLE items(item VARCHAR, value DECIMAL(10,2), count INTEGER)")
dbExecute(con, "INSERT INTO items VALUES ('jeans', 20.0, 1), ('hammer', 42.2, 2)")
dbExecute(con, "CREATE INDEX itemcount_idx ON items (item, count);")
Running the last command again will tell you the index already exists.
dbExecute(con, "CREATE INDEX itemcount_idx ON items (item, count);")
Error in duckdb_execute(res) : duckdb_execute_R: Failed to run query
Error: Catalog Error: Index with name "itemcount_idx" already exists!

SQL Error: ORA-00904: : invalid identifier in line 4

I was working in sql command line and got this error ORA-00904 when i queried to create a table
I tried various inputs and got the same error in line 4.
Help me out.
If you create a table
Then this would work :
CREATE TABLE DATA
(
ID INT NOT NULL,
NAME VARCHAR2(10) NOT NULL
);
But this would raise an ORA-00904 :
CREATE TABLE DATA
(
ID INT NOT NULL,
NAME VARCHAR2(10) NOT NULL,
);
The difference?
After that last comma, something more is expected.
Yet, all it finds is a round bracket.
Hence, the error.

i have tried to rum this procedure but looks like it doesnt comile

create or replace procedure nestedTableColumnDemo is
--i have tried to create netsed table
TYPE address_nest1 is TABLE OF varchar2(50);
--using varchar i tried to create a table but it gives an error i have no idea why.
var1 varchar2(100);
begin
--this is where i created the table using a variable var1
var1:='create table customer_info(name varchar2(50),postal_address address_nest1) nested table postal_address store as postal_address_tab';
execute immediate var1;
end nestedTableColumnDemo;
execute nestedTableColumnDemo;
When I try to execute this it shows an error but no table is created.
CREATE OR REPLACE TYPE address_nest1 IS TABLE OF VARCHAR2(10)
/
create or replace procedure nestedTableColumnDemo is --i have tried to create netsed table
var1 varchar2(200);--using varchar i tried to create a table but it gives an error i have no idea why.
begin
var1:='create table customer_info
(name varchar2(50),
postal_address address_nest1)
nested table postal_address store as postal_address_tab'; --this is where i created the table using a variable var1
execute immediate var1;
end nestedTableColumnDemo;
/
execute nestedTableColumnDemo;
/
This Works.

ORA-00907: missing right parenthesis when creating tables

I am trying to create 3 tables but I am getting this error:
CREATE TABLE dj_abonent
(
dj_klientID INT NOT NULL PRIMARY KEY,
emer_klienti varchar2(10),
mbiemer_klienti VARCHAR2(10),
sasia_cel INT
);
CREATE TABLE dj_phones
(
phone_number varchar2(12),
activated number(1) default 0,
activation_date date default null,
CONSTRAINT dj_phone_number_check
CHECK (substr(phone_number,1,5) in( '35566','35567','35568','35569') ),
CONSTRAINT dj_activated_check
CHECK (activated in(1,0) )
dj_KlientID int FOREIGN KEY REFERENCES dj_Abonenti(dj_KlientID)
);
CREATE TABLE dj_telef
(
start_time date,
end_time date,
abonent_1 varchar2(10),
abonent_2 varchar2(10)
);
Error at Command Line : 26 Column : 17
Error report -
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
The line number is from your SQL Developer script window, which isn't entirely helpful as it doesn't seem to align with the issue. There may be other things too but you're missing a comma after your check constraint (just like a previous question). But you should put the constraints at the end of the command:
CREATE TABLE dj_phones
(
phone_number varchar2(12),
activated number(1) default 0,
activation_date date default null,
dj_KlientID int FOREIGN KEY REFERENCES dj_Abonenti(dj_KlientID)
CONSTRAINT dj_phone_number_check
CHECK (substr(phone_number,1,5) in( '35566','35567','35568','35569') ),
CONSTRAINT dj_activated_check
CHECK (activated in(1,0) )
);
You might find it easier to debug these issues if you ran one statement at a time, either with the run statement command (control-enter), or by highlighting the text one one command and using run script (F5).

Resources