I don't understand the last part of your SOQL in which you are pointing the CampaingId to the Campaign object. Please, try this query instead:
List<OpportunityContactRole> ocr =[SELECT contactid,contact.name,contact.account.name,role,opportunityid opportunity.name
FROM opportunitycontactrole WHERE contactid in (SELECT contactid FROM campaignmember WHERE campaignid != null)];
It looks like you want to make sure that there is a campaign related to the OpportunityContactRole. By adding the !=null
(not equal) we can accomplish that logic and avoid the error which it is a limitation in your SOQL.
UPDATE:
You can use a list of Campings and use it as your criteria as part of your SOQL.
List<Campaign> camList = [SELECT Id FROM Campaign];
List<OpportunityContactRole> ocr =[SELECT contactid, contact.name, contact.account.name, role, opportunityid, opportunity.name
FROM opportunitycontactrole WHERE contactid in (SELECT contactid FROM campaignmember WHERE campaignid IN: camList)];
If you can pass the campaigns to thatcamList
list you could do something like the above query. You need to be aware of governor limits for the campaign list.