jmc
jmc

Reputation: 408

Can I use a function, which takes parameters using "=>" syntax, in a view?

I got a select statement working (no syntax errors and returning desired results), but I get an error when I try to use the same select statement in a view. I figure it has something to do with the "=>" to name the parameters.

select SDO_UTIL.AFFINETRANSFORMS(
  geometry => STRTS.GEOMETRY,
  translation => 'FALSE', tx => 0.0, ty => 0.0, tz => 0.0,
  scaling => 'TRUE', psc1 =>
    MDSYS.SDO_GEOMETRY( 3001, NULL, SDO_POINT_TYPE( 0, 0, 0 ), NULL, NULL),
    sx => 0.8, sy => 0.8, sz => 0.8,
  rotation => 'FALSE', p1 => NULL,
    line1 => NULL, angle => 10.0, dir => 2,
  shearing => 'FALSE', shxy => 0.0, 
    shyx => 0.0, shxz => 0.0, shzx => 0.0, shyz => 0.0, shzy => 0.0,
  reflection => 'FALSE', pref => NULL, lineR => NULL, dirR => 0, 
    planeR => 'FALSE', n => NULL, bigD => NULL ) AS GEOMETRY 
FROM (
  SELECT 
    MDSYS.SDO_GEOMETRY(3002, NULL, NULL, 
    SDO_ELEM_INFO_ARRAY(1, 2, 1), 
    SDO_ORDINATE_ARRAY(-90, 30, 0, -90, 30, 0))
  as GEOMETRY
  FROM DUAL ) STRTS

I simplified the statement to only use dual to make it easier to reproduce. I have table with linear geometries that I'm going to use instead of the "SELECT ... FROM DUAL" and a way to pull a point off the line to use for psc1.

The error I get when using sqldeveloper's test syntax is

Error(s) parsing SQL: Unexpected token at 45 near =>.

The first "=>" is 45 characters into the string, so I figure there's just something invalid about using it in the create view.

I pretty sure I can work around this by creating a function that doesn't use this "=>" syntax, but hoped there was a way to call this oracle function straight from the create view.

Edit: So it appears sqldeveloper/sqlplus have support for something like named parameters. I added comments around the named parameters (/* named_param =>*/) to stop using the named parameter syntax. Now it just a "wrong number or type of arguments" error. Unfortunately, I put all the parameters in the exact order as show in Oracle's online docs ( from http://docs.oracle.com/cd/B28359_01/appdev.111/b28400/sdo_util.htm#BJEGCCDF ). So I guess this becomes a question of how to find the right order for my function arguments.

Upvotes: 4

Views: 322

Answers (1)

Tony Andrews
Tony Andrews

Reputation: 132570

Yes you can, but only since Oracle 11G. Prior to that, only positional notation was allowed in any SQL statement, which includes view definitions.

Upvotes: 5

Related Questions