Which limitiations exist in using ORACLE CUSTOM DATA TYPES as parameter in PL/SQL Stored Procedures? - sql

I'm involved in a pair of java project in which are used oracle stored procedures using oracle custom data type, for example ORACLE OBJECT
CREATE OR REPLACE TYPE OBJ1 AS OBJECT(
SOME_VALUE VARCHAR2(18 CHAR)
, SOME_OTHER_VALUE NUMBER(3,0)
, ...
);
/
and ORACLE TABLE containg these OBJECTS
CREATE OR REPLACE TYPE TBL1 IS TABLE OF OBJ1;
/
So the Stored Procedures receive the ORACLE TABLE as parameter, something like this:
CREATE OR REPLACE PACKAGE PKG_SECURITY_CHECK AS
PROCEDURE VERIFY1(
TBL_INPUT TBL1,
SOME_OUTPUT OUT NUMBER
);
END PKG_CIRCUITO_DI_SICUREZZA;
I'm wondering if there are limitations for example in the number of columns of the ORACLE OBJECT, or in the number of ORACLE OBJECT that could be contained inside the ORACLE TABLE, when the TABLE is passed as parameter...?
I see some other question about parameter numbers or parameter size permitted, put are general question about simple data type as varchar2 or number, I did not find something specific for ORACLE CUSTOM DATA TYPES as parameter in STORED PROCEDURES.

There are no additional structural limitations. Providing it's a valid Oracle type - we can create it in SQL - we can use it to define a PL/SQL parameter.
There no numerical limits to the number of instances of OBJ1 you can store in TBL1. However, objects are stored in session memory, so there is a ceiling, depending on how many populated attributes the object has. However, if you're stuffing so many objects into a collection you blow the MAX_PGA_TARGET that's a sign you've probably chosen the wrong approach.

Related

Snowflake schema and table reference in User Defined Function arguments

I'm trying to create a User Defined Function (UDF) in Snowflake where the arguments can take in schema, table, and column values as variables so that the function can dynamically call different tables. I tried to do this and save the function but Snowflake threw an error saying that the schema name did not exist - it tried to look for the schema using the argument name rather than the variable that will be entered into the function arguments.
Here is an example of what I'm trying to do:
CREATE OR REPLACE FUNCTION "DB_NAME"."SCHEMA_NAME"."FUNCTION_NAME"(
SCHEMA_VAR VARCHAR,
TABLE_VAR VARCHAR,
COLUMN_VAR VARCHAR)
RETURNS TABLE (RETURN_COL VARCHAR)
AS
$$
SELECT COLUMN_VAR FROM "DB_NAME".SCHEMA_VAR.TABLE_VAR
$$;
What you are describing is dynamic SQL which is only allowed from a stored procedure, not a function.
From normal SQL you can use a TABLE LITERAL to have dynamical named tables from the perspective of your code running the SQL, but then you can also just do string manipluation in your code, but this method makes it injection safe.
Honestly, even if what you're trying to achieve was doable using a UDF, it's an overkill. Consider below
set (table_name, column_name) = ('mydb.myschema.mytable', 'mycolumn');
select $column_name
from identifier($table_name);

Hana: How to create a table type LIKE the type of another table?

I'm trying to create a table type which has a lot of fields, in SQLScript for a Hana machine.
I've tried some combinations of 'Like' and other keywords but it all comes out as a syntax error.
Furthermore, I could not find any hint of this in the SQLScript reference guide.
I've been creating tables LIKE [orignal table] with no data and inserting records into it - not practical :(
Thanks in advance.
Miguel
EDIT: to understand if the procedure 'get_object_definition' can be used with tables with case-sensitive names.
In this image we can see the procedure calls, with the error message; in the image after, the tables and table types in each of the schemas.
EDITED: I got it, have to call the procedure with ' " table_name " '
There is no specific command to create a type based on an existing table or another type.
What you can do is to get the definition of the table via
call get_object_definition ('<schema name>', '<table name>');
and edit the object creation statement to a CREATE TYPE statement. This is basically just changing the starting part of the statement and cutting away some parts at the end.

Can you use "Drop table ......." in SSRS

I am creating a report which drops the table if it exists at the beginning and inserts the data that is needed.
The SQl runs smoothly in SQL Server Management Studio with no issues but when I place it into SSRS to create a report, it is saying that the synax is wrong.
I think I might need to do this as a stored procedure but I wanted to make sure that I have not missed anything first.
Thanks in advance.
Place the code in a Stored procedure, and use temporary tables or table variables rather.
Have a look at
CREATE TABLE (Transact-SQL)
Temporary Tables
You can create local and global temporary tables.
Local temporary tables are visible only in the current session, and
global temporary tables are visible to all sessions. Temporary tables
cannot be partitioned.
Prefix local temporary table names with single number sign
(#table_name), and prefix global temporary table names with a double
number sign (##table_name).
SQL statements reference the temporary table by using the value
specified for table_name in the CREATE TABLE statement
Also have a look at
DECLARE #local_variable (Transact-SQL)
#table_variable_name
Is the name of a variable of type table. Variable names must begin
with an at (#) sign and conform to the rules for identifiers.
Defines the table data type. The table declaration includes column
definitions, names, data types, and constraints. The only constraint
types allowed are PRIMARY KEY, UNIQUE, NULL, and CHECK. An alias data
type cannot be used as a column scalar data type if a rule or default
definition is bound to the type.
is a subset of information used to define a
table in CREATE TABLE. Elements and essential definitions are included
here. For more information, see CREATE TABLE (Transact-SQL).

How to reference CLR UDTs when creating a table

I have no idea why there is very little documentation on this so I'll ask here.
I have created some user defined data types and would like to use them when creating a table.
However I have no idea what the syntax is for calling to them.
Yes I know it's best to STAY AWAY from them but I'm in a position where I am forced to work with them.
You use User Defined Types (UDTs) just like the built-in types.
Defining UDT Tables and Columns
There is no special syntax for creating a UDT column in a table. You
can use the name of the UDT in a column definition as though it were
one of the intrinsic SQL Server data types.
The following CREATE TABLE Transact-SQL statement creates a table
named Points, with a column named ID, which is defined as an int
identity column and \ the primary key for the table. The second column
is named PointValue, with a data type of Point. The schema name used
in this example is dbo. Note that you must have the necessary
permissions to specify a schema name. If you omit the schema name, the
default schema for the database user is used.
CREATE TABLE dbo.Points
(
ID int IDENTITY(1,1) PRIMARY KEY,
PointValue Point
)
Registering User-Defined Types in SQL Server

How do I create Oracle Type which refers to table columns for data type?

I am trying to define a type using the following code.
CREATE OR REPLACE TYPE MY_TYPE AS OBJECT (
app_id some_table_name.app_id%type
);
If I run this, I get the error.
Error(4,32): PLS-00201: identifier 'some_table_name.app_id' must be declared
What is wrong with this?
What's wrong with it is that %type is PL/SQL syntax. It isn't supported in SQL. Now we use PL/SQL to define Types (especially member functions, constructors, etc) but the Types themselves are SQL objects, and so follow SQL rules. That means we must declare Type attributes with explicit datatypes.
I agree that's a shame, and it would be really neat if we could reference table columns in type declarations like this. Unfortunately Oracle have really slowed down the changes to their TYPE implementation over the last couple of versions, so I think it is unlikely this will change in the near future.
What I would really like to see is Oracle support this syntax:
CREATE OR REPLACE TYPE MY_TYPE AS OBJECT
( one_row some_table_name.%rowtype );
Dynamic objects for interfaces: how cool would that be?
You cannot use some_table_name.app_id%type when declaring a type in the database, any more than you can do this:
create table emp (empno number,
deptno dept.deptnp%type, -- NOT ALLOWED
);
You must use either a built-in type such as NUMBER, VARCHAR2(10) or a user-defined type such as mytype