I want to get the complete SQL code of the system views like USER_OBJECTS. However, when I execute the query below, it returns an error saying view not found in the SYS schema.
select dbms_metadata.get_ddl('VIEW', 'USER_OBJECTS', 'SYS') from dual;
When I execute the query below, it returns some codes in the text_vc column, but not the complete one. I cannot see the tables and where clause etc.
select * from ALL_VIEWS where VIEW_NAME = 'USER_OBJECTS';
But with this query, I can see that it is in the SYS schema with that name.
So, what is the reason that I cannot see the whole query? And is there a way to see it all?
+1 for looking at the definitions of the system views!
The first problem (DBMS_METADATA empty) is a privilege problem. According to the documentation, normal users will see only their own objects. You'll need the role SELECT_CATALOG_ROLE or EXP_FULL_DATABASE to see other users objects.
The second problem (SQL is not complete) comes from the datatype LONG, which - according to Oracle - should not be used anymore. However, it is still used by Oracle for view definitions, defaults, constraint text etc. Because it is so hard to handle, the view ALL_VIEWS has the original text in the LONG column and a truncated text, mostly the first 4000 characters, in the column text_vc, presumably for "text in varchar".
EDIT:
I believe you use Oracle 12 as you mention the column text_vc, which is not available in Oracle 11. Presumably, you are using a containerized database. If so, then please have a look at Data Dictionary Architecture in a CDB. Apparently, the definition of Oracle supplied things like views and packages are only visible in the root container. Sigh!!
In SQL*Plus, you'd set long (I shortened the output):
SQL> set pagesize 0
SQL> set long 10000
SQL>
SQL> select text from all_views where view_name = 'USER_OBJECTS';
select o.name, o.subname, o.obj#, o.dataobj#,
decode(o.type#, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE',
7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
11, 'PACKAGE BODY', 12, 'TRIGGER',
<snip>
from sys."_CURRENT_EDITION_OBJ" o
where o.owner# = userenv('SCHEMAID')
and o.linkname is null
and (o.type# not in (1 /* INDEX - handled below */,
10 /* NON-EXISTENT */)
or
<snip>
union all
select l.name, NULL, to_number(null), to_number(null),
'DATABASE LINK',
l.ctime, to_date(null), NULL, 'VALID', 'N', 'N', 'N', NULL, NULL
from sys.link$ l
where l.owner# = userenv('SCHEMAID')
SQL>
Also, your first query works in my database (11g XE) if I'm connected as SYS:
SQL> show user
USER is "SYS"
SQL> select dbms_metadata.get_ddl('VIEW', 'USER_OBJECTS', 'SYS') from dual;
DBMS_METADATA.GET_DDL('VIEW','USER_OBJECTS','SYS')
--------------------------------------------------------------------------------
CREATE OR REPLACE FORCE VIEW "SYS"."USER_OBJECTS" ("OBJECT_NAME", "SUBOBJECT_N
AME", "OBJECT_ID", "DATA_OBJECT_ID", "OBJECT_TYPE", "CREATED", "LAST_DDL_TIME",
"TIMESTAMP", "STATUS", "TEMPORARY", "GENERATED", "SECONDARY", "NAMESPACE", "EDIT
ION_NAME") AS
select o.name, o.subname, o.obj#, o.dataobj#,
decode(o.type#, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE',
7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
11, 'PACKAGE BODY', 12, 'TRIGGER',
<snip>
Related
I have an Oracle 18c SDO_GEOMETRY object that has attributes (aka properties):
with cte as (
select
sdo_util.from_wktgeometry('MULTILINESTRING ((0 5 0, 10 10 10, 30 0 33.54),(50 10 33.54, 60 10 -10000))') shape
from dual)
select
a.shape.sdo_gtype as old_gtype,
a.shape.sdo_gtype + 300 as new_gtype,
a.shape
from
cte a
OLD_GTYPE NEW_GTYPE SHAPE
--------- --------- -----
3006 3306 SDO_GEOMETRY(3006, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1, 10, 2, 1), SDO_ORDINATE_ARRAY(0, 5, 0, 10, 10, 10, 30, 0, 33.54, 50, 10, 33.54, 60, 10, -10000))
I want to modify the GTYPE attribute of the SDO_GEOMETRY object:
Old GTYPE: 3006
New GTYPE: 3306
It's possible to modify the GTYPE attribute using a custom function (or an inline function):
See #AlbertGodfrind's answer in Convert M-enabled SDE.ST_GEOMETRY to SDO_GEOMETRY using SQL
However, as an experiment, I want to modify the GTYPE attribute right in the SELECT clause in a query -- without using a custom function.
For example, I wonder if there might be OOTB functionality like this:
modify_object_property(object, property_name, new_val) returns sdo_geometry
Is there a way to modify an SDO_GEOMETRY GTYPE attribute/property — without creating a custom function?
Related: Replace value in SDO_ELEM_INFO_ARRAY varray
You can use the sdo_geometry constructor as follows
with cte as (
select
sdo_util.from_wktgeometry('MULTILINESTRING ((0 5 0, 10 10 10, 30 0 33.54),(50 10 33.54, 60 10 -10000))') shape
from dual)
select sdo_geometry(a.shape.sdo_gtype + 300,
a.shape.sdo_srid,
a.shape.sdo_point,
a.shape.sdo_elem_info,
a.shape.sdo_ordinates) as shape
from cte a;
You can modify the contents of an object in SQL. You just need to make sure you use an alias on the table. For example:
update my_table t
set t.geom.sdo_gtype = t.geom.sdo_gtype + 300
where ... ;
But that is not what you are looking for. Modifying an object that way in the select list is not possible. Hence the approach via a custom function.
I need to calculate Distance between two location through Pl SQL Query. I had tried some Qry but not getting it.
for this we are using Query in SQL is as follows
SELECT ROUND(geography::Point(cast('19.2806118' as float),cast('72.8757395' as float) ,
4326).STDistance(geography::Point(cast('19.4482006' as float),
cast('72.7912511' as float), 4326))/1000,1) DIST
Result : 20.6
To Calculate the same in ORACLE Db I have found a solution over internet which is as follows
select sdo_geom.sdo_distance(sdo_geometry(2001,4326,null,sdo_elem_info_array(1, 1, 1),
sdo_ordinate_array( 19.2806118,72.8757395)),sdo_geometry(2001,4326, null,sdo_elem_info_array(1, 1,
1),sdo_ordinate_array( 19.4482006,72.7912511)),1,'unit=KM') distance_km from dual
Result : 10.9271..
Please suggest the method which will give me result in KM as I am getting MS SQL
Please suggest the method which will give me result in KM as I am getting MS SQL
Swapping parameter order 19.2806118,72.8757395 to 72.8757395,19.2806118
select sdo_geom.sdo_distance(
sdo_geometry(2001,4326,null,sdo_elem_info_array(1, 1, 1),
sdo_ordinate_array(72.8757395,19.2806118)),
sdo_geometry(2001,4326, null,sdo_elem_info_array(1, 1,1),
sdo_ordinate_array(72.7912511,19.4482006))
,1
,'unit=KM') distance_km
from dual;
Yields exactly the same result as SQL Server: 20.5657053685075
db<>fiddle demo Oracle
db<>fiddle demo SQL Server
Or by using sdo_point:
SELECT sdo_geom.sdo_distance(
sdo_geometry(2001, 4326,
sdo_point_type(72.8757395, 19.2806118, NULL), NULL, NULL),
sdo_geometry(2001, 4326,
sdo_point_type(72.7912511, 19.4482006, NULL), NULL, NULL),
1, 'unit=KM') distance_in_m
from DUAL;
SQL Server: geography::Point ( Lat, Long, SRID )
I want to get the complete SQL code of the system views like USER_OBJECTS. However, when I execute the query below, it returns an error saying view not found in the SYS schema.
select dbms_metadata.get_ddl('VIEW', 'USER_OBJECTS', 'SYS') from dual;
When I execute the query below, it returns some codes in the text_vc column, but not the complete one. I cannot see the tables and where clause etc.
select * from ALL_VIEWS where VIEW_NAME = 'USER_OBJECTS';
But with this query, I can see that it is in the SYS schema with that name.
So, what is the reason that I cannot see the whole query? And is there a way to see it all?
+1 for looking at the definitions of the system views!
The first problem (DBMS_METADATA empty) is a privilege problem. According to the documentation, normal users will see only their own objects. You'll need the role SELECT_CATALOG_ROLE or EXP_FULL_DATABASE to see other users objects.
The second problem (SQL is not complete) comes from the datatype LONG, which - according to Oracle - should not be used anymore. However, it is still used by Oracle for view definitions, defaults, constraint text etc. Because it is so hard to handle, the view ALL_VIEWS has the original text in the LONG column and a truncated text, mostly the first 4000 characters, in the column text_vc, presumably for "text in varchar".
EDIT:
I believe you use Oracle 12 as you mention the column text_vc, which is not available in Oracle 11. Presumably, you are using a containerized database. If so, then please have a look at Data Dictionary Architecture in a CDB. Apparently, the definition of Oracle supplied things like views and packages are only visible in the root container. Sigh!!
In SQL*Plus, you'd set long (I shortened the output):
SQL> set pagesize 0
SQL> set long 10000
SQL>
SQL> select text from all_views where view_name = 'USER_OBJECTS';
select o.name, o.subname, o.obj#, o.dataobj#,
decode(o.type#, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE',
7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
11, 'PACKAGE BODY', 12, 'TRIGGER',
<snip>
from sys."_CURRENT_EDITION_OBJ" o
where o.owner# = userenv('SCHEMAID')
and o.linkname is null
and (o.type# not in (1 /* INDEX - handled below */,
10 /* NON-EXISTENT */)
or
<snip>
union all
select l.name, NULL, to_number(null), to_number(null),
'DATABASE LINK',
l.ctime, to_date(null), NULL, 'VALID', 'N', 'N', 'N', NULL, NULL
from sys.link$ l
where l.owner# = userenv('SCHEMAID')
SQL>
Also, your first query works in my database (11g XE) if I'm connected as SYS:
SQL> show user
USER is "SYS"
SQL> select dbms_metadata.get_ddl('VIEW', 'USER_OBJECTS', 'SYS') from dual;
DBMS_METADATA.GET_DDL('VIEW','USER_OBJECTS','SYS')
--------------------------------------------------------------------------------
CREATE OR REPLACE FORCE VIEW "SYS"."USER_OBJECTS" ("OBJECT_NAME", "SUBOBJECT_N
AME", "OBJECT_ID", "DATA_OBJECT_ID", "OBJECT_TYPE", "CREATED", "LAST_DDL_TIME",
"TIMESTAMP", "STATUS", "TEMPORARY", "GENERATED", "SECONDARY", "NAMESPACE", "EDIT
ION_NAME") AS
select o.name, o.subname, o.obj#, o.dataobj#,
decode(o.type#, 0, 'NEXT OBJECT', 1, 'INDEX', 2, 'TABLE', 3, 'CLUSTER',
4, 'VIEW', 5, 'SYNONYM', 6, 'SEQUENCE',
7, 'PROCEDURE', 8, 'FUNCTION', 9, 'PACKAGE',
11, 'PACKAGE BODY', 12, 'TRIGGER',
<snip>
I have a URI column coming in a log. I have to parse it and remove the certain parts from it and store it in a table. For Example if I have /v7/cp/members/~PERF1SP826T90869AN/options, then I have to store it as /v7/cp/members/*/options. Can I do that using REGEXP_REPLACE?
Also I would like to see if I could store that part that I removed from the URI as another column?
For Example from /v7/cp/members/~PERF1SP826T90869AN/options, I should store /v7/cp/members/*/options as a column and PERF1SP826T90869AN in a separate column.
If you are using Oracle, here's a method:
SQL> with tbl(str) as (
select '/v7/cp/members/~PERF1SP826T90869AN/options' from dual
)
select regexp_replace(str, '(.*?)(/|$)', '*/', 1, 5) as replaced,
regexp_substr(str, '(.*?)(/|$)', 1, 5, NULL, 1) as fifth_element
from tbl;
REPLACED FIFTH_ELEMENT
------------------------ -------------------
/v7/cp/members/*/options ~PERF1SP826T90869AN
SQL>
org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback; bad SQL grammar
[{call pkg_name.procedure_name()}]; nested exception is java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'PROCEDURE_NAME'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
I have two schemas- OwnerSchema and AppSchema. I have grant execute privileges on all the packages from OwnerSchema to AppSchema. When I try to execute any procedure from the back end of AppSchema, I am able to execute the procedure. When I try to execute the same procedure from Java Spring JDBC, I get above error. I am able to execute this procedure from OwnerSchema from Java.
I am able to access all the tables from Java Spring JDBC application with AppSchema.
I have used following trigger to point to the OwnerSchmea on LogOn.
CREATE OR REPLACE TRIGGER FINAL_APP_USER.AFTER_LOGON_TRG
AFTER LOGON ON FINAL_APP_USER.SCHEMA
BEGIN
DBMS_APPLICATION_INFO.SET_MODULE(USER, 'Initialized');
EXECUTE IMMEDIATE 'ALTER SESSION SET current_schema=TEST'; --enter owner
END;
/
Here is the call to procedure
SimpleJdbcCall simpleJdbcCall = getSimpleJdbcCall()
.withCatalogName("pkg_name").withProcedureName(
"procedure_name").returningResultSet(
"C_Srf_1", new RowMapper<FinalCountForQuestions>() {
public FinalCountForQuestions mapRow(
ResultSet rs, int rowNum)
throws SQLException {
...
return finalCountForQuestions;
}
});
Map<String, Object> mapOfOutputParams = simpleJdbcCall.execute();
Spring JDBC template generates following query while making call to database procedure
SELECT PACKAGE_NAME AS PROCEDURE_CAT,
OWNER AS PROCEDURE_SCHEM,
OBJECT_NAME AS PROCEDURE_NAME,
ARGUMENT_NAME AS COLUMN_NAME,
DECODE(POSITION, 0, 5,
DECODE(IN_OUT, 'IN', 1,
'OUT', 4,
'IN/OUT', 2,
0)) AS COLUMN_TYPE,
DECODE (DATA_TYPE, 'CHAR', 1,
'VARCHAR2', 12,
'NUMBER', 3,
'LONG', -1,
'DATE', 91,
'RAW', -3,
'LONG RAW', -4,
'TIMESTAMP', 93,
'TIMESTAMP WITH TIME ZONE', -101,
'TIMESTAMP WITH LOCAL TIME ZONE', -102,
'INTERVAL YEAR TO MONTH', -103,
'INTERVAL DAY TO SECOND', -104,
'BINARY_FLOAT', 100, 'BINARY_DOUBLE', 101, 1111) AS DATA_TYPE,
DECODE(DATA_TYPE, 'OBJECT', TYPE_OWNER || '.' || TYPE_NAME, DATA_TYPE) AS TYPE_NAME,
DECODE (DATA_PRECISION, NULL, DATA_LENGTH,
DATA_PRECISION) AS PRECISION,
DATA_LENGTH AS LENGTH,
DATA_SCALE AS SCALE,
10 AS RADIX,
1 AS NULLABLE,
NULL AS REMARKS,
SEQUENCE,
OVERLOAD,
DEFAULT_VALUE
from ALL_ARGUMENTS
where OWNER like '<USER>' escape '/'
and OBJECT_NAME like '<PROCEDURE_NAME>' escape '/'
and PACKAGE_NAME like '<PACKAGE_NAME>' ESCAPE '/'
AND (ARGUMENT_NAME LIKE 'C_SRF_1' ESCAPE '/'
OR (ARGUMENT_NAME IS NULL
and DATA_TYPE is not null))
--and
--other arguments
ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME, OVERLOAD, SEQUENCE;
So when you are using an ApplicationUser to call the database procedure, it will look into ALL_ARGUMENTS view with you ApplicationUser name and will not find any arguments. So, solution for this is, when you make a call to a procedure, pass the schema name of owner as follows.
SimpleJdbcCall simpleJdbcCall = getSimpleJdbcCall()
.withSchemaName(<OwnerSchema>)
.withCatalogName("pkg_name").withProcedureName(
"procedure_name").returningResultSet(
"C_Srf_1", new RowMapper<FinalCountForQuestions>() {
Wasted an hour with similar error. I had schema name in catalog name. Procedure was found nicely, but got the error. I had to declare all bits separately (tt.payment_requests.start_process):
simpleJdbcCall = new SimpleJdbcCall(oracleDataSource())
.withSchemaName("TT")
.withCatalogName("PAYMENT_REQUESTS")
.withProcedureName("START_PROCESS");