op:generate-view( $schemaName as xs:string, $viewName as xs:string, [$columnDeclarations as map:map*] ) as element()
This method generates a view that encapsulates a query. Insert the generated XML into the schemas database and then use the op.fromView op:from-view accessor to use the generated view.
xquery version "1.0-ml"; import module namespace op="http://marklogic.com/optic" at "/MarkLogic/optic.xqy"; op:from-view("main", "employees") => op:where(cts:collection-query("/division/manufacturing")) => op:select(("EmployeeID", "FirstName", "LastName")) => op:order-by("EmployeeID") => op:generate-view("main", "manufacturingEmployees")